Browsing - Accessing Data Correctly

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
JonLor
Hero Member
Hero Member
Posts: 48
Joined: 30 Jan 2014, 11:05

Browsing - Accessing Data Correctly

Post by JonLor »

Hello,

When browsing nodes on the server from a client I do something like this:

Code: Select all

  byte[] continuationPoint;
  BrowseContext browseContext = new BrowseContext { BrowseDirection = BrowseDirection.Forward, ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences, IncludeSubtypes = true };
  List<ReferenceDescription> referenceDescriptions = _session.Browse(nodeId, browseContext, out continuationPoint);
For each ReferenceDescription I would like to extract the following information:

1. The data type of the reference target
2. If the reference target has any child objects

I have accomplished this, but I feel that it might not be the best solution.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Browsing - Accessing Data Correctly

Post by Support Team »

Hi,

You will need to call Browse for each reference returned to find out if children exist. For optimization purpose you can call Browse with a list of starting nodes.
You should check the TypeDefinition NodeId in the returned ReferenceDescription. If the TypeDefinition is PropertyType you do not need to include this node in a browse for children since properties cannot have children.

You will also need to call Read to get the DataType/ValueRank attribute for any Variables if you need the DataType. The NodeClass returned in ReferenceDescription indicates if the node is a variable. The attributes DataType/ValueRank are only available for Variables and it makes no sense to read the attributes for other NodeClasses.
You should optimize the Read call by making one call for all Variable Nodes returned instead of making one call per node.

Best Regards,
Unified Automation Support Team

JonLor
Hero Member
Hero Member
Posts: 48
Joined: 30 Jan 2014, 11:05

Re: Browsing - Accessing Data Correctly

Post by JonLor »

Thanks,

one more question. What is the recommended approach when, for instance, comparing the ReferenceDescription.TypeDefinition to VariableTypes.PropertyType? My first attempt was something like this:

Code: Select all

...
List<OpcNodeDescription> nodes = new List<OpcNodeDescription>();
foreach (ReferenceDescription referenceDescription in referenceDescriptions)
{
  var isProperty = referenceDescription.TypeDefinition.ToNodeId(_session.NamespaceUris).Equals(VariableTypes.PropertyType);
...
However, this does not work.

Best regards
Jonas

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Browsing - Accessing Data Correctly

Post by Support Team »

Hi,

The check should look like:

Code: Select all

if ( referenceDescription.TypeDefinition ==  VariableTypeIds.PropertyType )
There are two types of constants
VariableTypes.PropertyType
VariableTypeIds.PropertyType

The first is just the numeric identifier that can be used in switch statements.
The second is a full NodeId.

Best Regards,
Unified Automation Support Team

Post Reply