UA Bundle SDK .NET  2.2.0.255
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Read – Read Attribute

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example implementation of the Read service which allows the user to select the Node and the Attribute to read. Press the button “Show Code” to display the corresponding code, and the button “Help” for further information.

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

The NodeId is now displayed in the field “Node Id” and you can select the attribute to read from the corresponding drop-down menu.

On pressing the button “Read”, the value of the node’s attribute is read and displayed in the corresponding field at “Read Response”. Press the button “...” to view details for the value. Check the box in front of “Use Asynchronous Pattern” to call “BeginRead” instead of “Read”.

See Read – Read With Index Range for an example for reading only a subset of an array variable.

Sample Code

The following code reads the selected Attribute for the selected Node from the server.

try
{
// build a list of values to read.
List<ReadValueId> nodesToRead = new List<ReadValueId>();
// parse the node id and get the selected attribute id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
uint attributeId = ((DropDownItem)AttributeCB.SelectedItem).AttributeId;
// 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 = attributeId });
// 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);
}