How do I determine if a Node is an Attribute?

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

Moderator: uasdknet

Post Reply
TexasTim65
Jr. Member
Jr. Member
Posts: 1
Joined: 30 Oct 2017, 20:39

How do I determine if a Node is an Attribute?

Post by TexasTim65 »

Hi,

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
and I start browsing from Foo I want to return Tag1, Tag2, Tag3 and 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
            }
        }
When I run this routine and pass in the Foo node my browsedNodes list does indeed give me Tag1, Tag2, Tag3 and Tag4. However it also gives me every attribute for these tags so that I also get _Access, _ClientAccess, _Description etc in the browsedNodes list.

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

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

Re: How do I determine if a Node is an Attribute?

Post by Support Team »

Hello Tim,

_Access, _ClientAccess, _Description are not attributes in OPC UA.
Please use correct wording in this forum.

I assume _Access, _ClientAccess, _Description are properties of some nodes. Properties are Variables, so they are returned in Browse. If you want to reject the properties, you can evaluate the TypeDefinition that is returned in the ReferenceDescriptions.
Best regards
Unified Automation Support Team

Post Reply