Skip to content

An Implementation of the OPC-XML-DA Protocol in Go.

License

Notifications You must be signed in to change notification settings

dernate/gopcxmlda

Repository files navigation

gopcxmlda

An Implementation of the OPC-XML-DA Protocol in Go. See https://www.opcconnect.com/xml.php#xmlspec or here in the repository

Status

The basic functions of the OPC-XML-DA protocol are implemented in gopcxmlda. The project is therefore in maintenance or "bug-fix" status. No new functions are planned.

Supported OPC-XML-DA Methods:

  • GetStatus
  • Browse
  • Read
  • Write
  • Subscribe
  • GetProperties

Usage

Basic Procedure

Basic usage is as follows:

package main
import (
    "github.com/dernate/gopcxmlda"
)

func main() {
	_url, _ := url.Parse("http://your.opc-xml-da.server"),
	s := Server{
		_url,
		"en-US", 
		10,
	}
}

GetStatus

var ClientRequestHandle string
status, err := s.GetStatus(context.Background(), ClientRequestHandle, "ns1")

Browse

options := TBrowseOptions{}
var ClientRequestHandle string
browseResponse, err := s.Browse(context.Background(), "my/OPC/path", ClientRequestHandle, "ns1", options)

Read

items := []TItem{
    {
        ItemName: "my/OPC/path",
    },
    {
        ItemName: "my/OPC/path2",
    },
}
options := map[string]string{
    "ReturnItemTime": true,
	"ReturnItemPath": true,
}
var ClientRequestHandle string
var ClientItemHandles []string
readResponse, err := s.Read(context.Background(), items, ClientRequestHandle, ClientItemHandles, "ns1", options)

Write

items := []TItem{
    {
        ItemName: "my/OPC/path",
        Value: TValue{
            Value: 123,
        },
    },
}
options := map[string]string{}
var ClientRequestHandle string
var ClientItemHandles []string
writeResponse, err := s.Write(context.Background(), items, ClientRequestHandle, ClientItemHandles, "ns1", options)

Subscribe

items := []TItem{
    {
        ItemName: "my/OPC/path",
    },
}
options := map[string]string{
    "ReturnItemTime": true,
    "ReturnItemPath": true,
    "ReturnItemName": true,
}
var ClientRequestHandle string
var ClientItemHandles []string
SubscriptionPingRate := 5000
subscribeResponse, err := s.Subscribe(context.Background(), items, ClientRequestHandle, ClientItemHandles, "ns1", true, SubscriptionPingRate, false, options)
// for the SubscriptionPolledRefresh and SubscriptionCancel functionality see client_test.go

GetProperties

items := []TItem{
    {
        ItemName: "my/OPC/path",
    },
}
propertyOptions := TPropertyOptions{
    ReturnAllProperties:  true,
    ReturnPropertyValues: true,
    ReturnErrorText:      true,
}
var ClientRequestHandle string
properties, err := s.GetProperties(context.Background(), items, propertyOptions, &ClientRequestHandle, "ns1")

About

An Implementation of the OPC-XML-DA Protocol in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages