2016-09-05 9 views
16

私はSiemens 1200 PLCを持っています。 node-opcua clientとKepserverを使用して、変数を読み込んで値を変更することができました。 今、私はKepServerのnode-opcuaからPLCに新しい変数を作成したいと思います。 enter image description herenode-opcuaでKepserverに変数を作成

の例では、私は、変数を作成する方法を見てきたので、私はノードopcuaサーバーを使用しようとしましたが、私はKepServerが行うのと同じポートに接続しようとしているので、私はエラーを取得します。

var server = new opcua.OPCUAServer({ 
    port: 49320, // the port of the listening socket of the server 
    resourcePath: "", // this path will be added to the endpoint resource name 
    buildInfo : { 
     productName: "MySampleServer1", 
     buildNumber: "7658", 
     buildDate: new Date(2014,5,2) 
    } 
}); 

enter image description here

はどうやって新しい変数を作成するために対処するだろうか? node-opcuaからグループタグを作成するには?

それはKepserverでopcuaサーバーを持っているし、直接そのサーバーに接続する変数を作成することは可能ですか? opc.tcp: 私Kepserverはである// localhostを:49320 このKepserverに接続するには、私はnodeopcuaクライアントを使用します。

var opcua = require("node-opcua"); var client = new opcua.OPCUAClient(); var endpointUrl = "opc.tcp://127.0.0.1:49320"; var the_session = null; async.series([

// step 1 : connect to 
    function(callback) { 

     client.connect(endpointUrl,function (err) { 

      if(err) { 
       console.log(" cannot connect to endpoint :" , endpointUrl); 
      } else { 
       console.log("connected !"); 
      } 
      callback(err); 
     }); 
    }, 
    // step 2 : createSession 
    function(callback) { 
     client.createSession(function(err,session) { 
      if(!err) { 
       the_session = session; 
      } 
      callback(err); 
     }); 

    }, 
    // step 3 : browse 
    function(callback) { 

     the_session.browse("RootFolder", function(err,browse_result,diagnostics){ 
      if(!err) { 
       browse_result[0].references.forEach(function(reference) { 
        console.log(reference.browseName); 
       }); 
      } 
      callback(err); 
     }); 
    }, 
    // step 4 : read a variable 
    function(callback) { 
     the_session.readVariableValue("ns=2;s=S7.1200.nombre", function(err,dataValue) { 
      if (!err) { 
       console.log(" temperature = " , dataValue.toString()); 
      } 
      callback(err); 
     }) 
    }, 

    // step 5: install a subscription and monitored item 
    // 
    // ----------------------------------------- 
    // create subscription 
    function(callback) { 

     the_subscription=new opcua.ClientSubscription(the_session,{ 
      requestedPublishingInterval: 1000, 
      requestedLifetimeCount: 10, 
      requestedMaxKeepAliveCount: 200, 
      maxNotificationsPerPublish: 10, 
      publishingEnabled: true, 
      priority: 10 
     }); 
     the_subscription.on("started",function(){ 
      console.log("subscription started for 2 seconds - subscriptionId=",the_subscription.subscriptionId); 
     }).on("keepalive",function(){ 
      console.log("keepalive"); 
     }).on("terminated",function(){ 
      callback(); 
     }); 
     setTimeout(function(){ 
      the_subscription.terminate(); 
     },100000); 


     // install monitored item 
     // 
     var monitoredItem = the_subscription.monitor({ 
      nodeId: opcua.resolveNodeId("ns=2;s=S7.1200.nombre"), 
      attributeId: 13 
      //, dataEncoding: { namespaceIndex: 0, name:null } 
     }, 
     { 
      samplingInterval: 100, 
      discardOldest: true, 
      queueSize: 10 
     }); 
     console.log("-------------------------------------"); 

     // subscription.on("item_added",function(monitoredItem){ 
     //xx monitoredItem.on("initialized",function(){ }); 
     //xx monitoredItem.on("terminated",function(value){ }); 


     monitoredItem.on("changed",function(value){ 
      console.log(" New Value = ",value.toString()); 
     }); 

    }, 

    // ------------------------------------------------ 
    // closing session 
    // 
    function(callback) { 
     console.log(" closing session"); 
     the_session.close(function(err){ 

      console.log(" session closed"); 
      callback(); 
     }); 
    }, 


], 
    function(err) { 
     if (err) { 
      console.log(" failure ",err); 
     } else { 
      console.log("done!") 
     } 
     client.disconnect(function(){}); 
}) ; 

私は私のコードから新しい変数を作成したいですKepserver。私はnodeopcuaサーバコードで変数を作成する方法があることを見てきました: https://github.com/node-opcua/node-opcua/blob/master/documentation/creating_a_server.md

私はKepServerのようなものを使用したいと思います:server.engine.addressSpace.addVariable

私は私の問題を解決するために何ができますか?

+0

何が欲しいですか?可変環境ですか? –

+0

PLCメモリにタグを動的に作成したい – mram888

答えて

0

あなたはnode-opcuaクライアントからKEPServerExで変数を作成することはできません。

でも、作成する必要はありません。 KEPServerExの機能を使用してPLCに変数をトンネリングすることができます。つまり、サーバ変数リストに定義されていない変数を読み込もうとすると、KEPServerExはそれらをPLC内で見つけようとします。したがって、KEPServerExで変数リストを作成する必要はありません。正しい変数の住所を持つクライアントがそれを読んでください:

session.readVariableValue("ns=2;s=Channel1.Device1.MB0", function(err,dataValue) { 
    if (!err) { 
     console.log("value=", dataValue.toString()); 
    } 
} 
関連する問題