To write in PLC using S7 Out I have to write all Variables in it and before this code, I have to make to array one for variables and another for values (payload)
Desired Output: I want to remove the variables from the S7 out and send it from the prepare Data function.
[
{
"id": "247e3fda1f9e7969",
"type": "inject",
"z": "4b831203ffade23e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 280,
"y": 260,
"wires": [
[
"31c124bf7d9a7e81"
]
]
},
{
"id": "74629abe4d903824",
"type": "function",
"z": "4b831203ffade23e",
"name": "Prepare Data",
"func": "msg.payload = [msg.payload[0].Program_ID,\nmsg.payload[0].JOB_ID,\nmsg.payload[0].Length];\nmsg.variable = [\n 'PROGRAM',\n 'JOB',\n 'LENGTH'\n];\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 810,
"y": 260,
"wires": [
[
"3fefac4934f9933f"
]
]
},
{
"id": "3b0dab24c63581d8",
"type": "MSSQL",
"z": "4b831203ffade23e",
"mssqlCN": "4c7d57acebd0dde5",
"name": "",
"outField": "payload",
"returnType": 0,
"throwErrors": 1,
"query": "SELECT TOP 1 Program_ID\r\n,JOB_ID\r\n,Length\r\n,LEFT(JOB_CODE, 40) AS JOB_CODE\r\n,LEFT((LEFT(HEAT_CODE, CHARINDEX('**', HEAT_CODE) - 1)), 30) AS HEAT_CODE\r\nFROM PRD_BUNDLE_5\r\nORDER BY ID DESC",
"modeOpt": "queryMode",
"modeOptType": "query",
"queryOpt": "payload",
"queryOptType": "msg",
"paramsOpt": "queryParams",
"paramsOptType": "msg",
"rows": "rows",
"rowsType": "msg",
"parseMustache": true,
"params": [],
"x": 580,
"y": 260,
"wires": [
[
"74629abe4d903824",
"54a129af06f067ae"
]
]
},
{
"id": "31c124bf7d9a7e81",
"type": "function",
"z": "4b831203ffade23e",
"name": "Query",
"func": "msg.payload = `SELECT TOP 1 Program_ID\n,JOB_ID\n,Length\n,LEFT(JOB_CODE, 40) AS JOB_CODE\n,LEFT((LEFT(HEAT_CODE, CHARINDEX('**', HEAT_CODE) - 1)), 30) AS HEAT_CODE\nFROM PRD_BUNDLE_5\nORDER BY ID DESC`\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 260,
"wires": [
[
"3b0dab24c63581d8"
]
]
},
{
"id": "3fefac4934f9933f",
"type": "s7 out",
"z": "4b831203ffade23e",
"endpoint": "1dc3de29454f834f",
"variable": "",
"name": "Write on Datablock DB1010 on PLC E63",
"x": 1080,
"y": 260,
"wires": []
},
{
"id": "acef96b68e69f3b2",
"type": "debug",
"z": "4b831203ffade23e",
"name": "PROGRAM",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.value[0]",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 910,
"y": 440,
"wires": []
},
{
"id": "2dc94d561f26692d",
"type": "inject",
"z": "4b831203ffade23e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 440,
"y": 500,
"wires": [
[
"0a38762e95466403",
"6317c8e82f50273e",
"7cc1ccbc7533d728"
]
]
},
{
"id": "0a38762e95466403",
"type": "s7comm read",
"z": "4b831203ffade23e",
"connection": "cb814bd938d11a92",
"payload": "{\"S7_Type\":\"DB\",\"S7_DBnum\":\"1010\",\"S7_Datatype\":\"DI\",\"S7_Offset\":\"102\",\"S7_BitOffset\":\"0\",\"S7_Quantity\":\"1\",\"S7_Name\":\"PROGRAM\"}",
"s7Name": "PROGRAM",
"topic": "",
"name": "READ PROGRAM",
"signalSetted": false,
"none": "true",
"repeat": "",
"once": false,
"x": 730,
"y": 440,
"wires": [
[
"acef96b68e69f3b2"
]
]
},
{
"id": "d0d9eb5006fd4653",
"type": "debug",
"z": "4b831203ffade23e",
"name": "JOB",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.value[0]",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 500,
"wires": []
},
{
"id": "6317c8e82f50273e",
"type": "s7comm read",
"z": "4b831203ffade23e",
"connection": "cb814bd938d11a92",
"payload": "{\"S7_Type\":\"DB\",\"S7_DBnum\":\"1010\",\"S7_Datatype\":\"DI\",\"S7_Offset\":\"106\",\"S7_BitOffset\":\"0\",\"S7_Quantity\":\"1\",\"S7_Name\":\"JOB\"}",
"s7Name": "JOB",
"topic": "",
"name": "READ JOB",
"signalSetted": false,
"none": "true",
"repeat": "",
"once": false,
"x": 710,
"y": 500,
"wires": [
[
"d0d9eb5006fd4653"
]
]
},
{
"id": "6875b4aeb3ef8052",
"type": "debug",
"z": "4b831203ffade23e",
"name": "LENGTH",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.value[0]",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 900,
"y": 580,
"wires": []
},
{
"id": "7cc1ccbc7533d728",
"type": "s7comm read",
"z": "4b831203ffade23e",
"connection": "cb814bd938d11a92",
"payload": "{\"S7_Type\":\"DB\",\"S7_DBnum\":\"1010\",\"S7_Datatype\":\"DI\",\"S7_Offset\":\"110\",\"S7_BitOffset\":\"0\",\"S7_Quantity\":\"1\",\"S7_Name\":\"LENGTH\"}",
"s7Name": "LENGTH",
"topic": "",
"name": "READ LENGTH",
"signalSetted": false,
"none": "true",
"repeat": "",
"once": false,
"x": 720,
"y": 580,
"wires": [
[
"6875b4aeb3ef8052"
]
]
},
{
"id": "54a129af06f067ae",
"type": "debug",
"z": "4b831203ffade23e",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 780,
"y": 200,
"wires": []
},
{
"id": "4c7d57acebd0dde5",
"type": "MSSQL-CN",
"z": "4b831203ffade23e",
"tdsVersion": "7_4",
"name": "Connection_RML",
"server": "172.31.51.100",
"port": "1433",
"encyption": false,
"trustServerCertificate": false,
"database": "SUEZSTEELRM_RML",
"useUTC": false,
"connectTimeout": "15000",
"requestTimeout": "15000",
"cancelTimeout": "5000",
"pool": "5",
"parseJSON": false,
"enableArithAbort": true
},
{
"id": "1dc3de29454f834f",
"type": "s7 endpoint",
"transport": "iso-on-tcp",
"address": "172.31.51.13",
"port": "102",
"rack": "0",
"slot": "4",
"localtsaphi": "01",
"localtsaplo": "00",
"remotetsaphi": "01",
"remotetsaplo": "00",
"connmode": "rack-slot",
"adapter": "",
"busaddr": "2",
"cycletime": "1000",
"timeout": "2000",
"name": "Write on DatablocK DB1010 on PLC E63",
"vartable": [
{
"addr": "DB1010,DINT102",
"name": "PROGRAM"
},
{
"addr": "DB1010,DINT106",
"name": "JOB"
},
{
"addr": "DB1010,DINT110",
"name": "LENGTH"
}
]
},
{
"id": "cb814bd938d11a92",
"type": "s7comm",
"ip": "172.31.51.13",
"port": "102",
"rack": "0",
"slot": "4",
"payload": [
{
"S7_Type": "DB",
"S7_DBnum": "1010",
"S7_Datatype": "DI",
"S7_Offset": "102",
"S7_BitOffset": "0",
"S7_Quantity": "1",
"S7_Name": "PROGRAM"
},
{
"S7_Type": "DB",
"S7_DBnum": "1010",
"S7_Datatype": "DI",
"S7_Offset": "106",
"S7_BitOffset": "0",
"S7_Quantity": "1",
"S7_Name": "JOB"
},
{
"S7_Type": "DB",
"S7_DBnum": "1010",
"S7_Datatype": "DI",
"S7_Offset": "110",
"S7_BitOffset": "0",
"S7_Quantity": "1",
"S7_Name": "LENGTH"
}
]
}
]