节点opcua-关于客户端如何获取给定UAObject节点ID的所有变量的需求示例

时间:2019-01-16 14:14:31

标签: node-opcua

当我实现一个nodejs客户端程序并想在给定的UAObject节点ID下查找所有变量时,该怎么做?是否有一个节点opcua库可导航到子节点或在父UAObject nodeId下获得所有变量?

1 个答案:

答案 0 :(得分:1)

此示例将演示您的要求:

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());
    });
})();

它将产生此输出

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
   }
 ]
};