opcda

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 10 Imported by: 0

README

Go OPC DA Client

OPC_DA_WIN codecov Go Report Card Go Reference

English | 简体中文

This is an OPC DA client written in Go language, allowing you to communicate with OPC DA servers and retrieve data. OPC DA is a commonly used industrial automation communication protocol that enables data exchange between devices and control systems.

Features

  • Get all OPC DA servers
  • Connect to OPC DA server
  • Browse tags on OPC DA server
  • Synchronously read tag values
  • Asynchronously read tag values
  • Synchronously write tag values
  • Asynchronously write tag values
  • Subscribe to real-time data changes of tags

Prerequisites

Before using this client, make sure you meet the following prerequisites:

  • Windows operating system with amd64/i386 architecture
  • Go version 1.20 or higher

Go 1.20 is the last version that supports Microsoft Windows 7 / 8 / Server 2008 / Server 2012. To ensure compatibility, this client will continue to support Go 1.20.

Testing is done with both Go 1.20 and the latest version of Go, covering both 32-bit and 64-bit testing.

Installation

Use the following command to install this client:

go get github.com/huskar-t/opcda

Types

This client provides support for the following types:

OPC Type Go Type Description
VT_BOOL bool Boolean value
VT_I1 int8 8-bit signed integer
VT_I2 int16 16-bit signed integer
VT_I4 int32 32-bit signed integer
VT_I8 int64 64-bit signed integer
VT_UI1 uint8 8-bit unsigned integer
VT_UI2 uint16 16-bit unsigned integer
VT_UI4 uint32 32-bit unsigned integer
VT_UI8 uint64 64-bit unsigned integer
VT_R4 float32 32-bit floating point number
VT_R8 float64 64-bit floating point number
VT_BSTR string String
VT_DATE time.Time Date time
VT_ARRAY|VT_BOOL []bool Boolean array
VT_ARRAY|VT_I1 []int8 8-bit signed integer array
VT_ARRAY|VT_I2 []int16 16-bit signed integer array
VT_ARRAY|VT_I4 []int32 32-bit signed integer array
VT_ARRAY|VT_I8 []int64 64-bit signed integer array
VT_ARRAY|VT_UI1 []uint8 8-bit unsigned integer array
VT_ARRAY|VT_UI2 []uint16 16-bit unsigned integer array
VT_ARRAY|VT_UI4 []uint32 32-bit unsigned integer array
VT_ARRAY|VT_UI8 []uint64 64-bit unsigned integer array
VT_ARRAY|VT_R4 []float32 32-bit floating point number array
VT_ARRAY|VT_R8 []float64 64-bit floating point number array
VT_ARRAY|VT_BSTR []string String array
VT_ARRAY|VT_DATE []time.Time Date time array

Other types are not currently supported.

Usage Examples

API Documentation

All APIs can be found in the API documentation.

Why Choose This Client

  1. There is currently no mature OPC DA client in the Go language ecosystem, and this client was developed to fill this gap.
  2. This client is written purely in Go language and supports both 32-bit and 64-bit architectures.
  3. This client also provides relatively complete functionality, including reading, writing, and subscribing to real-time data changes of tags.
Why Not konimarti/opc
  1. konimarti/opc uses the OPC DA Automation Wrapper interface, which cannot be modified for bug fixes. For example, using the Graybox DA Automation Wrapper cannot compile for 64-bit operation (HIGHENTROPYVA is enabled by default, leading to out-of-bounds memory address conversion within the Wrapper).
  2. There are memory leaks when reading string types.
  3. Insufficient functionality, such as inability to subscribe to real-time data changes of tags.
  4. go-ole has not been updated #252, making it unable to obtain millisecond timestamps.

Frequently Questions

  1. Cross-platform support

    This client only supports the Windows operating system.

  2. Multi-platform compilation

    This client cannot be compiled on non-Windows platforms because it relies on Windows platform COM interfaces. If the program needs to support multiple platforms, interfaces can be encapsulated, and non-Windows platform interfaces can be set to empty implementations.

  3. Memory leaks

    This client uses COM interfaces, and memory release has been handled internally, with fatigue testing done for all supported types. However, if memory leak issues are found during use, you can submit an issue and provide reproduction steps.

Documentation

Index

Constants

View Source
const (
	OPC_READABLE uint32 = 0x1

	OPC_WRITEABLE = 0x2
)
View Source
const (
	OPC_DS_CACHE  com.OPCDATASOURCE = 1
	OPC_DS_DEVICE com.OPCDATASOURCE = OPC_DS_CACHE + 1
)
View Source
const (
	OPC_NS_HIERARCHIAL com.OPCNAMESPACETYPE = 1
	OPC_NS_FLAT        com.OPCNAMESPACETYPE = OPC_NS_HIERARCHIAL + 1
)
View Source
const (
	OPC_STATUS_RUNNING    com.OPCServerState = 1
	OPC_STATUS_FAILED                        = OPC_STATUS_RUNNING + 1
	OPC_STATUS_NOCONFIG                      = OPC_STATUS_FAILED + 1
	OPC_STATUS_SUSPENDED                     = OPC_STATUS_NOCONFIG + 1
	OPC_STATUS_TEST                          = OPC_STATUS_SUSPENDED + 1
	OPC_STATUS_COMM_FAULT                    = OPC_STATUS_TEST + 1
)
View Source
const (
	OPC_BROWSE_UP   com.OPCBROWSEDIRECTION = 1
	OPC_BROWSE_DOWN com.OPCBROWSEDIRECTION = OPC_BROWSE_UP + 1
	OPC_BROWSE_TO   com.OPCBROWSEDIRECTION = OPC_BROWSE_DOWN + 1
)
View Source
const (
	OPC_BRANCH com.OPCBROWSETYPE = 1
	OPC_LEAF   com.OPCBROWSETYPE = OPC_BRANCH + 1
	OPC_FLAT   com.OPCBROWSETYPE = OPC_LEAF + 1
)
View Source
const (
	OPC_ENUM_PRIVATE_CONNECTIONS = 1
	OPC_ENUM_PUBLIC_CONNECTIONS  = OPC_ENUM_PRIVATE_CONNECTIONS + 1
	OPC_ENUM_ALL_CONNECTIONS     = OPC_ENUM_PUBLIC_CONNECTIONS + 1
	OPC_ENUM_PRIVATE             = OPC_ENUM_ALL_CONNECTIONS + 1
	OPC_ENUM_PUBLIC              = OPC_ENUM_PRIVATE + 1
	OPC_ENUM_ALL                 = OPC_ENUM_PUBLIC + 1
)

Variables

View Source
var (
	OPCInvalidHandle   = uint32(0xC0040001)
	OPCBadType         = uint32(0xC0040004)
	OPCPublic          = uint32(0xC0040005)
	OPCBadRights       = uint32(0xC0040006)
	OPCUnknownItemID   = uint32(0xC0040007)
	OPCInvalidItemID   = uint32(0xC0040008)
	OPCInvalidFilter   = uint32(0xC0040009)
	OPCUnknownPath     = uint32(0xC004000A)
	OPCRange           = uint32(0xC004000B)
	OPCDuplicateName   = uint32(0xC004000C)
	OPCUnsupportedRate = uint32(0x0004000D)
	OPCClamp           = uint32(0x0004000E)
	OPCInuse           = uint32(0x0004000F)
	OPCInvalidConfig   = uint32(0xC0040010)
	OPCNotFound        = uint32(0xC0040011)
	OPCInvalidPID      = uint32(0xC0040203)
)
View Source
var IID_CATID_OPCDAServer10 = windows.GUID{
	Data1: 0x63D5F430,
	Data2: 0xCFE4,
	Data3: 0x11d1,
	Data4: [8]byte{0xB2, 0xC8, 0x00, 0x60, 0x08, 0x3B, 0xA1, 0xFB},
}
View Source
var IID_CATID_OPCDAServer20 = windows.GUID{
	Data1: 0x63D5F432,
	Data2: 0xCFE4,
	Data3: 0x11d1,
	Data4: [8]byte{0xB2, 0xC8, 0x00, 0x60, 0x08, 0x3B, 0xA1, 0xFB},
}
View Source
var IID_IOPCDataCallback = windows.GUID{
	Data1: 0x39c13a70,
	Data2: 0x011e,
	Data3: 0x11d0,
	Data4: [8]byte{0x96, 0x75, 0x00, 0x20, 0xaf, 0xd8, 0xad, 0xb3},
}
View Source
var IID_IOPCShutdown = windows.GUID{
	Data1: 0xF31DFDE1,
	Data2: 0x07B6,
	Data3: 0x11d2,
	Data4: [8]byte{0xB2, 0xD8, 0x00, 0x60, 0x08, 0x3B, 0xA1, 0xFB},
}

Functions

func DataAddRef

func DataAddRef(this unsafe.Pointer) uintptr

func DataOnCancelComplete

func DataOnCancelComplete(this unsafe.Pointer, dwTransid uint32, hGroup uint32) uintptr

func DataOnDataChange

func DataOnDataChange(this unsafe.Pointer, dwTransid uint32, hGroup uint32, hrMasterquality int32, hrMastererror int32, dwCount uint32, phClientItems unsafe.Pointer, pvValues unsafe.Pointer, pwQualities unsafe.Pointer, pftTimeStamps unsafe.Pointer, pErrors unsafe.Pointer) uintptr

func DataOnReadComplete

func DataOnReadComplete(this unsafe.Pointer, dwTransid uint32, hGroup uint32, hrMasterquality int32, hrMastererror int32, dwCount uint32, phClientItems unsafe.Pointer, pvValues unsafe.Pointer, pwQualities unsafe.Pointer, pftTimeStamps unsafe.Pointer, pErrors unsafe.Pointer) uintptr

func DataOnWriteComplete

func DataOnWriteComplete(this unsafe.Pointer, dwTransid uint32, hGroup uint32, hrMastererr int32, dwCount uint32, pClienthandles unsafe.Pointer, pErrors unsafe.Pointer) uintptr

func DataQueryInterface

func DataQueryInterface(this unsafe.Pointer, iid *windows.GUID, punk *unsafe.Pointer) uintptr

func DataRelease

func DataRelease(this unsafe.Pointer) uintptr

func ShutdownAddRef

func ShutdownAddRef(this unsafe.Pointer) uintptr

func ShutdownQueryInterface

func ShutdownQueryInterface(this unsafe.Pointer, iid *windows.GUID, punk *unsafe.Pointer) uintptr

func ShutdownRelease

func ShutdownRelease(this unsafe.Pointer) uintptr

func ShutdownRequest

func ShutdownRequest(this *com.IUnknown, pReason *uint16) uintptr

Types

type CCancelCompleteCallBackData

type CCancelCompleteCallBackData struct {
	TransID     uint32
	GroupHandle uint32
}

type CDataChangeCallBackData

type CDataChangeCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterQuality     int32
	MasterErr         int32
	ItemClientHandles []uint32
	Values            []interface{}
	Qualities         []uint16
	TimeStamps        []time.Time
	Errors            []int32
}

type CReadCompleteCallBackData

type CReadCompleteCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterQuality     int32
	MasterErr         int32
	ItemClientHandles []uint32
	Values            []interface{}
	Qualities         []uint16
	TimeStamps        []time.Time
	Errors            []int32
}

type CWriteCompleteCallBackData

type CWriteCompleteCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterErr         int32
	ItemClientHandles []uint32
	Errors            []int32
}

type CancelCompleteCallBackData

type CancelCompleteCallBackData struct {
	TransID     uint32
	GroupHandle uint32
}

type DataChangeCallBackData

type DataChangeCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterQuality     int32
	MasterErr         error
	ItemClientHandles []uint32
	Values            []interface{}
	Qualities         []uint16
	TimeStamps        []time.Time
	Errors            []error
}

type DataEventReceiver

type DataEventReceiver struct {
	// contains filtered or unexported fields
}

func NewDataEventReceiver

func NewDataEventReceiver(
	dataChangeReceiver chan *CDataChangeCallBackData,
	readCompleteReceiver chan *CReadCompleteCallBackData,
	writeCompleteReceiver chan *CWriteCompleteCallBackData,
	cancelCompleteReceiver chan *CCancelCompleteCallBackData,
) *DataEventReceiver

type DataEventReceiverVtbl

type DataEventReceiverVtbl struct {
	// contains filtered or unexported fields
}

type OPCBrowser

type OPCBrowser struct {
	// contains filtered or unexported fields
}

func NewOPCBrowser

func NewOPCBrowser(parent *OPCServer) (*OPCBrowser, error)

func (*OPCBrowser) GetAccessRights

func (b *OPCBrowser) GetAccessRights() uint32

GetAccessRights get the requested access rights that apply to the ShowLeafs methods

func (*OPCBrowser) GetCount

func (b *OPCBrowser) GetCount() int

GetCount Required property for collections

func (*OPCBrowser) GetCurrentPosition

func (b *OPCBrowser) GetCurrentPosition() (string, error)

GetCurrentPosition Returns the current position in the tree

func (*OPCBrowser) GetDataType

func (b *OPCBrowser) GetDataType() uint16

GetDataType get the requested data type that applies to ShowLeafs methods. This property defaults to com.VT_EMPTY, which means that any data type is acceptable.

func (*OPCBrowser) GetFilter

func (b *OPCBrowser) GetFilter() string

GetFilter get the filter that applies to ShowBranches and ShowLeafs methods

func (*OPCBrowser) GetItemID

func (b *OPCBrowser) GetItemID(leaf string) (string, error)

GetItemID Given a name, returns a valid ItemID that can be passed to OPCItems Add method.

func (*OPCBrowser) GetOrganization

func (b *OPCBrowser) GetOrganization() (com.OPCNAMESPACETYPE, error)

GetOrganization Returns either OPCHierarchical or OPCFlat.

func (*OPCBrowser) Item

func (b *OPCBrowser) Item(index int) (string, error)

Item returns the name of the item at the specified index. index is 0-based.

func (*OPCBrowser) MoveDown

func (b *OPCBrowser) MoveDown(name string) error

MoveDown Move down into this branch.

func (*OPCBrowser) MoveTo

func (b *OPCBrowser) MoveTo(branches []string) error

MoveTo Move to an absolute position.

func (*OPCBrowser) MoveToRoot

