.NET Based OPC UA Client/Server SDK  3.0.10.493
Read – Read With Index Range

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example for implementation of the Read service, which allows the user to select a subset of an array variable to read. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

clienttutorials_read_with_index_range.png

On pressing the button “...” at “Read Request”, a window for browsing the address space opens. Expand the tree, select an array variable and press “OK”.

clienttutorials_read_attribute2.png

The NodeId is now displayed in the field “Node Id”.

Specify the subset of the array variable to be read, either in the form “n” to read the n-th entry or “n:m” to read the entries from n to m.

clienttutorials_read_with_index_range2.png

On pressing the button “Read”, the values of the specified subset of the array variable is read and displayed in the corresponding field at “Read Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginRead” instead of “Read”. Press the button “...” to display more details of the read response.

clienttutorials_read_with_index_range3.png

Sample Code

The following code reads the specified subset of an array value of a given node ID from the server and displays it in the user interface.

The numeric range is specified as text in the GUI. We first check whether the string has a syntactically correct format. The Read service is called in the same way as in Read – Basic Read and Read – Read Attribute. The IndexRange is set as a string in the class UaBase.ReadValueId.

// let's pre-validate the index range.
try
{
NumericRange.Parse(IndexRangeTB.Text);
}
catch (Exception)
{
m_parent.ShowError(this, "The IndexRange must have the form 'n' or 'n:m' where 'n' is the first index to read and 'm' is the last index.");
return;
}
// parse the node id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
List<ReadValueId> nodesToRead = new List<ReadValueId>();
// read the display name and the selected attribute for the node.
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = Attributes.DisplayName });
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = Attributes.Value, IndexRange = IndexRangeTB.Text });
// 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 });