javascript - node.js opc ua many monitored items - Stack Overflow

I use node-opcua module andI would like to monitor many opc ua nodes with subscription I see result l

I use node-opcua module and I would like to monitor many opc ua nodes with subscription I see result like: user in html UI choose what nodes to monitor, then click Monitor button that sent these nodeIds as parameters and then for every nodeid will be set subscription and .on("changed") works for every of these items like in parallel. Now code looks like:

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

Right now if I want to set new item to monitor it just add many vars MonitorItem1 , ..2 , ..3 etc.

How to do it in more agile/dynamic way? if I have array(strings) of nodeIds and I want each of these to be monitored in subscription. Code is part of async.series([ code ])

I use node-opcua module and I would like to monitor many opc ua nodes with subscription I see result like: user in html UI choose what nodes to monitor, then click Monitor button that sent these nodeIds as parameters and then for every nodeid will be set subscription and .on("changed") works for every of these items like in parallel. Now code looks like:

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

Right now if I want to set new item to monitor it just add many vars MonitorItem1 , ..2 , ..3 etc.

How to do it in more agile/dynamic way? if I have array(strings) of nodeIds and I want each of these to be monitored in subscription. Code is part of async.series([ code ])

Share Improve this question edited Jan 5, 2016 at 23:46 Etienne 16.9k3 gold badges29 silver badges32 bronze badges asked Dec 19, 2015 at 17:17 leonas5555leonas5555 831 silver badge9 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

solved using async.each method

async.each(nodeIdArr, function(nodeid, callback) {

     var monitoredItem  = the_subscription.monitor({
           nodeId: opcua.resolveNodeId(nodeid),
           attributeId: 13
       },
       {
           samplingInterval: 100,
           discardOldest: true,
           queueSize: 10
       },
       opcua.read_service.TimestampsToReturn.Both
       );
       console.log("-------------------------------------");


       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: nodeid, 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);
      });

Now you can use the method the_subscription.monitorItems()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745405434a4626291.html

相关推荐

  • javascript - node.js opc ua many monitored items - Stack Overflow

    I use node-opcua module andI would like to monitor many opc ua nodes with subscription I see result l

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信