func (b *OPCBrowser) MoveToRoot()

MoveToRoot Move up to the first level in the tree.

func (*OPCBrowser) MoveUp

func (b *OPCBrowser) MoveUp() error

MoveUp Move up one level in the tree.

func (*OPCBrowser) Release

func (b *OPCBrowser) Release()

Release release the OPCBrowser

func (*OPCBrowser) SetAccessRights

func (b *OPCBrowser) SetAccessRights(accessRights uint32) error

SetAccessRights set the requested access rights that apply to the ShowLeafs methods

func (*OPCBrowser) SetDataType

func (b *OPCBrowser) SetDataType(dataType uint16)

SetDataType set the requested data type that applies to ShowLeafs methods.

func (*OPCBrowser) SetFilter

func (b *OPCBrowser) SetFilter(filter string)

SetFilter set the filter that applies to ShowBranches and ShowLeafs methods

func (*OPCBrowser) ShowBranches

func (b *OPCBrowser) ShowBranches() error

ShowBranches Fills the collection with names of the branches at the current browse position.

func (*OPCBrowser) ShowLeafs

func (b *OPCBrowser) ShowLeafs(flat bool) error

ShowLeafs Fills the collection with the names of the leafs at the current browse position

type OPCError

type OPCError struct {
	ErrorCode    int32
	ErrorMessage string
}

func (*OPCError) Error

func (e *OPCError) Error() string

type OPCGroup

type OPCGroup struct {
	// contains filtered or unexported fields
}

func NewOPCGroup

func NewOPCGroup(
	opcGroups *OPCGroups,
	iUnknown *com.IUnknown,
	clientGroupHandle uint32,
	serverGroupHandle uint32,
	groupName string,
	revisedUpdateRate uint32,
) (*OPCGroup, error)

func (*OPCGroup) AsyncCancel

func (g *OPCGroup) AsyncCancel(cancelID uint32) error

AsyncCancel Request that the server cancel an outstanding transaction. An AsyncCancelComplete event will occur indicating whether or not the cancel succeeded.

func (*OPCGroup) AsyncRead

func (g *OPCGroup) AsyncRead(
	serverHandles []uint32,
	clientTransactionID uint32,
) (cancelID uint32, errs []error, err error)

AsyncRead Read one or more items in a group. The results are returned via the AsyncReadComplete event associated with the OPCGroup object.

func (*OPCGroup) AsyncRefresh

func (g *OPCGroup) AsyncRefresh(
	source com.OPCDATASOURCE,
	clientTransactionID uint32,
) (cancelID uint32, err error)

AsyncRefresh Generate an event for all active items in the group (whether they have changed or not). Inactive items are not included in the callback. The results are returned via the DataChange event associated with the OPCGroup object.

func (*OPCGroup) AsyncWrite

func (g *OPCGroup) AsyncWrite(
	serverHandles []uint32,
	values []interface{},
	clientTransactionID uint32,
) (cancelID uint32, errs []error, err error)

AsyncWrite Write one or more items in a group. The results are returned via the AsyncWriteComplete event associated with the OPCGroup object.

func (*OPCGroup) GetClientHandle

func (g *OPCGroup) GetClientHandle() uint32

GetClientHandle get a Long value associated with the group

func (*OPCGroup) GetDeadband

func (g *OPCGroup) GetDeadband() (float32, error)

GetDeadband A deadband is expressed as percent of full scale (legal values 0 to 100).

func (*OPCGroup) GetIsActive

func (g *OPCGroup) GetIsActive() bool

GetIsActive Returns whether the group is active

func (*OPCGroup) GetLocaleID

func (g *OPCGroup) GetLocaleID() (uint32, error)

GetLocaleID get the locale identifier for the group

func (*OPCGroup) GetName

func (g *OPCGroup) GetName() string

GetName Returns the name of the group

func (*OPCGroup) GetParent

func (g *OPCGroup) GetParent() *OPCGroups

GetParent Returns reference to the parent OPCServer object

func (*OPCGroup) GetServerHandle

func (g *OPCGroup) GetServerHandle() uint32

GetServerHandle get the server assigned handle for the group

func (*OPCGroup) GetTimeBias

func (g *OPCGroup) GetTimeBias() (int32, error)

GetTimeBias This property provides the information needed to convert the time stamp on the data back to the local time of the device

func (*OPCGroup) GetUpdateRate

func (g *OPCGroup) GetUpdateRate() (uint32, error)

GetUpdateRate The fastest rate at which data change events may be fired. A slow process might cause data changes to fire at less than this rate, but they will never exceed this rate. Rate is in milliseconds. This property’s default depends on the value set in the OPCGroups Collection. Assigning a value to this property is a “request” for a new update rate. The server may not support that rate, so reading the property may result in a different rate (the server will use the closest rate it does support).

func (*OPCGroup) OPCItems

func (g *OPCGroup) OPCItems() *OPCItems

