首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >node opcua -需要有关客户端如何获取给定UAObject节点ID的所有变量的示例

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

Stack Overflow用户
提问于 2019-01-16 22:14:31
回答 1查看 2.8K关注 0票数 1

当我想要实现一个Node.js客户端程序并查找给定UAObject节点ID下的所有变量时,该如何实现?是否有一个用Node.js编写的OPC库来导航子节点或获取父UAObject nodeId下的所有变量?

EN

回答 1

Stack Overflow用户

发布于 2019-08-22 14:27:20

此示例将演示您提出的问题:

代码语言:javascript
复制
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());
    });
})();

它将产生以下输出

代码语言:javascript
复制
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
   }
 ]
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54218978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档