konimarti / opc

OPC DA client in Golang for monitoring and analyzing process data based on Windows COM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some questions

HOULL2 opened this issue · comments

func main() {
opc.Debug()

client, err := opc.NewConnection("Kepware.KEPServerEX.V6", []string{"localhost"}, []string{"test.test1.1", "test.test1.2", "test.test1.3"})
if err != nil {
	fmt.Println(err)
	return
}

for i := 0; i < 100; i++ {
	v := client.ReadItem("test.test1.1")
	fmt.Println("i: ", i, ", value: ", v)

	v = client.ReadItem("test.test1.2")
	fmt.Println("i: ", i, ", value: ", v)

	v = client.ReadItem("test.test1.3")
	fmt.Println("i: ", i, ", value: ", v)
	time.Sleep(time.Second)
	fmt.Println("//--------------------------------------------------//")
}

defer client.Close()

}

output:
2019/08/21 08:52:32 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/21 08:52:32 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/21 08:52:32 Connecting to Kepware.KEPServerEX.V6 on node localhost
2019/08/21 08:54:32 Connected.
i: 0 , value: { 8 2019-08-21 00:54:32 +0000 UTC}
i: 0 , value: { 8 2019-08-21 00:54:32 +0000 UTC}
i: 0 , value: { 8 2019-08-21 00:54:32 +0000 UTC}
//--------------------------------------------------//
i: 1 , value: {3 192 2019-08-21 00:54:33 +0000 UTC}
i: 1 , value: {true 192 2019-08-21 00:54:33 +0000 UTC}
i: 1 , value: {false 192 2019-08-21 00:54:33 +0000 UTC}
//--------------------------------------------------//
i: 2 , value: {3 192 2019-08-21 00:54:34 +0000 UTC}
i: 2 , value: {true 192 2019-08-21 00:54:34 +0000 UTC}
i: 2 , value: {false 192 2019-08-21 00:54:34 +0000 UTC}
//--------------------------------------------------//
i: 3 , value: {3 192 2019-08-21 00:54:35 +0000 UTC}
i: 3 , value: {true 192 2019-08-21 00:54:35 +0000 UTC}
i: 3 , value: {false 192 2019-08-21 00:54:35 +0000 UTC}
//--------------------------------------------------//
i: 4 , value: {3 192 2019-08-21 00:54:36 +0000 UTC}
i: 4 , value: {true 192 2019-08-21 00:54:36 +0000 UTC}
i: 4 , value: {false 192 2019-08-21 00:54:36 +0000 UTC}
//--------------------------------------------------//
i: 5 , value: {3 192 2019-08-21 00:54:37 +0000 UTC}
i: 5 , value: {true 192 2019-08-21 00:54:37 +0000 UTC}
i: 5 , value: {false 192 2019-08-21 00:54:37 +0000 UTC}
//--------------------------------------------------//

question:
The value of the first reading is not right The values read the second time and after that are correct.

func main() {
opc.Debug()

client, err := opc.NewConnection("Kepware.KEPServerEX.V6", []string{"localhost"}, []string{})
if err != nil {
	fmt.Println(err)
	return
}

for i := 0; i < 100; i++ {

	err := client.Add("test.test1.1")
	if err != nil {
		fmt.Println(err)
	}
	v := client.ReadItem("test.test1.1")
	fmt.Println("i: ", i, ", value: ", v)

	err = client.Add("test.test1.2")
	if err != nil {
		fmt.Println(err)
	}
	v = client.ReadItem("test.test1.2")
	fmt.Println("i: ", i, ", value: ", v)

	err = client.Add("test.test1.3")
	if err != nil {
		fmt.Println(err)
	}
	v = client.ReadItem("test.test1.3")
	fmt.Println("i: ", i, ", value: ", v)
	time.Sleep(time.Second)
	fmt.Println("//--------------------------------------------------//")
}

defer client.Close()

}

output:
API server listening at: 127.0.0.1:10734
2019/08/21 09:04:13 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/21 09:04:13 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/21 09:04:13 Connecting to Kepware.KEPServerEX.V6 on node localhost
2019/08/21 09:06:13 Connected.
i: 0 , value: {nil 8 2019-08-21 01:06:13 +0000 UTC}
i: 0 , value: {nil 8 2019-08-21 01:06:13 +0000 UTC}
i: 0 , value: {nil 8 2019-08-21 01:06:13 +0000 UTC}
//--------------------------------------------------//
i: 1 , value: {nil 8 2019-08-21 01:06:14 +0000 UTC}
i: 1 , value: {nil 8 2019-08-21 01:06:14 +0000 UTC}
i: 1 , value: {nil 8 2019-08-21 01:06:14 +0000 UTC}
//--------------------------------------------------//
i: 2 , value: {nil 8 2019-08-21 01:06:15 +0000 UTC}
i: 2 , value: {true 192 2019-08-21 01:06:15 +0000 UTC}
i: 2 , value: {nil 8 2019-08-21 01:06:15 +0000 UTC}
//--------------------------------------------------//
i: 8 , value: {nil 8 2019-08-21 01:06:21 +0000 UTC}
i: 8 , value: {nil 8 2019-08-21 01:06:21 +0000 UTC}
i: 8 , value: {false 192 2019-08-21 01:06:21 +0000 UTC}
//--------------------------------------------------//
i: 25 , value: {3 192 2019-08-21 01:06:38 +0000 UTC}
i: 25 , value: {nil 8 2019-08-21 01:06:38 +0000 UTC}
i: 25 , value: {nil 8 2019-08-21 01:06:38 +0000 UTC}
//--------------------------------------------------//

