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

Prerequisites

A session with the server must be established.

Description

The following dialog shows a dialog window which demonstrates an implementation of the Translate Browse Paths operation. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

clienttutorials_translate_browse_paths2.png

Enter a Node ID into the input field “Node ID” or press the button “...” to open a browse window and select a node.

It is possible to list two browse paths starting at the node specified above by entering their browse names into the fields “Path to Translate 1” and “Path to Translate 2”. After pressing the button “Translate” the corresponding NodeIDs are displayed at “Translate Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginTranslate” instead of “Translate”.

Sample Code

The following code finds the Nodes at the end of a browse path, starting at a specified node.

The starting NodeId is parsed from a string specified in the GUI. The TranslateBrowsePaths method is taking a list of BrowsePaths as argument. The GUI contains only a text field. The format of the string is shown the screen shot.

We use a helper function to create a BrowsePath from this string.

// parse the node id.
NodeId startingNodeId = NodeId.Parse(NodeIdTB.Text);
// get the browse paths.
List<BrowsePath> pathsToTranslate = new List<BrowsePath>();
pathsToTranslate.Add(GetBrowsePath(startingNodeId, AbsoluteName.ToQualifiedNames(PathToTranslate1TB.Text)));
pathsToTranslate.Add(GetBrowsePath(startingNodeId, AbsoluteName.ToQualifiedNames(PathToTranslate2TB.Text)));
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
// translate the references (setting a 10 second timeout).
List<BrowsePathResult> results = session.TranslateBrowsePath(
pathsToTranslate,
new RequestSettings() { OperationTimeout = 10000 });
private BrowsePath GetBrowsePath(NodeId startingNodeId, IList<QualifiedName> qnames)
{
BrowsePath browsePath = new BrowsePath();
browsePath.StartingNode = startingNodeId;
foreach (QualifiedName qname in qnames)
{
browsePath.RelativePath.Elements.Add(new RelativePathElement()
{
ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences,
IncludeSubtypes = true,
IsInverse = false,
TargetName = qname
});
}
return browsePath;
}