UA Bundle SDK .NET  2.4.2.373
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Modules Pages
Read – Read With Data Encoding

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example 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_read_with_data_encoding.png

Press the button “...” to open a Browse window and select a NodeId of a variable with a structured DataType, e.g. ServerStatus. Confirm your choice by pressing “OK”.

clienttutorials_read_attribute2.png

The NodeId is now displayed in the field “Node Id” and the drop-down shows all available Data Encodings for the DataType of the selected Variable node. Standard values are “Default Binary” and “Default XML”.

clienttutorials_read_with_data_encoding2.png

On pressing the button “Read”, the variable is read using the specified data encoding and the response is displayed at “Read Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginRead” instead of “Read”.

clienttutorials_read_with_data_encoding3.png
clienttutorials_read_with_data_encoding4.png

Sample Code

The following code reads the Value of the specified Variable from the server.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// build a list of values to read.
List<ReadValueId> nodesToRead = PrepareRequest(session);
if (nodesToRead == null)
{
return;
}
// 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.
ProcessResults(results);
}
private List<ReadValueId> PrepareRequest(Session session)
{
// nothing to do if no session.
if (session == null)
{
return null;
}
// need the browse name of the encoding to pass with the request.
QualifiedName dataEncoding = null;
if (DataEncodingCB.SelectedIndex >= 0)
{
// Get the BrowseName of the selected encoding node.
// Standard values are QualifiedName("Default Binary") and QualifiedName("Default XML").
dataEncoding = session.Cache.GetAttribute<QualifiedName>(
((DropDownItem)DataEncodingCB.SelectedItem).DataEncoding,
Attributes.BrowseName,
null);
}
// build a list of values to read.
List<ReadValueId> nodesToRead = new List<ReadValueId>();
// assume we are reading a variable so the default attribute is the Value attribute.
nodesToRead.Add(new ReadValueId()
{
NodeId = NodeId.Parse(NodeIdTB.Text),
AttributeId = Attributes.Value,
DataEncoding = dataEncoding
});
return nodesToRead;
}