Reading value from ML PLC using modbus serial RS232 in nodered

Hi There, as @Steve-Mcl was telling me why i am using code not the node the reason is this, This is a working example from a guy who helped me well enough but now he is not there and i have to read data from PLC as he made a very complicated program which i am not understanding and therefore i just need to read a value which is on tag N7:10 in PLC which i dont know how to read it, as this is very big program and i am trying to understand but its not working well as i expected so please help me.

[
    {
        "id": "14300416a6f63886",
        "type": "tab",
        "label": "Modbus-Slave",
        "disabled": false,
        "info": ""
    },
    {
        "id": "17e88aff9d040cc2",
        "type": "serial in",
        "z": "14300416a6f63886",
        "name": "",
        "serial": "6003e99f93d98d89",
        "x": 210,
        "y": 140,
        "wires": [
            [
                "411e0f4ba5ed577b",
                "09a05bfea99cf211"
            ]
        ]
    },
    {
        "id": "411e0f4ba5ed577b",
        "type": "trigger",
        "z": "14300416a6f63886",
        "name": "",
        "op1": "",
        "op2": "",
        "op1type": "pay",
        "op2type": "pay",
        "duration": "40",
        "extend": true,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 2,
        "x": 430,
        "y": 140,
        "wires": [
            [],
            [
                "6f8ecdfa50313a80"
            ]
        ]
    },
    {
        "id": "09a05bfea99cf211",
        "type": "join",
        "z": "14300416a6f63886",
        "name": "",
        "mode": "custom",
        "build": "buffer",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "",
        "joinerType": "bin",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 200,
        "y": 200,
        "wires": [
            [
                "d9e9e8ce396ec760"
            ]
        ]
    },
    {
        "id": "6f8ecdfa50313a80",
        "type": "change",
        "z": "14300416a6f63886",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "complete",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 140,
        "wires": [
            [
                "09a05bfea99cf211"
            ]
        ]
    },
    {
        "id": "d9e9e8ce396ec760",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Decode UnitID",
        "property": "payload[0]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 240,
        "y": 260,
        "wires": [
            [
                "803588323168b772"
            ],
            [
                "cae14779b7072cf7"
            ],
            [
                "fc5d2d22386ab19a"
            ]
        ]
    },
    {
        "id": "fc5d2d22386ab19a",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Decode Fn03, Fn16",
        "property": "payload[1]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "3",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "16",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 250,
        "y": 320,
        "wires": [
            [
                "ec39addff30338e2",
                "4973860738530f05"
            ],
            [
                "7fee2582d342f56b",
                "b63834c24e2a357d"
            ]
        ]
    },
    {
        "id": "4b53d6e135845d98",
        "type": "serial out",
        "z": "14300416a6f63886",
        "name": "",
        "serial": "6003e99f93d98d89",
        "x": 790,
        "y": 380,
        "wires": []
    },
    {
        "id": "7fee2582d342f56b",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Odp FC16",
        "func": "var F = [6];\nF[0] = msg.payload[0];\nF[1] = msg.payload[1];\nF[2] = msg.payload[2];\nF[3] = msg.payload[3];\nF[4] = msg.payload[4];\nF[5] = msg.payload[5];\nmsg.payload = F;\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 344,
        "wires": [
            [
                "18740f26719a216a"
            ]
        ]
    },
    {
        "id": "18740f26719a216a",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Oblicz CRC",
        "func": "var L = parseInt(msg.payload.length);\nvar A = [L+2];\n\n// Oblicz MODBUS RTU CRC\nvar crc = 0xFFFF;\n\nfor (var pos = 0; pos < L; pos++) { \n    A[pos] = msg.payload[pos];\n    crc ^= A[pos]; \n     for (var i = 8; i !== 0; i--) { \n      if ((crc & 0x0001) !== 0) { \n          crc >>= 1;\n          crc ^= 0xA001;\n        }\n       else \n          crc >>= 1; \n     }\n}\n//var TempS = crc.toString(16);\n\n//A[pos+1] = parseInt(\"0x\"+TempS.substring(0,2),16);\n//A[pos] = parseInt(\"0x\"+TempS.substring(2,4),16);\nA[pos] = crc % 256;\nA[pos+1] = crc >>= 8;\n\nvar b = Buffer.from(A);\nmsg.payload = b;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 344,
        "wires": [
            [
                "4b53d6e135845d98"
            ]
        ]
    },
    {
        "id": "42528871281c31b0",
        "type": "inject",
        "z": "14300416a6f63886",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 100,
        "wires": [
            [
                "8e69051ee2ee13c8"
            ]
        ]
    },
    {
        "id": "8e69051ee2ee13c8",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Init Bufory In/Out",
        "func": "// inicjacja stanu początkowego buforów modbusowych\n// rozmiar jest liczbą parzystą = ilość rejestrów *2\n// zdefiniowane są jako global więc dostępne są we wszystkich flowach.\n// adresy 0 do 10 maksymalnie może być do adresu 255 -  takie moje ograniczenie\n// dla uproszczenia.\nglobal.set(\"FrameN33\",[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);\nglobal.set(\"FrameN34\",[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "762b40f12f68dfa9",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Set coil ",
        "func": "var Out = global.get(\"FrameN33\");\nvar adr = parseInt(msg.adr);  //index startowy  FrameN33 = nr bajtu w którym przechowywana jest cewka\nvar mask = msg.payload;\nOut[adr] |= mask; \nglobal.set(\"FrameN33\",Out);\nmsg.payload = Out;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 790,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "b63834c24e2a357d",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Set register FC16",
        "func": "var Out = global.get(\"FrameN34\");\n\nmsg.adr =msg.payload[3]  //TUTAJ ZMIANA ustaw adres zmieniowego rejestru\nvar adr = msg.payload[3]*2;  //index startowy  FrameN34 = adr.rej *2\nvar bytes = msg.payload[6];\n\nfor (var pos = 0; pos < bytes; pos++) { \n  Out[adr] = msg.payload[7+pos];\n  adr++;\n  }\nglobal.set(\"FrameN34\",Out);\nmsg.payload = Out;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 270,
        "y": 440,
        "wires": [
            [
                "01e0ffcf26c48428"
            ]
        ]
    },
    {
        "id": "ec39addff30338e2",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Odp FC03",
        "func": "var Out = global.get(\"FrameN33\");\nvar L = msg.payload[5]*2 //ilość bajtów do wysłania ilość.rej *2\nvar F = [L + 3];         // nowa tablica o rozm. L+3   \nF[0] = msg.payload[0];   // przepisz UnitId\nF[1] = msg.payload[1];   // kod funkcji\nF[2] = L;                // iloś bajtów\n// przepisz do ramki bajty z bufora FrameN33\nvar adr = msg.payload[3]*2;  //index startowy  FrameN33 = adr.rej *2\nfor (var pos = 0; pos < L; pos++) {\n    F[pos+3] = Out[pos+adr];     \n    } \n\nmsg.payload = F;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 300,
        "wires": [
            [
                "18740f26719a216a",
                "dbb4feec3f4f6f56"
            ]
        ]
    },
    {
        "id": "dbb4feec3f4f6f56",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Clear FrameN33",
        "func": "// inicjacja stanu początkowego buforów modbusowych\n// rozmiar jest liczbą parzystą = ilość rejestrów *2\n// zdefiniowane są jako global więc dostępne są we wszystkich flowach.\n// adresy 0 do 10 maksymalnie może być do adresu 255 -  takie moje ograniczenie\n// dla uproszczenia.\nglobal.set(\"FrameN33\",[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 630,
        "y": 300,
        "wires": [
            [
                "2534ab96d7b7d0a5"
            ]
        ]
    },
    {
        "id": "f882f42b9a9c52d1",
        "type": "ui_led",
        "z": "14300416a6f63886",
        "order": 1,
        "group": "a10e59cacd707215",
        "width": "0",
        "height": "0",
        "label": "Power",
        "labelPlacement": "left",
        "labelAlignment": "center",
        "colorForValue": [
            {
                "color": "#000000",
                "value": "false",
                "valueType": "bool"
            },
            {
                "color": "#ffff00",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "square",
        "showGlow": true,
        "name": "O0:0/0",
        "x": 1090,
        "y": 420,
        "wires": []
    },
    {
        "id": "da69b33df6ecfc0e",
        "type": "q-gate",
        "z": "14300416a6f63886",
        "name": "q-gate",
        "controlTopic": "control",
        "defaultState": "queueing",
        "openCmd": "open",
        "closeCmd": "close",
        "toggleCmd": "toggle",
        "queueCmd": "queue",
        "defaultCmd": "default",
        "triggerCmd": "trigger",
        "flushCmd": "flush",
        "resetCmd": "reset",
        "peekCmd": "peek",
        "dropCmd": "drop",
        "statusCmd": "status",
        "maxQueueLength": "0",
        "keepNewest": false,
        "qToggle": false,
        "persist": false,
        "x": 630,
        "y": 560,
        "wires": [
            [
                "762b40f12f68dfa9"
            ]
        ]
    },
    {
        "id": "9532a84702c2b07c",
        "type": "link in",
        "z": "14300416a6f63886",
        "name": "",
        "links": [
            "2534ab96d7b7d0a5"
        ],
        "x": 685,
        "y": 620,
        "wires": [
            [
                "a6a3c98e1edd0de3"
            ]
        ]
    },
    {
        "id": "fc8b032911c8173c",
        "type": "link in",
        "z": "14300416a6f63886",
        "name": "",
        "links": [
            "4973860738530f05"
        ],
        "x": 685,
        "y": 680,
        "wires": [
            [
                "5741b77f46854363"
            ]
        ]
    },
    {
        "id": "a6a3c98e1edd0de3",
        "type": "change",
        "z": "14300416a6f63886",
        "name": "open",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "open",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "control",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 620,
        "wires": [
            [
                "da69b33df6ecfc0e"
            ]
        ]
    },
    {
        "id": "5741b77f46854363",
        "type": "change",
        "z": "14300416a6f63886",
        "name": "close",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "queue",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "control",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 680,
        "wires": [
            [
                "da69b33df6ecfc0e"
            ]
        ]
    },
    {
        "id": "4973860738530f05",
        "type": "link out",
        "z": "14300416a6f63886",
        "name": "close",
        "links": [
            "fc8b032911c8173c"
        ],
        "x": 765,
        "y": 333,
        "wires": []
    },
    {
        "id": "2534ab96d7b7d0a5",
        "type": "link out",
        "z": "14300416a6f63886",
        "name": "open",
        "links": [
            "9532a84702c2b07c"
        ],
        "x": 785,
        "y": 300,
        "wires": []
    },
    {
        "id": "615c06ce3f0354f9",
        "type": "link out",
        "z": "14300416a6f63886",
        "name": "",
        "links": [
            "3586a73c362a8dea"
        ],
        "x": 845,
        "y": 200,
        "wires": []
    },
    {
        "id": "803588323168b772",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Decode Fn03",
        "property": "payload[1]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "3",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 430,
        "y": 200,
        "wires": [
            [
                "7cac6f64e56c872f"
            ]
        ]
    },
    {
        "id": "d0a23f7673275245",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Set reg Id1",
        "func": "var Out1 = global.get(\"FrameN31\");\nvar adr1 = 0;\nvar bytes1 = msg.payload[2];\nfor (var pos1 = 0; pos1 < bytes1; pos1++) { \n  Out1[adr1] = msg.payload[3+pos1];\n  adr1++;\n  }\nglobal.set(\"FrameN31\",Out1);\nmsg.payload = Out1;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 740,
        "y": 200,
        "wires": [
            [
                "615c06ce3f0354f9"
            ]
        ]
    },
    {
        "id": "7cac6f64e56c872f",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Quantity",
        "property": "payload[2]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "58",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 590,
        "y": 200,
        "wires": [
            [
                "d0a23f7673275245"
            ]
        ]
    },
    {
        "id": "c10bcb658452a861",
        "type": "link out",
        "z": "14300416a6f63886",
        "name": "",
        "links": [
            "39f35a13959ff7f6"
        ],
        "x": 845,
        "y": 260,
        "wires": []
    },
    {
        "id": "cae14779b7072cf7",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Decode Fn04",
        "property": "payload[1]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "4",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 430,
        "y": 260,
        "wires": [
            [
                "af2f0758a389db16"
            ]
        ]
    },
    {
        "id": "af2f0758a389db16",
        "type": "switch",
        "z": "14300416a6f63886",
        "name": "Quantity",
        "property": "payload[2]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "80",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 590,
        "y": 260,
        "wires": [
            [
                "f85f8644e913b70c"
            ]
        ]
    },
    {
        "id": "f85f8644e913b70c",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Set reg Id2",
        "func": "var Out2 = global.get(\"FrameN32\");\nvar adr2 = 0;\nvar bytes2 = msg.payload[2];\nfor (var pos2 = 0; pos2 < bytes2; pos2++) { \n  Out2[adr2] = msg.payload[3+pos2];\n  adr2++;\n  }\nglobal.set(\"FrameN32\",Out2);\nmsg.payload = Out2;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 740,
        "y": 260,
        "wires": [
            [
                "c10bcb658452a861"
            ]
        ]
    },
    {
        "id": "3c0f9a6897a164f5",
        "type": "ui_button",
        "z": "14300416a6f63886",
        "name": "",
        "group": "44f1ca174f11089f",
        "order": 2,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Stop",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 200,
        "y": 580,
        "wires": [
            [
                "bc9f71198683f468"
            ]
        ]
    },
    {
        "id": "2f062ce176ac6bc3",
        "type": "change",
        "z": "14300416a6f63886",
        "name": "ON",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "2",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "adr",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 427,
        "y": 540,
        "wires": [
            [
                "da69b33df6ecfc0e"
            ]
        ]
    },
    {
        "id": "bc9f71198683f468",
        "type": "change",
        "z": "14300416a6f63886",
        "name": "OFF",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "4",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "adr",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 427,
        "y": 580,
        "wires": [
            [
                "da69b33df6ecfc0e"
            ]
        ]
    },
    {
        "id": "01e0ffcf26c48428",
        "type": "function",
        "z": "14300416a6f63886",
        "name": "Read coils",
        "func": "var Out2 = global.get(\"FrameN34\");\nvar adr2 = 1;\nvar msg0 = { payload:(Out2[adr2] & 1) !=0 };\nvar msg1 = { payload:(Out2[adr2] & 2) !=0 };\nvar msg2 = { payload:(Out2[adr2] & 4) !=0 };\nvar msg3 = { payload:(Out2[adr2] & 8) !=0 };\nvar msg4 = { payload:(Out2[adr2] & 16) !=0 };\nvar msg5 = { payload:(Out2[adr2] & 32) !=0 };\nvar msg6 = { payload:(Out2[adr2] & 64) !=0 };\nvar msg7 = { payload:(Out2[adr2] & 128) !=0 };\nreturn [msg0,msg1,msg2,msg3,msg4,msg5,msg6,msg7];",
        "outputs": 8,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 560,
        "y": 440,
        "wires": [
            [
                "f882f42b9a9c52d1"
            ],
            [],
            [],
            [],
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "81b1d7f4b5115bdd",
        "type": "ui_button",
        "z": "14300416a6f63886",
        "name": "",
        "group": "44f1ca174f11089f",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Start",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 200,
        "y": 540,
        "wires": [
            [
                "2f062ce176ac6bc3"
            ]
        ]
    },
    {
        "id": "6003e99f93d98d89",
        "type": "serial-port",
        "serialport": "/dev/ttyUSB0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "1",
        "bin": "bin",
        "out": "count",
        "addchar": "",
        "responsetimeout": "10000"
    },
    {
        "id": "a10e59cacd707215",
        "type": "ui_group",
        "name": "Lamp",
        "tab": "9aaf3869c16a83db",
        "order": 8,
        "disp": true,
        "width": 4,
        "collapse": false,
        "className": ""
    },
    {
        "id": "44f1ca174f11089f",
        "type": "ui_group",
        "name": "Buttons",
        "tab": "9aaf3869c16a83db",
        "order": 7,
        "disp": true,
        "width": 4,
        "collapse": false,
        "className": ""
    },
    {
        "id": "9aaf3869c16a83db",
        "type": "ui_tab",
        "name": "Frank for Jayesh",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

A NR using the Modbus protocol is unable to read a value that the ML does not send to it.
ML sends 30 registers starting from address N34:0, and in this program 1 bit from address N34:0 is used.
If you can't rewrite the data from N7:10 (in fact, it is the value of T4:0.ACC) into the free area starting with N34:1 in ML, then I don't see it.

anyone one with a solution to this issue @Steve-Mcl

Did you check or setup the PLC as I indicated in the previous thread here: How to find address for ML 1200 for modbus or RS485 - #23 by Steve-Mcl

What addresses are mapped to the modbus register's?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.