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

connection.Read returns 0 when reading a Kepware Server tag

Lynckx opened this issue · comments

I'm trying to read simulated values from a Kepware server but the connection.Read returns 0 while the tag i'm trying to read can't be 0.

package main

import (
	"fmt"

	"github.com/konimarti/opc"
)

func main() {
	opc.Debug()
	client, err := opc.NewConnection(
		"Kepware.KEPServerEX.V6",
		[]string{"localhost"},
		[]string{"Channel1.Device1.Sinus1"},
	)
	defer client.Close()
	if err != nil {
		panic(err)
	}
	// read single tag: value, quality, timestamp
	fmt.Println(client.ReadItem("Channel1.Device1.Sinus1"))
}

returns this:

2019/07/10 16:39:06 Could not load OPC Automation object with wrapper OPC.Automation.1                                                                                                                                   2019/07/10 16:39:06 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/07/10 16:39:06 Connecting to Kepware.KEPServerEX.V6 on node localhost
2019/07/10 16:39:06 Connected.
{<nil> 8 2019-07-10 14:39:06 +0000 UTC}

what executable do you mean exactly?

Some simulation servers return garbage values on the first read. A second read then returns reasonable values. See the example below from the Graybox simulation server after a system restart:

PS C:\> opc-cli.exe read localhost Graybox.Simulator numeric.sin.float
map[numeric.sin.float:{0 32 1601-01-01 00:00:00 +0000 UTC}]
PS C:\> opc-cli.exe read localhost Graybox.Simulator numeric.sin.float                                          
map[numeric.sin.float:{99.99495 192 2019-07-11 08:55:21 +0000 UTC}]

I don't have a Kepware server installed so I can't really test the server specifics.

The readings after the first reading are indeed usable data. thanks.

2019/07/11 11:22:36 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/07/11 11:22:36 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/07/11 11:22:36 Connecting to Kepware.KEPServerEX.V6 on node localhost
2019/07/11 11:22:36 Connected.
{<nil> 8 2019-07-11 09:22:37 +0000 UTC}
{16.90839 192 2019-07-11 09:22:37 +0000 UTC}
{16.90839 192 2019-07-11 09:22:38 +0000 UTC}
{9.739066 192 2019-07-11 09:22:39 +0000 UTC}