OPCItems A collection of OPCItem objects

func (*OPCGroup) RegisterCancelComplete

func (g *OPCGroup) RegisterCancelComplete(ch chan *CancelCompleteCallBackData) error

RegisterCancelComplete Register to receive cancel complete events

func (*OPCGroup) RegisterDataChange

func (g *OPCGroup) RegisterDataChange(ch chan *DataChangeCallBackData) error

RegisterDataChange Register to receive data change events

func (*OPCGroup) RegisterReadComplete

func (g *OPCGroup) RegisterReadComplete(ch chan *ReadCompleteCallBackData) error

RegisterReadComplete Register to receive read complete events

func (*OPCGroup) RegisterWriteComplete

func (g *OPCGroup) RegisterWriteComplete(ch chan *WriteCompleteCallBackData) error

RegisterWriteComplete Register to receive write complete events

func (*OPCGroup) Release

func (g *OPCGroup) Release()

Release Releases the resources used by the group

func (*OPCGroup) SetClientHandle

func (g *OPCGroup) SetClientHandle(clientHandle uint32) error

SetClientHandle set a Long value associated with the group

func (*OPCGroup) SetDeadband

func (g *OPCGroup) SetDeadband(deadband float32) error

SetDeadband A deadband is expressed as percent of full scale (legal values 0 to 100).

func (*OPCGroup) SetIsActive

func (g *OPCGroup) SetIsActive(isActive bool) error

SetIsActive set whether the group is active

func (*OPCGroup) SetLocaleID

func (g *OPCGroup) SetLocaleID(id uint32) error

SetLocaleID set the locale identifier for the group

func (*OPCGroup) SetName

func (g *OPCGroup) SetName(name string) error

SetName set the name of the group

func (*OPCGroup) SetTimeBias

func (g *OPCGroup) SetTimeBias(timeBias int32) error

SetTimeBias This property provides the information needed to convert the time stamp on the data back to the local time of the device

func (*OPCGroup) SetUpdateRate

func (g *OPCGroup) SetUpdateRate(updateRate uint32) error

SetUpdateRate set the update rate

func (*OPCGroup) SyncRead

func (g *OPCGroup) SyncRead(source com.OPCDATASOURCE, serverHandles []uint32) ([]*com.ItemState, error)

SyncRead This function reads the value, quality and timestamp information for one or more items in a group.

func (*OPCGroup) SyncWrite

func (g *OPCGroup) SyncWrite(serverHandles []uint32, values []interface{}) ([]error, error)

SyncWrite Writes values to one or more items in a group

type OPCGroups

type OPCGroups struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewOPCGroups

func NewOPCGroups(opcServer *OPCServer) *OPCGroups

func (*OPCGroups) Add

func (gs *OPCGroups) Add(szName string) (*OPCGroup, error)

Add Creates a new OPCGroup object and adds it to the collections

func (*OPCGroups) GetCount

func (gs *OPCGroups) GetCount() int

GetCount Required property for collections.

func (*OPCGroups) GetDefaultGroupDeadband

func (gs *OPCGroups) GetDefaultGroupDeadband() float32

GetDefaultGroupDeadband get the default deadband for OPCGroups created using Groups.Add

func (*OPCGroups) GetDefaultGroupIsActive

func (gs *OPCGroups) GetDefaultGroupIsActive() bool

GetDefaultGroupIsActive get the default active state for OPCGroups created using Groups.Add

func (*OPCGroups) GetDefaultGroupLocaleID

func (gs *OPCGroups) GetDefaultGroupLocaleID() uint32

GetDefaultGroupLocaleID get the default locale for OPCGroups created using Groups.Add.

func (*OPCGroups) GetDefaultGroupTimeBias

func (gs *OPCGroups) GetDefaultGroupTimeBias() int32

GetDefaultGroupTimeBias get the default time bias for OPCGroups created using Groups.Add.

func (*OPCGroups) GetDefaultGroupUpdateRate

func (gs *OPCGroups) GetDefaultGroupUpdateRate() uint32

GetDefaultGroupUpdateRate get the default update rate (in milliseconds) for OPCGroups created using Groups.Add

func (*OPCGroups) GetOPCGroup

func (gs *OPCGroups) GetOPCGroup(serverHandle uint32) (*OPCGroup, error)

GetOPCGroup Returns an OPCGroup by server handle

func (*OPCGroups) GetOPCGroupByName

func (gs *OPCGroups) GetOPCGroupByName(name string) (*OPCGroup, error)

GetOPCGroupByName Returns an OPCGroup by name

func (*OPCGroups) GetParent

func (gs *OPCGroups) GetParent() *OPCServer

GetParent Returns reference to the parent OPCServer object.

func (*OPCGroups) Item

func (gs *OPCGroups) Item(index int32) (*OPCGroup, error)

