Mam sterownik PLC Siemens 1200. Za pomocą klienta node-opcua i Kepserver mogę odczytać zmienne i zmienić wartości. Teraz chciałbym utworzyć nową zmienną w PLC z node-opcua w KepServer. Utwórz zmienną w Kepserver z węzłem-opcua
Próbowałem użyć serwera node-opcua, ponieważ w przykładach widziałem, jak tworzyć zmienne, ale pojawia się błąd, ponieważ próbuję połączyć się z tym samym portem, który wykonuje 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)
}
});
Jak mogłem sobie, aby utworzyć nową zmienną? i stworzyć tag grupy z node-opcua?
Czy można mieć serwer opcua w Kepserver i tworzyć zmienne łączące się bezpośrednio z tym serwerem? My KEPServer znajduje się w: opc.tcp: // localhost: 49320 Aby połączyć się z tym KEPServer Używam klienta 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(){});
}) ;
Chciałbym utworzyć nowe zmienne z kodu w moim Kepserver. Widziałem, że z kodu serwera nodeopcua istnieje sposób tworzenia zmiennych: https://github.com/node-opcua/node-opcua/blob/master/documentation/creating_a_server.md
chciałbym użyć czegoś takiego jak w KEPServer: server.engine.addressSpace.addVariable
Co mogę zrobić, aby rozwiązać mój problem?
Czego chcesz? Zmienne środowisko? –
Chcę utworzyć tag w pamięci PLC w sposób dynamiczny – mram888