.NET Based OPC UA Client/Server SDK  3.3.3.537
Browse/Translate – Browse

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example implementation of the Browse service, which can be used to read references from a node. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

clienttutorials_browse.png

First, you have to specify some parameters to filter your results. Klick on the button “...” right of the field “Node ID” to open an adress space browser, select the desired node and confirm with “OK”. Now, the NodeId is shown at the corresponding field.

clienttutorials_read_attribute2.png

Pick a browse direction from the drop down menu.

clienttutorials_browse2.png

On pressing the button “...” right of the field “Reference Type”, a browse window opens. This allows you to further restrain the results. Check the box in front of “Include Subtypes” to return subtypes of the reference type as well.

clienttutorials_browse3.png

By specifiying “Max References” you can limit the maximum number of references in a single response. If specified, a continuation point is set and the method BrowseNext is called repeatedly until all references are returned. Select “0” to get all references in a single response.

After pressing the button “Browse” the reference types matching your request are shown in the table at “Browse Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginBrowse” instead of “Browse”.

clienttutorials_browse4.png

Sample Code

First we need to fill the BrowseContext to specify

  • the direction, i.e. if forward, inverse, or both kinds of references are returned;
  • the reference type, i.e. references having this ReferenceType will be returned;
  • IncludeSubtypes to select whether references are returned that have a subtype of the reference type selected above
  • the maximum number of references returned in one service call.

BrowseContext

// set up the browse filters.
BrowseContext context = new BrowseContext();
context.BrowseDirection = (BrowseDirection)BrowseDirectionCB.SelectedItem;
context.ReferenceTypeId = (NodeId)ReferenceTypeTB.Tag;
context.IncludeSubtypes = IncludeSubtypesCK.Checked;
context.MaxReferencesToReturn = (uint)MaxReferencesUD.Value;

The starting NodeId that is used for the Browse operation is provided by the GUI in standard XML format. So NodeId.Parse can be used to get the NodeId. A continuation point has to be used as out parameter.

// parse the node id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
byte[] continuationPoint = null;
// browse the references (setting a 10 second timeout).
List<ReferenceDescription> references = session.Browse(
nodeId,
context,
new RequestSettings() { OperationTimeout = 10000 },
out continuationPoint);

There is a maximum number of ReferenceDescriptions that can be returned in a single Browse operation. If there are more reference descriptions available on the server that can be retrieved, the continuation point is not null, otherwise the continuation point is null.

This continuation point can used to get the next chunk of reference descriptions from the server. If the client is not interested in the next set of references, the continuation point has to be released.

m_continueAutomatically = context.MaxReferencesToReturn <= 0;
while (!ByteString.IsNull(continuationPoint))
{
if (!m_continueAutomatically)
{
session.ReleaseBrowseContinuationPoint(continuationPoint);
break;
}
references = session.BrowseNext(new RequestSettings() { OperationTimeout = 10000 }, ref continuationPoint);