monitor

package
v0.0.0-...-d7a2235 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultCallbackBufferLen is the size of the internal buffer when using a callback-based subscription
	DefaultCallbackBufferLen = 8192

	// ErrSlowConsumer is returned when a subscriber does not keep up with the incoming messages
	ErrSlowConsumer = errors.New("slow consumer. messages may be dropped")
)

Functions

This section is empty.

Types

type DataChangeMessage

type DataChangeMessage struct {
	*ua.DataValue
	Error  error
	NodeID *ua.NodeID
}

DataChangeMessage represents the changed DataValue from the server. It also includes a reference to the sending NodeID and error (if any)

type ErrHandler

type ErrHandler func(*opcua.Client, *Subscription, error)

ErrHandler is a function that is called when there is an out of band issue with delivery

type Item

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

Item is a struct to manage Monitored Items

func (*Item) ID

func (m *Item) ID() uint32

ID returns the MonitorItemID set by the server

func (*Item) NodeID

func (m *Item) NodeID() *ua.NodeID

NodeID returns the NodeID for the Item

type MsgHandler

type MsgHandler func(*Subscription, *DataChangeMessage)

MsgHandler is a function that is called for each new DataValue

type NodeMonitor

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

NodeMonitor creates new subscriptions

func NewNodeMonitor

func NewNodeMonitor(client *opcua.Client) (*NodeMonitor, error)

NewNodeMonitor creates a new NodeMonitor

func (*NodeMonitor) ChanSubscribe

func (m *NodeMonitor) ChanSubscribe(ctx context.Context, params *opcua.SubscriptionParameters, ch chan<- *DataChangeMessage, nodes ...string) (*Subscription, error)

ChanSubscribe creates a new channel-based subscription and an optional list of nodes. The channel should be deep enough to allow some buffering, otherwise `ErrSlowConsumer` is sent via the monitor's `ErrHandler`. The caller must call `Unsubscribe` to stop and clean up resources. Canceling the context will also cause the subscription to stop, but `Unsubscribe` must still be called.

func (*NodeMonitor) SetErrorHandler

func (m *NodeMonitor) SetErrorHandler(cb ErrHandler)

SetErrorHandler sets an optional callback for async errors

func (*NodeMonitor) Subscribe

func (m *NodeMonitor) Subscribe(ctx context.Context, params *opcua.SubscriptionParameters, cb MsgHandler, nodes ...string) (*Subscription, error)

Subscribe creates a new callback-based subscription and an optional list of nodes. The caller must call `Unsubscribe` to stop and clean up resources. Canceling the context will also cause the subscription to stop, but `Unsubscribe` must still be called.

type Request

type Request struct {
	NodeID               *ua.NodeID
	MonitoringMode       ua.MonitoringMode
	MonitoringParameters *ua.MonitoringParameters
	// contains filtered or unexported fields
}

Request is a struct to manage a request to monitor a node

type Subscription

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

Subscription is an instance of an active subscription. Nodes can be added and removed concurrently.

func (*Subscription) AddMonitorItems

func (s *Subscription) AddMonitorItems(nodes ...Request) ([]Item, error)

AddMonitorItems adds nodes with monitoring parameters to the subscription

func (*Subscription) AddNodeIDs

func (s *Subscription) AddNodeIDs(nodes ...*ua.NodeID) error

AddNodeIDs adds nodes

func (*Subscription) AddNodes

func (s *Subscription) AddNodes(nodes ...string) error

AddNodes adds nodes defined by their string representation

func (*Subscription) Delivered

func (s *Subscription) Delivered() uint64

Delivered returns the number of DataChangeMessages delivered

func (*Subscription) Dropped

func (s *Subscription) Dropped() uint64

Dropped returns the number of DataChangeMessages dropped due to a slow consumer

func (*Subscription) RemoveMonitorItems

func (s *Subscription) RemoveMonitorItems(items ...Item) error

RemoveMonitorItems removes nodes

func (*Subscription) RemoveNodeIDs

func (s *Subscription) RemoveNodeIDs(nodes ...*ua.NodeID) error

RemoveNodeIDs removes nodes

func (*Subscription) RemoveNodes

func (s *Subscription) RemoveNodes(nodes ...string) error

RemoveNodes removes nodes defined by their string representation

func (*Subscription) Stats

Stats returns statistics for the subscription

func (*Subscription) Subscribed

func (s *Subscription) Subscribed() int

Subscribed returns the number of currently subscribed to nodes

func (*Subscription) SubscriptionID

func (s *Subscription) SubscriptionID() uint32

SubscriptionID returns the underlying subscription id

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe() error

Unsubscribe removes the subscription interests and cleans up any resources

Jump to

Keyboard shortcuts

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