Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

[opcua] Browsing nodes

More
21 Feb 2022 13:48 #10643 by support
Replied by support on topic [opcua] Browsing nodes
Hello,

please see the code below. I hope it helps.

// This example shows how to obtain "data nodes" under the "Objects" node, recursively.
 
using System;
using System.Diagnostics;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.AddressSpace.Standard;
using OpcLabs.EasyOpc.UA.OperationModel;
 
namespace UADocExamples._EasyUAClient
{
    partial class BrowseDataNodes
    {
        public static void Recursive()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (not in .NET Standard)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"
 
            // Instantiate the client object
            var client = new EasyUAClient();
 
            try
            {
                BrowseFromNode(client, endpointDescriptor, UAObjectIds.ObjectsFolder, level:0);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
            }
        }
 
        private static void BrowseFromNode(
            EasyUAClient client,
            UAEndpointDescriptor endpointDescriptor,
            UANodeDescriptor parentNodeDescriptor,
            int level)
        {
            Debug.Assert(!(client is null));
            Debug.Assert(!(endpointDescriptor is null));
            Debug.Assert(!(parentNodeDescriptor is null));
 
            // Obtain all node elements under parentNodeDescriptor
            UANodeElementCollection nodeElementCollection = 
                client.BrowseDataNodes(endpointDescriptor, parentNodeDescriptor);
            // Remark: BrowseDataNodes(...) may throw UAException; we handle it in the calling method.
 
            foreach (UANodeElement nodeElement in nodeElementCollection)
            {
                Debug.Assert(!(nodeElement is null));
 
                Console.Write(new string(' ', level*2));    // indent
                Console.WriteLine(nodeElement);
 
                // Browse recursively into the node.
                // The UANodeElement has an implicit conversion to UANodeDescriptor.
                BrowseFromNode(client, endpointDescriptor, nodeElement, level + 1);
 
                // Note that the number of nodes you obtain through recursive browsing may be very large, or even infinite.
                // Production code should contain appropriate safeguards for these cases.
            }
        }
 
 
        // Example output:
        //
        //ServerStatus -> nsu=http://opcfoundation.org/UA/ ;i=2256 (Variable) 
        //  StartTime -> nsu=http://opcfoundation.org/UA/ ;i=2257 (Variable) 
        //  CurrentTime -> nsu=http://opcfoundation.org/UA/ ;i=2258 (Variable) 
        //  State -> nsu=http://opcfoundation.org/UA/ ;i=2259 (Variable) 
        //  BuildInfo -> nsu=http://opcfoundation.org/UA/ ;i=2260 (Variable) 
        //    ProductUri -> nsu=http://opcfoundation.org/UA/ ;i=2262 (Variable) 
        //    ManufacturerName -> nsu=http://opcfoundation.org/UA/ ;i=2263 (Variable) 
        //    ProductName -> nsu=http://opcfoundation.org/UA/ ;i=2261 (Variable) 
        //    SoftwareVersion -> nsu=http://opcfoundation.org/UA/ ;i=2264 (Variable) 
        //    BuildNumber -> nsu=http://opcfoundation.org/UA/ ;i=2265 (Variable) 
        //    BuildDate -> nsu=http://opcfoundation.org/UA/ ;i=2266 (Variable) 
        //  SecondsTillShutdown -> nsu=http://opcfoundation.org/UA/ ;i=2992 (Variable) 
        //  ShutdownReason -> nsu=http://opcfoundation.org/UA/ ;i=2993 (Variable) 
        //ServerCapabilities -> nsu=http://opcfoundation.org/UA/ ;i=2268 (Object) 
        //  OperationLimits -> nsu=http://opcfoundation.org/UA/ ;i=11704 (Object) 
        //    MaxNodesPerRead -> nsu=http://opcfoundation.org/UA/ ;i=11705 (Variable) 
        //    MaxNodesPerHistoryReadData -> nsu=http://opcfoundation.org/UA/ ;i=12165 (Variable) 
        //    MaxNodesPerHistoryReadEvents -> nsu=http://opcfoundation.org/UA/ ;i=12166 (Variable) 
        //    MaxNodesPerWrite -> nsu=http://opcfoundation.org/UA/ ;i=11707 (Variable) 
        //    MaxNodesPerHistoryUpdateData -> nsu=http://opcfoundation.org/UA/ ;i=12167 (Variable) 
        //...
    }
}

Best regards
The following user(s) said Thank You: yong

Please Log in or Create an account to join the conversation.

More
21 Feb 2022 07:30 #10641 by yong
Replied by yong on topic [opcua] Browsing nodes
Yes, I would appreciate it if you could provide actual example code.

Best regards

Please Log in or Create an account to join the conversation.

More
21 Feb 2022 06:39 #10640 by support
Replied by support on topic [opcua] Browsing nodes
Hello.

It is not clear what you are asking for. Do you want tor recursively browse into the nodes, and basically obtain the whole tree?

If so, it looks like that you already have an example code that gets you the first level. Each of the result "elements" contains a node Id of the node you obtained. You can use that to browse further from that node, passing it as starting element (an additional argument) to one of the BrowseXXXX methods (possible the BrowseDataNodes again).

With this, do you need an actual example code for that ?

Best regards

Please Log in or Create an account to join the conversation.

More
21 Feb 2022 06:26 #10639 by yong
[opcua] Browsing nodes was created by yong
Hello.

I am using opclabs quick opcua version 5.23 for C# .NET core.
I need to find a way to programmatically browse like a program uaexpert node.

I couldn’t find any documentation for that, do you have any example code for that?
How do you browse beneath (forward) one of the nodes? For instance the node with display name “Data”?


Best regards,
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.048 seconds