저는 Siemens 1200 PLC를 가지고 있습니다. node-opcua client와 Kepserver를 사용하여 변수를 읽고 값을 변경할 수 있습니다. 이제 KepServer의 node-opcua에서 PLC에 새 변수를 만들고 싶습니다. node-opcua를 사용하여 Kepserver에서 변수 생성
예를 들어 변수를 만드는 방법을 보았으나 KepServer와 동일한 포트에 연결하려고하기 때문에 오류가 발생하기 때문에 node-opcua 서버를 사용하려고했습니다.
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)
}
});
어떻게 새로운 변수를 만들 다룰 수 있을까? node-opcua에서 그룹 태그를 만드시겠습니까?
Kepserver에서 opcua 서버를 사용하고 해당 서버에 직접 연결하는 변수를 만들 수 있습니까? opc.tcp : 내 Kepserver이있는 // 로컬 호스트 : 49,320 내가 nodeopcua 클라이언트를 사용하여이 Kepserver에 연결하려면 :
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
내 문제를 해결하기 위해 무엇을 할 수 있을까?
무엇이 필요합니까? 가변 환경? –
동적으로 PLC 메모리에 태그를 생성하고 싶습니다. – mram888