Item Returns an OPCGroup by ItemSpecifier. ItemSpecifier is the name or 0-based index into the collection

func (*OPCGroups) ItemByName

func (gs *OPCGroups) ItemByName(name string) (*OPCGroup, error)

ItemByName Returns an OPCGroup by name

func (*OPCGroups) Release

func (gs *OPCGroups) Release() error

Release Releases the resources used by the collection and the items it contains.

func (*OPCGroups) Remove

func (gs *OPCGroups) Remove(serverHandle uint32) error

Remove Removes an OPCGroup from the collection

func (*OPCGroups) RemoveAll

func (gs *OPCGroups) RemoveAll() error

RemoveAll Removes all OPCGroups from the collection

func (*OPCGroups) RemoveByName

func (gs *OPCGroups) RemoveByName(name string) error

RemoveByName Removes an OPCGroup from the collection by name

func (*OPCGroups) SetDefaultGroupDeadband

func (gs *OPCGroups) SetDefaultGroupDeadband(defaultDeadband float32)

SetDefaultGroupDeadband set the default deadband for OPCGroups created using Groups.Add

func (*OPCGroups) SetDefaultGroupIsActive

func (gs *OPCGroups) SetDefaultGroupIsActive(defaultActive bool)

SetDefaultGroupIsActive set the default active state for OPCGroups created using Groups.Add

func (*OPCGroups) SetDefaultGroupLocaleID

func (gs *OPCGroups) SetDefaultGroupLocaleID(defaultLocaleID uint32)

SetDefaultGroupLocaleID set the default locale for OPCGroups created using Groups.Add.

func (*OPCGroups) SetDefaultGroupTimeBias

func (gs *OPCGroups) SetDefaultGroupTimeBias(defaultGroupTimeBias int32)

SetDefaultGroupTimeBias set the default time bias for OPCGroups created using Groups.Add.

func (*OPCGroups) SetDefaultGroupUpdateRate

func (gs *OPCGroups) SetDefaultGroupUpdateRate(defaultGroupUpdateRate uint32)

SetDefaultGroupUpdateRate set the default update rate (in milliseconds) for OPCGroups created using Groups.Add

type OPCItem

type OPCItem struct {
	// contains filtered or unexported fields
}

func NewOPCItem

func NewOPCItem(
	parent *OPCItems,
	tag string,
	result com.TagOPCITEMRESULTStruct,
	clientHandle uint32,
	accessPath string,
	isActive bool,
) *OPCItem

func (*OPCItem) GetAccessPath

func (i *OPCItem) GetAccessPath() string

GetAccessPath get the access path for the item.

func (*OPCItem) GetAccessRights

func (i *OPCItem) GetAccessRights() uint32

GetAccessRights get the access rights for the item.

func (*OPCItem) GetCanonicalDataType

func (i *OPCItem) GetCanonicalDataType() com.VT

GetCanonicalDataType Returns the canonical data type for the item.

func (*OPCItem) GetClientHandle

func (i *OPCItem) GetClientHandle() uint32

GetClientHandle get the client handle for the item.

func (*OPCItem) GetEUInfo

func (i *OPCItem) GetEUInfo() (interface{}, error)

GetEUInfo Returns the EU info for the item.

func (*OPCItem) GetEUType

func (i *OPCItem) GetEUType() (int, error)

GetEUType Returns the EU type for the item.

func (*OPCItem) GetIsActive

func (i *OPCItem) GetIsActive() bool

GetIsActive get the active state for the item.

func (*OPCItem) GetItemID

func (i *OPCItem) GetItemID() string

GetItemID get the item ID for the item.

func (*OPCItem) GetParent

func (i *OPCItem) GetParent() *OPCItems

GetParent Returns reference to the parent OPCItems object.

func (*OPCItem) GetQuality

func (i *OPCItem) GetQuality() uint16

GetQuality Returns the latest quality read from the server

func (*OPCItem) GetRequestedDataType

func (i *OPCItem) GetRequestedDataType() com.VT

GetRequestedDataType get the requested data type for the item.

func (*OPCItem) GetServerHandle

func (i *OPCItem) GetServerHandle() uint32

GetServerHandle get the server handle for the item.

func (*OPCItem) GetTimestamp

func (i *OPCItem) GetTimestamp() time.Time

GetTimestamp Returns the latest timestamp read from the server

func (*OPCItem) GetValue

func (i *OPCItem) GetValue() interface{}

GetValue Returns the latest value read from the server

func (*OPCItem) Read

func (i *OPCItem) Read(source com.OPCDATASOURCE) (value interface{}, quality uint16, timestamp time.Time, err error)

Read makes a blocking call to read this item from the server.

func (*OPCItem) Release

func (i *OPCItem) Release()

Release Releases the OPCItem object

func (*OPCItem) SetClientHandle

func (i *OPCItem) SetClientHandle(clientHandle uint32) error

SetClientHandle set the client handle for the item.

