Code examples Opc Ua Sdk

The integration of PLCcom.Opc.Ua.Sdk is very easy and user-friendly.
The following examples will show you the most important functionality.

You will find other documentations with more code examples in our example application in the download package or online.

The provided endpoints of an OPC UA server can be determined with the command GetEndpoints (.net) or discoverEndpoints (Java).

Please see the following complete working sample:

Example: Discover OPC UA Server

Connecting an OPC UA server can be performed automatically or manually.

By default, a client automatically connects to the server when a connection is required. The reconnect after a connection break also takes place automatically.

The behavior can be set using the AutoConnect property of the client object.

DataAccessClient client = new DataAccessClient(„< Enter your UserName here >“, „< Enter your Serial here >“, sessionConfiguration, false);
or
client.AutoConnect = false;

Please see the following complete working sample:

Example: Connect to endpoint

The nodes of an OPC UA server can be browsed with the "Browse" command.

Simple Example:
ReferenceDescription rd = client.Browse(„Objects.Server.Data.Static“) ;

Please see the following complete working sample:

Example: Browse nodes

Reading or writing of values can take place either via the NodeId or directly over the complete name / path of the node:

Example for reading a node:
DataValue value = client.ReadValue(„Objects.Server.Data.Static.Scalar.Int64Value“);

Example for writing the value 123 to a node:
StatusCode sc = client.WriteValue(„Objects.Server.Data.Static.Scalar.Int64Value“,123);

Please see the following complete working sample:

Example: Read or write values

The monitoring of items can be done either via the NodeId or directly over the complete name / path of the node:

Example:

//create and register monitoring item
client.StartMonitoringItem(„Objects.Server.Data.Dynamic.Scalar.Int64Value“, Client_MonitorNotification);

//catch the monitoring event
private void Client_MonitorNotification(string Identifier, MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
Console.WriteLine(Identifier + “ “ + monitoredItem.StartNodeId + “ Value: “ + notification.Value + “ Status: “ + notification.Value.StatusCode.ToString());
}

Please see the following complete working sample:

Example: Monitoring items