UA Bundle SDK .NET  2.2.3.276
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
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.

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”.

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.

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.

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.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// nothing to do if no session.
if (session == null)
{
return;
}
// 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 });
// update the controls.
ValueLB.Text = results[0].ToString();
ValueTB.Text = results[1].ToString();
ValueTB.Tag = results[1];
}
catch (Exception exception)
{
ExceptionDlg.Show(this.Text, exception);
}