func (*OPCItem) SetIsActive

func (i *OPCItem) SetIsActive(isActive bool) error

SetIsActive set the active state for the item.

func (*OPCItem) SetRequestedDataType

func (i *OPCItem) SetRequestedDataType(requestedDataType com.VT) error

SetRequestedDataType set the requested data type for the item.

func (*OPCItem) Write

func (i *OPCItem) Write(value interface{}) error

Write makes a blocking call to write this value to the server

type OPCItems

type OPCItems struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewOPCItems

func NewOPCItems(
	parent *OPCGroup,
	itemMgt *com.IOPCItemMgt,
	iCommon *com.IOPCCommon,
) *OPCItems

func (*OPCItems) AddItem

func (is *OPCItems) AddItem(tag string) (*OPCItem, error)

AddItem adds an item to the group.

func (*OPCItems) AddItems

func (is *OPCItems) AddItems(tags []string) ([]*OPCItem, []error, error)

AddItems adds items to the group.

func (*OPCItems) GetCount

func (is *OPCItems) GetCount() int

GetCount get the number of items in the collection

func (*OPCItems) GetDefaultAccessPath

func (is *OPCItems) GetDefaultAccessPath() string

GetDefaultAccessPath get the default AccessPath that will be used in calls to Add

func (*OPCItems) GetDefaultActive

func (is *OPCItems) GetDefaultActive() bool

GetDefaultActive get the default active state for OPCItems created using Items.Add

func (*OPCItems) GetDefaultRequestedDataType

func (is *OPCItems) GetDefaultRequestedDataType() com.VT

GetDefaultRequestedDataType get the requested data type that will be used in calls to Add

func (*OPCItems) GetOPCItem

func (is *OPCItems) GetOPCItem(serverHandle uint32) (*OPCItem, error)

GetOPCItem returns the OPCItem by serverHandle

func (*OPCItems) GetParent

func (is *OPCItems) GetParent() *OPCGroup

GetParent Returns reference to the parent OPCGroup object

func (*OPCItems) Item

func (is *OPCItems) Item(index int32) (*OPCItem, error)

Item get the item by index

func (*OPCItems) ItemByName

func (is *OPCItems) ItemByName(name string) (*OPCItem, error)

ItemByName get the item by name

func (*OPCItems) Release

func (is *OPCItems) Release()

Release Releases the OPCItems collection and all associated resources.

func (*OPCItems) Remove

func (is *OPCItems) Remove(serverHandles []uint32)

Remove Removes an OPCItem

func (*OPCItems) SetActive

func (is *OPCItems) SetActive(serverHandles []uint32, active bool) []error

SetActive Allows Activation and deactivation of individual OPCItem’s in the OPCItems Collection

func (*OPCItems) SetClientHandles

func (is *OPCItems) SetClientHandles(serverHandles []uint32, clientHandles []uint32) []error

SetClientHandles Changes the client handles or one or more Items in a Group.

func (*OPCItems) SetDataTypes

func (is *OPCItems) SetDataTypes(serverHandles []uint32, requestedDataTypes []com.VT) []error

SetDataTypes Changes the requested data type for one or more Items

func (*OPCItems) SetDefaultAccessPath

func (is *OPCItems) SetDefaultAccessPath(defaultAccessPath string)

SetDefaultAccessPath set the default AccessPath that will be used in calls to Add

func (*OPCItems) SetDefaultActive

func (is *OPCItems) SetDefaultActive(defaultActive bool)

SetDefaultActive set the default active state for OPCItems created using Items.Add

func (*OPCItems) SetDefaultRequestedDataType

func (is *OPCItems) SetDefaultRequestedDataType(defaultRequestedDataType com.VT)

SetDefaultRequestedDataType set the requested data type that will be used in calls to Add

func (*OPCItems) Validate

func (is *OPCItems) Validate(tags []string, requestedDataTypes *[]com.VT, accessPaths *[]string) ([]error, error)

Validate Determines if one or more OPCItems could be successfully created via the Add method (but does not add them).

type OPCServer

type OPCServer struct {
	Name string
	Node string
	// contains filtered or unexported fields
}

func Connect

func Connect(progID, node string) (opcServer *OPCServer, err error)

Connect connect to OPC server

func (*OPCServer) CreateBrowser

func (s *OPCServer) CreateBrowser() (*OPCBrowser, error)

CreateBrowser Creates an OPCBrowser object

func (*OPCServer) Disconnect

func (s *OPCServer) Disconnect() error

Disconnect from OPC server

func (*OPCServer) GetBandwidth

func (s *OPCServer) GetBandwidth() (uint32, error)

GetBandwidth Returns the bandwidth of the server

func (*OPCServer) GetBuildNumber

func (s *OPCServer) GetBuildNumber() (uint16, error)

GetBuildNumber Returns the build number of the server

func (*OPCServer) GetClientName

