Skip to content

Latest commit

 

History

History
118 lines (105 loc) · 2.74 KB

README.md

File metadata and controls

118 lines (105 loc) · 2.74 KB

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")