我使用node-opcua module
并且我想opc ua nodes
通过订阅监视许多我看到的结果如下:用户在html UI中选择要监视的节点,然后单击Monitor按钮将这些nodeIds
作为参数发送,然后为每个nodeid
将设置订阅和.on("已更改" )并行处理所有这些项目.现在代码看起来像:
var monitoredItem = the_subscription.monitor({
nodeId: opcua.resolveNodeId("ns=6;s=S71500ET200MP station_1.Master.111"),
attributeId: 13
},
{
samplingInterval: 100,
discardOldest: true,
queueSize: 10
},
opcua.read_service.TimestampsToReturn.Both
);
console.log("-------------------------------------");
var nodes = [];
monitoredItem.on("changed",function(dataValue){
//console.log(" value = ",dataValue.value.value);
//console.log(" sourceTimestamp = ",dataValue.sourceTimestamp.toISOString());
//console.log(JSON.stringify(dataValue));
var Node = {nodeId: "ns=6;s=S71500ET200MP station_1.Master.111", nodeName: "111" , nodeValue: dataValue.value.value , nodeTimestamp: dataValue.sourceTimestamp.toISOString()};
var arrayNode = Object.keys(Node).map(function(k) { return Node[k] });
//console.log(JSON.stringify(Node));
nodes.push(arrayNode);
// console.log(nodes);
});
},
Run Code Online (Sandbox Code Playgroud)
现在,如果我想设置新项目来监控它,只需添加许多变量MonitorItem1,..2,.3等.
怎么做更多的agile/dynamic …
我正在学习节点opc-ua并且已经遵循了GitHub页面中为sample_server.js和simple_client.js提供的示例.
在sample_server中,我在构造服务器的地址空间时添加一个变量,例如:
//this code is in the server
addressSpace.addVariable({
componentOf: device,
nodeId: "ns=1;s=variable_1",
browseName: "MyVariable1",
dataType: "Double",
value: {
get: function () {
return new opcua.Variant({ dataType: opcua.DataType.Double, value: variable1 });
}
}
});
Run Code Online (Sandbox Code Playgroud)
以下是整个服务器代码供参考:
var opcua = require("node-opcua");
var server = new opcua.OPCUAServer({
port: 4334, // the port of the listening socket of the server
resourcePath: "UA/MyLittleServer", // this path will be added to the endpoint resource name
buildInfo: {
productName: "MySampleServer1",
buildNumber: "7658",
buildDate: new Date(2014, 5, 2) …
Run Code Online (Sandbox Code Playgroud)