question:
is wrong siganl item add some times? But the one below is fine.that is connected another opc service

func main() {
opc.Debug()

client, err := opc.NewConnection("OPC.SimaticNET.1", []string{"localhost"}, []string{})
if err != nil {
	fmt.Println(err)
	return
}

for i := 0; i < 10000; i++ {
	err := client.Add("S7:[@LOCALSERVER]DB1,INT17")
	if err != nil {
		fmt.Println(err)
	}
	v := client.ReadItem("S7:[@LOCALSERVER]DB1,INT17")
	fmt.Println("i: ", i, ", value: ", v)

	err = client.Add("S7:[@LOCALSERVER]DB1,INT117")
	if err != nil {
		fmt.Println(err)
	}
	v = client.ReadItem("S7:[@LOCALSERVER]DB1,INT117")
	fmt.Println("i: ", i, ", value: ", v)

	err = client.Add("S7:[@LOCALSERVER]DB1,X99.2")
	if err != nil {
		fmt.Println(err)
	}
	v = client.ReadItem("S7:[@LOCALSERVER]DB1,X99.2")
	fmt.Println("i: ", i, ", value: ", v)
	time.Sleep(time.Second)
	fmt.Println("//--------------------------------------------------//")
}
defer client.Close()

}
output:
2019/08/21 09:15:20 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/21 09:15:20 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/21 09:15:20 Connecting to OPC.SimaticNET.1 on node localhost
2019/08/21 09:19:07 Connected.
i: 0 , value: {3 192 2019-08-20 14:40:12 +0000 UTC}
i: 0 , value: {2 192 2019-08-20 14:40:12 +0000 UTC}
i: 0 , value: {false 192 2019-08-20 14:40:12 +0000 UTC}
//--------------------------------------------------//
i: 1 , value: {3 192 2019-08-21 01:19:09 +0000 UTC}
i: 1 , value: {2 192 2019-08-21 01:19:09 +0000 UTC}
i: 1 , value: {false 192 2019-08-21 01:19:09 +0000 UTC}
//--------------------------------------------------//
i: 2 , value: {3 192 2019-08-21 01:19:10 +0000 UTC}
i: 2 , value: {2 192 2019-08-21 01:19:10 +0000 UTC}
i: 2 , value: {false 192 2019-08-21 01:19:10 +0000 UTC}
//--------------------------------------------------//
i: 3 , value: {3 192 2019-08-21 01:19:11 +0000 UTC}
i: 3 , value: {2 192 2019-08-21 01:19:11 +0000 UTC}
i: 3 , value: {false 192 2019-08-21 01:19:11 +0000 UTC}
//--------------------------------------------------//
i: 4 , value: {3 192 2019-08-21 01:19:12 +0000 UTC}
i: 4 , value: {2 192 2019-08-21 01:19:12 +0000 UTC}
i: 4 , value: {false 192 2019-08-21 01:19:12 +0000 UTC}
//--------------------------------------------------//
i: 97 , value: {3 192 2019-08-21 01:20:45 +0000 UTC}
i: 97 , value: {2 192 2019-08-21 01:20:45 +0000 UTC}
i: 97 , value: {false 192 2019-08-21 01:20:45 +0000 UTC}
//--------------------------------------------------//
i: 98 , value: {3 192 2019-08-21 01:20:46 +0000 UTC}
i: 98 , value: {2 192 2019-08-21 01:20:46 +0000 UTC}
i: 98 , value: {false 192 2019-08-21 01:20:46 +0000 UTC}
//--------------------------------------------------//
i: 99 , value: {3 192 2019-08-21 01:20:47 +0000 UTC}
i: 99 , value: {2 192 2019-08-21 01:20:47 +0000 UTC}
i: 99 , value: {false 192 2019-08-21 01:20:47 +0000 UTC}

all of the value is right

Opc connections take a long time, two minutes at a time some maybe take more

func main() {
opc.Debug()

   client, err := opc.NewConnection("OPC.SimaticNET.1", []string{"localhost"}, []string{})
   if err != nil {
      fmt.Println(err)
  return

}
}

output:
2019/08/21 09:15:20 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/21 09:15:20 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/21 09:15:20 Connecting to OPC.SimaticNET.1 on node localhost
2019/08/21 09:19:07 Connected.

func main() {
opc.Debug()
client, err := opc.NewConnection("Kepware.KEPServerEX.V6", []string{"localhost"},
[]string{""})
if err != nil {
fmt.Println(err)
return
}
}

output:
API server listening at: 127.0.0.1:10734
2019/08/21 09:04:13 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/21 09:04:13 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/21 09:04:13 Connecting to Kepware.KEPServerEX.V6 on node localhost
2019/08/21 09:06:13 Connected.

Hi @HOULL2 this has also been discussed in #11
see here

Some OPC simulation server, after a fresh start, report garbage values before they are properly initialized.

It's always important to check the quality values of the returned items (opc.OPCQualityGood = 192); the quality values of your failed returned items was 8, and thus not proper values.