Hello, the PLC is a Siemens ET200SP, so I believe it's a S7-1500. The port for reading is the 2000, and the port for writing is the 2001 (datasheet).
I've tried to establish a TCP connection with the basic nodes in Node Red. I've succeeded to connect the ports 2000 and 2001 (see picture below). The problem is, it doesn't succeed to communicate with the PLC : "connect failed IP ADDRESS:PORT".
This is what I've done in my architecture :
- Connecting and listening to the ports 2000 (reading) and 2001 (writing), with a TCP response on the appropriate port.
- Creation of the frame to send to the PLC for reading measures --> read query
- TCP request for asking the PLC the data I want
- Add a debug node for receive the answer of the PLC
I also added the expected response of the PLC, which I verified on an specified application.
I created a flow in order to show you what I did. You'll find the .json just after. I as well put a screenshot of the architecture and what I have in the debug console (I injected the expected response in the debug console, it is not the real response of the PLC).
Thanks !
Flow :
[
{
"id": "68125ec0949e5455",
"type": "tab",
"label": "Flux 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "401c13f692b32cda",
"type": "inject",
"z": "68125ec0949e5455",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 90,
"y": 200,
"wires": [
[
"a1e98ebcdab0d865"
]
]
},
{
"id": "88d57d9f7acd2e12",
"type": "tcp request",
"z": "68125ec0949e5455",
"name": "",
"server": "192.168.0.1",
"port": "2000",
"out": "time",
"ret": "buffer",
"splitc": "0",
"newline": "",
"trim": false,
"tls": "",
"x": 500,
"y": 200,
"wires": [
[
"0bc099209cde7172"
]
]
},
{
"id": "0bc099209cde7172",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug readQuery + response PLC port 2000",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 200,
"wires": []
},
{
"id": "a1e98ebcdab0d865",
"type": "function",
"z": "68125ec0949e5455",
"name": "readQuery",
"func": "// Requête de lecture : lire les 2 premières données à partir de l'adresse 0\nlet buf = [];\n buf[0] = 'S'; //System ID\n buf[1] = '5'; \n buf[2] = 16; //Length of header\n buf[3] = 1; //ID OP code\n buf[4] = 3; //Length of OP code\n buf[5] = 5; //OP code, 5=READ FUNCTION\n buf[6] = 3; //ORG field\n buf[7] = 8; //Length ORG field\n buf[8] = 1; //ORG ID\n buf[9] = 62; //DB NR, in our case it is DB62\n buf[10] = 0; //Start address, high byte\n buf[11] = 0; //Start address, low byte\n buf[12] = 0; //Length, high byte - Data packet length in WORDS\n buf[13] = 4; // Les 2 premières mesures (Dry and Wet bulb)\n buf[14] = 255; //Empty field\n buf[15] = 2; //Length empty field\n\nlet a = []; \nfor (let i = 0; i < 16; i++) {\n a.push(buf[i]);\n}\n\nreturn [{payload: a}];\n\n\n\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 200,
"wires": [
[
"88d57d9f7acd2e12",
"d9d3d4b036bf9318"
]
]
},
{
"id": "2cc22a40c2cddf4c",
"type": "inject",
"z": "68125ec0949e5455",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 90,
"y": 260,
"wires": [
[
"f6a079f81a59f6e2"
]
]
},
{
"id": "1fa4de0610a5822b",
"type": "tcp request",
"z": "68125ec0949e5455",
"name": "",
"server": "192.168.0.1",
"port": "2001",
"out": "time",
"ret": "buffer",
"splitc": "0",
"newline": "",
"trim": false,
"tls": "",
"x": 500,
"y": 260,
"wires": [
[
"94aa2b35458de2bb"
]
]
},
{
"id": "94aa2b35458de2bb",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug readQuery + response PLC port 2001",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 260,
"wires": []
},
{
"id": "f6a079f81a59f6e2",
"type": "function",
"z": "68125ec0949e5455",
"name": "readQuery",
"func": "// Requête de lecture : lire les 2 premières données à partir de l'adresse 0\nlet buf = [];\n buf[0] = 'S'; //System ID\n buf[1] = '5'; \n buf[2] = 16; //Length of header\n buf[3] = 1; //ID OP code\n buf[4] = 3; //Length of OP code\n buf[5] = 5; //OP code, 5=READ FUNCTION\n buf[6] = 3; //ORG field\n buf[7] = 8; //Length ORG field\n buf[8] = 1; //ORG ID\n buf[9] = 62; //DB NR, in our case it is DB62\n buf[10] = 0; //Start address, high byte\n buf[11] = 0; //Start address, low byte\n buf[12] = 0; //Length, high byte - Data packet length in WORDS\n buf[13] = 4; // Les 2 premières mesures (Dry and Wet bulb)\n buf[14] = 255; //Empty field\n buf[15] = 2; //Length empty field\n\nlet a = []; \nfor (let i = 0; i < 16; i++) {\n a.push(buf[i]);\n}\n\nreturn [{payload: a}];\n\n\n\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 260,
"wires": [
[
"1fa4de0610a5822b"
]
]
},
{
"id": "b8b135847891b39f",
"type": "function",
"z": "68125ec0949e5455",
"name": "responseReadQuery",
"func": "// Réponse du PLC : écriture des 2 premières données à partir de l'adresse 0\nlet buf = [];\n buf[0] = 'S'; //System ID\n buf[1] = '5'; \n buf[2] = 16; //Length of header\n buf[3] = 1; //ID OP code\n buf[4] = 3; //Length of OP code\n buf[5] = 6; //OP code, 5=READ ACKNOWLEDGMENT FUNCTION\n buf[6] = 15; //ACK field\n buf[7] = 3; //Length ACK field\n buf[8] = 0; //Error\n buf[9] = 255; //Empty field\n buf[10] = 7; //Length empty field\n buf[11] = 0; //Start address, low byte\n buf[12] = 0; //Length, high byte - Data packet length in WORDS\n buf[13] = 0; // Les 2 premières mesures (Dry and Wet bulb)\n buf[14] = 0; //Empty field\n buf[15] = 0;\n\n // DATA : float => codé sur 4 bytes\n // 1ère valeur : Dry bulb \n buf[16] = 65; \n buf[17] = 198; \n buf[18] = 223; \n buf[19] = 194; \n\n // 2ème valeur : Wet bulb\n buf[20] = 67;\n buf[21] = 163; \n buf[22] = 213; \n buf[23] = 174;\n\nlet a = []; \nfor (let i = 0; i < 24; i++) {\n a.push(buf[i]);\n}\n\nreturn [{payload: a}];\n\n\n\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 900,
"wires": [
[
"476c85c49ca831bd"
]
]
},
{
"id": "13db1951bc7376e6",
"type": "inject",
"z": "68125ec0949e5455",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 110,
"y": 900,
"wires": [
[
"b8b135847891b39f"
]
]
},
{
"id": "476c85c49ca831bd",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug expected response by the PLC",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 900,
"wires": []
},
{
"id": "d9d3d4b036bf9318",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Frame to send",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 160,
"wires": []
},
{
"id": "0f8932c8f0fa62d9",
"type": "comment",
"z": "68125ec0949e5455",
"name": "Frame + TCP request PLC",
"info": "",
"x": 130,
"y": 120,
"wires": []
},
{
"id": "1f915e63c572b0d2",
"type": "tcp in",
"z": "68125ec0949e5455",
"name": "Connection port 2000",
"server": "client",
"host": "192.168.0.1",
"port": "2000",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 140,
"y": 580,
"wires": [
[
"6cc805f03596b6d7",
"8fd58e5781a88c51"
]
]
},
{
"id": "6cc805f03596b6d7",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug connexion port 2000",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 460,
"y": 640,
"wires": []
},
{
"id": "8fd58e5781a88c51",
"type": "tcp out",
"z": "68125ec0949e5455",
"name": "Response TCP port 2000",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"tls": "",
"x": 450,
"y": 560,
"wires": []
},
{
"id": "d6fe54f5f0d96f2e",
"type": "tcp in",
"z": "68125ec0949e5455",
"name": "Listening port 2000",
"server": "server",
"host": "192.168.0.1",
"port": "2000",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 130,
"y": 520,
"wires": [
[
"8fd58e5781a88c51",
"90dfcb79415de366"
]
]
},
{
"id": "90dfcb79415de366",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug listening port 2000",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 450,
"y": 480,
"wires": []
},
{
"id": "1c3c07de39031802",
"type": "tcp in",
"z": "68125ec0949e5455",
"name": "Connection port 2001",
"server": "client",
"host": "192.168.0.1",
"port": "2001",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 800,
"y": 560,
"wires": [
[
"c08de818ed379a84",
"aab782c653c16c7e"
]
]
},
{
"id": "c08de818ed379a84",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug connexion port 2001",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1120,
"y": 620,
"wires": []
},
{
"id": "aab782c653c16c7e",
"type": "tcp out",
"z": "68125ec0949e5455",
"name": "Response TCP port 2001",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"tls": "",
"x": 1110,
"y": 540,
"wires": []
},
{
"id": "e1982bf605d04cd6",
"type": "tcp in",
"z": "68125ec0949e5455",
"name": "Listening port 2001",
"server": "server",
"host": "192.168.0.1",
"port": "2001",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 790,
"y": 500,
"wires": [
[
"aab782c653c16c7e",
"aed5d2e1a3c8efa6"
]
]
},
{
"id": "aed5d2e1a3c8efa6",
"type": "debug",
"z": "68125ec0949e5455",
"name": "Debug listening port 2001",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1110,
"y": 460,
"wires": []
},
{
"id": "7b2d030f04621fcd",
"type": "comment",
"z": "68125ec0949e5455",
"name": "Connection + listening mode PLC",
"info": "",
"x": 150,
"y": 400,
"wires": []
},
{
"id": "d1645c2a4c2c20d7",
"type": "comment",
"z": "68125ec0949e5455",
"name": "Port 2000 : reading",
"info": "",
"x": 270,
"y": 700,
"wires": []
},
{
"id": "a37d3190c0832c5f",
"type": "comment",
"z": "68125ec0949e5455",
"name": "Port 2001 : writing",
"info": "",
"x": 950,
"y": 700,
"wires": []
},
{
"id": "d7656b2aa0e74685",
"type": "comment",
"z": "68125ec0949e5455",
"name": "Example : response expected by the PLC",
"info": "",
"x": 200,
"y": 840,
"wires": []
}