Hello,
I created a flow that read PLC data with the s7 library.
I would like to read the chamber configuration (ip, port, timeout and reading cycle) from a file and then inject those values in the s7 In node, rather than put them with hard code. I have read on the forum that is kind of possible using control s7 node, but I didn't really understand how to do it.
Here is a flow example (without reading file but just with an injection node) :
The PLC configuration would be set in a json file like this :
msg.payload = {
"ACS": {
"ip": "XX.XX.XX.XX",
"port": 102,
"reading_cycle": 10000,
"timeout": 500
}
}
return msg;
And I would like to inject the values like this :
How could I handle this problem ?
Thank you for your help.
Long story short - not possible with current s7 nodes.
Only option is to use npm package nodes7.
Check this first:
opened 08:03PM - 06 Oct 22 UTC
Hey! I'm working with your node on node-red for reading from a plc S7-1200, rack… 0 and slot 1 with external functions. But every time I send a readAllItems I get the response I want but the connection resets every time and never closes, even with dropConnection and connectionCleanup... I've been trying to solve it for a few days now, if anyone has any ideas...
```javascript
var devices = msg.payload; // devices example: {"delta":0,"name":"10.255.3.214","rack":0,"slot":1,"data":"Q0.0","ip":"10.255.3.214","port":102}
msg = [];
let nodes7 = global.get('nodes7');
var conn = new nodes7({ globalTimeout: 2000 });
var doneReading = false;
devices.forEach((/** @type {{ modbus_id: any; modbus_ip: any; modbus_port: any; address: any; quantity: any; }} */ dev) => {
var variables = {
DATA: dev.data
};
conn.initiateConnection({ port: dev.port, host: dev.ip, rack: dev.rack, slot: dev.slot, debug: false }, connected);
function connected(err) {
if (typeof (err) !== "undefined") {
// PLC FORA DO ALCANCE
//console.log(err);
node.error({
"ip": dev.ip,
"port": dev.port,
"message": "ERRO! Falha na leitura do host " + dev.ip + "!",
"error": err.code
});
flow.set("aguarda", false);
conn.dropConnection();
conn.connectionCleanup();
}
conn.setTranslationCB(function (tag) { return variables[tag]; });
conn.addItems('DATA');
conn.readAllItems(valuesReady);
}
function valuesReady(anythingBad, values) {
if (anythingBad) { console.log("ERRO! Falha na leitura do host."); flow.set("aguarda", false); conn.dropConnection(); conn.connectionCleanup(); }
//console.log(values);
if (values.DATA != "BAD 255") {
node.send({
"topic": "TCP Response",
"host": dev.ip,
"port": dev.port,
"rack": dev.rack,
"slot": dev.slot,
"data": dev.data,
"payload": values.DATA
});
}
doneReading = true;
conn.dropConnection();
conn.connectionCleanup();
}
});
return msg;
```
My own examples:
Hello,
I needed dynamic addressing of Siemens PLC, so standard NR nodes are not a case. I've imported GitHub - plcpeople/nodeS7: Node.JS library for communication to Siemens S7 PLCs as external module.
Here is the simple flow which closes connection after data is read. It is necessary because S7 connections accumulate until ECONNRESET is thrown and NR needs to be restarted.
[image]
My end goal was to read identical structures of data with offset for each module.
Simple flow is here, PLC IP…
There is an S7 package that supports runtime variable readings but I forget which one. Try some of the other contrib packages.