1

When I want to implement a Node.js client program and find all the variables under a given UAObject Node ID, how to do that? Is there an OPC UA library written in Node.js to navigate to child nodes or get all variables under a parent UAObject nodeId?

kahveci
  • 1,429
  • 9
  • 23

1 Answers1

3

This sample will demonstrate what you asked:

const { OPCUAClient, NodeClass } = require("node-opcua");

const nodeId = "ns=0;i=2253"; // RootFolder.Objects.Server
const endpointUri = "opc.tcp://localhost:48010";

(async () => {

    const client = OPCUAClient.create({ endpoint_must_exist: false});
    client.on("backoff", () => console.log("Backoff: trying to connect to ", endpointUri));

    await client.withSessionAsync(endpointUri, async (session) => {
        let browseResult = await session.browse({
            nodeId,
            nodeClassMask: NodeClass.Variable, // we only want sub node that are Variables
            resultMask: 63 // extract all information possible 
        });
        console.log("BrowseResult = ", browseResult.toString());
    });
})();

It will produce this output

BrowseResult =  { /*BrowseResult*/
 statusCode                    /* StatusCode          */: Good (0x00000)
 continuationPoint             /* ByteString          */: null
 references                    /* ReferenceDescript[] */: [
   { /*0*/
     referenceTypeId           /* NodeId              */: ns=0;i=46
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=2254
     browseName                /* QualifiedName       */: ServerArray
     displayName               /* LocalizedText       */: locale=en text=ServerArray
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=68
   },
   { /*1*/
     referenceTypeId           /* NodeId              */: ns=0;i=46
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=2255
     browseName                /* QualifiedName       */: NamespaceArray
     displayName               /* LocalizedText       */: locale=en text=NamespaceArray
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=68
   },
   { /*2*/
     referenceTypeId           /* NodeId              */: ns=0;i=47
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=2256
     browseName                /* QualifiedName       */: ServerStatus
     displayName               /* LocalizedText       */: locale= text=ServerStatus
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=2138
   },
   { /*3*/
     referenceTypeId           /* NodeId              */: ns=0;i=46
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=2267
     browseName                /* QualifiedName       */: ServiceLevel
     displayName               /* LocalizedText       */: locale=en text=ServiceLevel
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=68
   },
   { /*4*/
     referenceTypeId           /* NodeId              */: ns=0;i=46
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=2994
     browseName                /* QualifiedName       */: Auditing
     displayName               /* LocalizedText       */: locale=en text=Auditing
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=68
   },
   { /*5*/
     referenceTypeId           /* NodeId              */: ns=0;i=46
     isForward                 /* UABoolean           */: true
     nodeId                    /* ExpandedNodeId      */: ns=0;i=12885
     browseName                /* QualifiedName       */: EstimatedReturnTime
     displayName               /* LocalizedText       */: locale=en text=EstimatedReturnTime
     nodeClass                 /* NodeClass           */: 2 ( 2)
     typeDefinition            /* ExpandedNodeId      */: ns=0;i=68
   }
 ]
};

Etienne
  • 16,249
  • 3
  • 26
  • 31