I want to recursively browse through all the sub-nodes from a given parent and build a list of nodes that are variables. For example if I have the following
Code: Select all
Foo->Bar1->Tag1
->Tag2
->Bar2->Tag3
->Tag4
I found the following code snippets here on this Forum that gets me 95% of the way there.
Code: Select all
/// <summary>
/// Browse recursively and return all nodes under a parent node.
///
/// https://forum.unified-automation.com/topic1626.html
/// </summary>
/// <param name="nodeId">The parent node</param>
/// <param name="browsedNodes">A list of nodes under the parent</param>
void BrowseRec(NodeId nodeId, SortedList<NodeId, NodeId> browsedNodes)
{
try
{
var Browse = new Action<List<ReferenceDescription>>(a =>
{
foreach (ReferenceDescription reference in a)
{
NodeId targetNodeId = reference.NodeId.ToNodeId(mSession.NamespaceUris);
if (!browsedNodes.ContainsKey(targetNodeId))
{
// Only want to add to list if this is a variable and not an attribute!
if ()
{
browsedNodes.Add(targetNodeId, targetNodeId);
}
BrowseRec(targetNodeId, browsedNodes);
}
}
});
// Only interested in variables so set the NodeClassMask appropriately
// http://documentation.unified-automation.com/uasdkcpp/1.4.0/html/classUaClientSdk_1_1BrowseContext.html#ace381d5e585d4c488dd02c897da712c2
byte[] continuationPoint;
BrowseContext browseContext = new BrowseContext()
{
BrowseDirection = BrowseDirection.Forward,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HierarchicalReferences,
IncludeSubtypes = true,
NodeClassMask = 2,
ResultMask = (uint)BrowseResultMask.All,
MaxReferencesToReturn = 100
};
List<ReferenceDescription> results = mSession.Browse(nodeId, browseContext, out continuationPoint);
Browse(results);
while (continuationPoint != null)
{
results = mSession.BrowseNext(ref continuationPoint);
Browse(results);
}
}
catch
{
// For some reason this code sample always throws an exception
}
}
I looked for a way to differentiate actual variables from the attributes of those variables but I don't see any property like IsAttribute() and everything appears identical between a variable and it's attributes. So how can I fill in that if() statement to exclude attribute nodes?
TIA,
Tim