当我想实现一个 Node.js 客户端程序并找到给定 UAObject 节点 ID 下的所有变量时,该怎么做?是否有用 Node.js 编写的 OPC UA 库来导航到子节点或获取父 UAObject nodeId 下的所有变量?
问问题
3238 次
1 回答
3
此示例将演示您的要求:
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
}
]
};
于 2019-08-22T06:27:20.400 回答