.NET Based OPC UA Client/Server SDK  2.6.0.418
Read – Basic Read

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example of a basic implementation of the Read service. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

clienttutorials_basic_read.png

On pressing the button “Read”, the two variables Server/ServerStatus/State and Server/ServerStatus/CurrentTime are read. The response, i.e. the value of the variables is displayed in the corresponding fields at “Read Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginRead” instead of “Read”.

See Read – Read Attribute for an example which allows the user to select the Node and the attribute to read.

Sample Code

The following code reads the values of two OPC UA defined variables from the server and displays the values in the user interface.

The SDK provides classes that contain constants for NodeIds of nodes that are defined in the OPC UA standard model, e.g.

In this example, the value of two nodes from the standard namespace are read, so we can use some these constants to get the NodeIds.

// build a list of values to read.
List<ReadValueId> nodesToRead = new List<ReadValueId>();
// read the current time and state from the server using the predefined node ids.
nodesToRead.Add(new ReadValueId() { NodeId = VariableIds.Server_ServerStatus_State, AttributeId = Attributes.Value });
nodesToRead.Add(new ReadValueId() { NodeId = VariableIds.Server_ServerStatus_CurrentTime, AttributeId = Attributes.Value });
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
// read the value (setting a 10 second timeout).
List<DataValue> results = session.Read(
nodesToRead,
0,
new RequestSettings() { OperationTimeout = 10000 });