func (s *OPCServer) GetClientName() string

GetClientName Returns the client name of the client

func (*OPCServer) GetCurrentTime

func (s *OPCServer) GetCurrentTime() (time.Time, error)

GetCurrentTime Returns the current time from the server

func (*OPCServer) GetErrorString

func (s *OPCServer) GetErrorString(errorCode int32) (string, error)

GetErrorString Converts an error number to a readable string

func (*OPCServer) GetItemProperties

func (s *OPCServer) GetItemProperties(itemID string, propertyIDs []uint32) (data []interface{}, errors []error, err error)

GetItemProperties Return a list of the current data values for the passed ID codes.

func (*OPCServer) GetLastUpdateTime

func (s *OPCServer) GetLastUpdateTime() (time.Time, error)

GetLastUpdateTime Returns the last update time from the server

func (*OPCServer) GetLocaleID

func (s *OPCServer) GetLocaleID() (uint32, error)

GetLocaleID get locale ID

func (*OPCServer) GetMajorVersion

func (s *OPCServer) GetMajorVersion() (uint16, error)

GetMajorVersion Returns the major part of the server version number

func (*OPCServer) GetMinorVersion

func (s *OPCServer) GetMinorVersion() (uint16, error)

GetMinorVersion Returns the minor part of the server version number

func (*OPCServer) GetOPCGroups

func (s *OPCServer) GetOPCGroups() *OPCGroups

GetOPCGroups get a collection of OPCGroup objects

func (*OPCServer) GetServerName

func (s *OPCServer) GetServerName() string

GetServerName Returns the server name of the server that the client connected to via Connect().

func (*OPCServer) GetServerNode

func (s *OPCServer) GetServerNode() string

GetServerNode Returns the node name of the server that the client connected to via Connect().

func (*OPCServer) GetServerState

func (s *OPCServer) GetServerState() (com.OPCServerState, error)

GetServerState Returns the server’s state

func (*OPCServer) GetStartTime

func (s *OPCServer) GetStartTime() (time.Time, error)

GetStartTime Returns the time the server started running

func (*OPCServer) GetVendorInfo

func (s *OPCServer) GetVendorInfo() (string, error)

GetVendorInfo Returns the vendor information string for the server

func (*OPCServer) LookupItemIDs

func (s *OPCServer) LookupItemIDs(itemID string, propertyIDs []uint32) ([]string, []error, error)

LookupItemIDs Return a list of ItemIDs (if available) for each of the passed ID codes. have not tested because simulator return error

func (*OPCServer) QueryAvailableLocaleIDs

func (s *OPCServer) QueryAvailableLocaleIDs() ([]uint32, error)

QueryAvailableLocaleIDs Return the available LocaleIDs for this server/client session

func (*OPCServer) QueryAvailableProperties

func (s *OPCServer) QueryAvailableProperties(itemID string) (pPropertyIDs []uint32, ppDescriptions []string, ppvtDataTypes []uint16, err error)

QueryAvailableProperties Return a list of ID codes and Descriptions for the available properties for this ItemID

func (*OPCServer) RegisterServerShutDown

func (s *OPCServer) RegisterServerShutDown(ch chan string) error

RegisterServerShutDown register server shut down event

func (*OPCServer) SetClientName

func (s *OPCServer) SetClientName(clientName string) error

SetClientName Sets the client name of the client

func (*OPCServer) SetLocaleID

func (s *OPCServer) SetLocaleID(localeID uint32) error

SetLocaleID set locale ID

type PropertyDescription

type PropertyDescription struct {
	PropertyID   int32
	Description  string
	DataType     int16
	AccessRights int16
}

type ReadCompleteCallBackData

type ReadCompleteCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterQuality     int32
	MasterErr         error
	ItemClientHandles []uint32
	Values            []interface{}
	Qualities         []uint16
	TimeStamps        []time.Time
	Errors            []error
}

type ServerInfo

type ServerInfo struct {
	ProgID       string
	ClsStr       string
	VerIndProgID string
	ClsID        *windows.GUID
}

func GetOPCServers

func GetOPCServers(node string) ([]*ServerInfo, error)

GetOPCServers get OPC servers from node

type ShutdownEventReceiver

type ShutdownEventReceiver struct {
	// contains filtered or unexported fields
}

func NewShutdownEventReceiver

func NewShutdownEventReceiver() *ShutdownEventReceiver

func (*ShutdownEventReceiver) AddReceiver

func (er *ShutdownEventReceiver) AddReceiver(ch chan string)

type ShutdownEventReceiverVtbl

type ShutdownEventReceiverVtbl struct {
	// contains filtered or unexported fields
}

type WriteCompleteCallBackData

type WriteCompleteCallBackData struct {
	TransID           uint32
	GroupHandle       uint32
	MasterErr         error
	ItemClientHandles []uint32
	Errors            []error
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL