konimarti / opc

OPC DA client in Golang for monitoring and analyzing process data based on Windows COM.
MIT License
237 stars 85 forks source link

connection.Read returns 0 when reading a Kepware Server tag #11

Closed Lynckx closed 5 years ago

Lynckx commented 5 years ago

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}
konimarti commented 5 years ago

Did you try to run the executable twice in a row?

On Wed, 10 Jul 2019, 16:52 Rutger Luyckx, notifications@github.com wrote:

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. { 8 2019-07-10 14:39:06 +0000 UTC}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/konimarti/opc/issues/11?email_source=notifications&email_token=AHMKOVXVUZYHYD7M7HRZAADP6XZTFA5CNFSM4H7QHAUKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G6MBC5A, or mute the thread https://github.com/notifications/unsubscribe-auth/AHMKOVVSHHQISEPGKT3DWGDP6XZTFANCNFSM4H7QHAUA .

Lynckx commented 5 years ago

what executable do you mean exactly?

konimarti commented 5 years ago

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.

Lynckx commented 5 years ago

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}