MODBUS read and write

Hello,

i am still learning about MODBUS and created my own littile project. I read data from my pool-dosing pump and also conrtolling it via a node-red dashbaord on a VM. Its more a fun project for learning purpose.

Everything works so far but a couple uncertainties appeared in my flow (its a snipped, but it should not matter because the whole flow just reads more adresses).
In my node red dashbaord i have 6 dropdown menus, where i can make changes. This changes are send to a MQTT broker: CIM500/W_REMOTE
CIM500/W_DEAREATING (and so on)

The following flow is on a Raspi and dircetly connected to my pump to read and write to it

[
    {
        "id": "fbf3f9d9dd9b2d6a",
        "type": "mqtt out",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/ADR_201",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "",
        "x": 170,
        "y": 320,
        "wires": []
    },
    {
        "id": "2345f538fe542fe5",
        "type": "buffer-parser",
        "z": "36a1d1734752b2cb",
        "name": "buffer parser",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "bool",
                "name": "ActRemoteAccess",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActDeaerating",
                "offset": 1,
                "length": 1,
                "offsetbit": 1,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "AnalogueMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActTimerMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 3,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActSlowMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 4,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActVelocity",
                "offset": 1,
                "length": 1,
                "offsetbit": 5,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 150,
        "y": 280,
        "wires": [
            [
                "722783b55317f4f1",
                "fbf3f9d9dd9b2d6a"
            ]
        ]
    },
    {
        "id": "722783b55317f4f1",
        "type": "debug",
        "z": "36a1d1734752b2cb",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 350,
        "y": 280,
        "wires": []
    },
    {
        "id": "13fce020ab73d03f",
        "type": "modbus-flex-getter",
        "z": "36a1d1734752b2cb",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "3c8dd0dd2a7c33cf",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 180,
        "y": 240,
        "wires": [
            [
                "e7535949dc228a2d",
                "2345f538fe542fe5",
                "bc12eea645bbc032"
            ],
            []
        ]
    },
    {
        "id": "3b563adf71163ecf",
        "type": "function",
        "z": "36a1d1734752b2cb",
        "name": "Read_201",
        "func": "msg.payload =\n{\n    value: msg.payload,\n    'fc': 3,\n    'unitid': 0,\n    'address': 200,\n    'quantity': 1\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 150,
        "y": 200,
        "wires": [
            [
                "13fce020ab73d03f"
            ]
        ]
    },
    {
        "id": "e7535949dc228a2d",
        "type": "modbus-response",
        "z": "36a1d1734752b2cb",
        "name": "",
        "registerShowMax": 20,
        "x": 410,
        "y": 180,
        "wires": []
    },
    {
        "id": "c045d0c87e79819f",
        "type": "inject",
        "z": "36a1d1734752b2cb",
        "name": "interval",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 160,
        "wires": [
            [
                "3b563adf71163ecf"
            ]
        ]
    },
    {
        "id": "bc12eea645bbc032",
        "type": "function",
        "z": "36a1d1734752b2cb",
        "name": "Read_202",
        "func": "msg.payload =\n{\n    value: msg.payload,\n    'fc': 3,\n    'unitid': 0,\n    'address': 201,\n    'quantity': 1\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 750,
        "y": 200,
        "wires": [
            [
                "60bdb194082b232c"
            ]
        ]
    },
    {
        "id": "60bdb194082b232c",
        "type": "modbus-flex-getter",
        "z": "36a1d1734752b2cb",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "3c8dd0dd2a7c33cf",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 780,
        "y": 240,
        "wires": [
            [
                "fa19bd3752e971ae",
                "4194eec227d415c8"
            ],
            []
        ]
    },
    {
        "id": "fa19bd3752e971ae",
        "type": "modbus-response",
        "z": "36a1d1734752b2cb",
        "name": "",
        "registerShowMax": 20,
        "x": 1010,
        "y": 240,
        "wires": []
    },
    {
        "id": "728b1f7ef524f8cc",
        "type": "debug",
        "z": "36a1d1734752b2cb",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 280,
        "wires": []
    },
    {
        "id": "4194eec227d415c8",
        "type": "buffer-parser",
        "z": "36a1d1734752b2cb",
        "name": "buffer parser",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "bool",
                "name": "ActAutoDeaerating",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActFlowControlEnable",
                "offset": 1,
                "length": 1,
                "offsetbit": 1,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActModbusWatchdogEnable",
                "offset": 1,
                "length": 1,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActAutoFlowAdaptEnable",
                "offset": 1,
                "length": 1,
                "offsetbit": 3,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "ActPulseMemoryEnable",
                "offset": 1,
                "length": 1,
                "offsetbit": 4,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 750,
        "y": 280,
        "wires": [
            [
                "728b1f7ef524f8cc",
                "9560f694be10b5da"
            ]
        ]
    },
    {
        "id": "9560f694be10b5da",
        "type": "mqtt out",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/ADR_202",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "",
        "x": 770,
        "y": 320,
        "wires": []
    },
    {
        "id": "ef75e27e021b43fd",
        "type": "buffer-maker",
        "z": "36a1d1734752b2cb",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item",
                "type": "16bitbe",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 430,
        "y": 540,
        "wires": [
            [
                "b376463fd6e3302e"
            ]
        ]
    },
    {
        "id": "b376463fd6e3302e",
        "type": "buffer-parser",
        "z": "36a1d1734752b2cb",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "decimal",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 430,
        "y": 580,
        "wires": [
            [
                "ca2d83178b5842fc"
            ]
        ]
    },
    {
        "id": "ca2d83178b5842fc",
        "type": "function",
        "z": "36a1d1734752b2cb",
        "name": "write_101",
        "func": "var fc = 6;\nvar sa = 100;\nvar addresses = 1;\nvar value = msg.payload.decimal;  // value calculated from buffer-parser\n\nmsg.payload = { \"value\": value, 'fc': fc, 'unitid': 1, 'address': sa, 'quantity': addresses };\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 620,
        "wires": [
            [
                "5dcded8496d81837",
                "e43c2a1897cbf75c"
            ]
        ]
    },
    {
        "id": "fbf4e6942e41664b",
        "type": "function",
        "z": "36a1d1734752b2cb",
        "name": "update ContextADR100",
        "func": "let ps = flow.get(\"ContextADR101\")\n\nps = [[ps.Remote_On_Off, ps.Deaerating, ps.AnalogueMode, ps.TimerMode, ps.SlowMode, ps.Velocity, false, false]]\n\nif (msg.topic === \"CIM500/W_Remote\") {\n    ps[0][0] = msg.payload\n}\nelse if (msg.topic === \"CIM500/W_Deaerating\") {\n    ps[0][1] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_AnalogMode\") {\n    ps[0][2] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_TimerMode\") {\n    ps[0][3] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_SlowMode\") {\n    ps[0][4] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_Velocity\") {\n    ps[0][5] = msg.payload;\n}\n\nmsg.payload = ps;\n\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 500,
        "wires": [
            [
                "ef75e27e021b43fd"
            ]
        ]
    },
    {
        "id": "76d68559827a49c5",
        "type": "function",
        "z": "36a1d1734752b2cb",
        "name": "Read_101",
        "func": "msg.payload =\n{\n    value: msg.payload,\n    'fc': 3,\n    'unitid': 1,\n    'address': 100,\n    'quantity': 1\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 540,
        "wires": [
            [
                "8d205d8cc0db7c64"
            ]
        ]
    },
    {
        "id": "627a1d67391794b3",
        "type": "inject",
        "z": "36a1d1734752b2cb",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "3",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1030,
        "y": 500,
        "wires": [
            [
                "76d68559827a49c5"
            ]
        ]
    },
    {
        "id": "d7da7811fc270a98",
        "type": "buffer-parser",
        "z": "36a1d1734752b2cb",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "bool",
                "name": "Remote_On_Off",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Deaerating",
                "offset": 1,
                "length": 1,
                "offsetbit": 1,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "AnalogueMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "TimerMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 3,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "SlowMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 4,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Velocity",
                "offset": 1,
                "length": 1,
                "offsetbit": 5,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 1030,
        "y": 620,
        "wires": [
            [
                "704abbaddb6c8ae2"
            ]
        ]
    },
    {
        "id": "704abbaddb6c8ae2",
        "type": "change",
        "z": "36a1d1734752b2cb",
        "name": "ContextADR101",
        "rules": [
            {
                "t": "set",
                "p": "ContextADR101",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1040,
        "y": 660,
        "wires": [
            []
        ]
    },
    {
        "id": "075b8fdec43a80ce",
        "type": "link out",
        "z": "36a1d1734752b2cb",
        "name": "link out 6",
        "mode": "link",
        "links": [
            "19ed1612eccf7bb8"
        ],
        "x": 835,
        "y": 660,
        "wires": []
    },
    {
        "id": "19ed1612eccf7bb8",
        "type": "link in",
        "z": "36a1d1734752b2cb",
        "name": "link in 6",
        "links": [
            "075b8fdec43a80ce"
        ],
        "x": 855,
        "y": 540,
        "wires": [
            [
                "76d68559827a49c5"
            ]
        ]
    },
    {
        "id": "0acf1f0892928080",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_Remote",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 150,
        "y": 500,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "2893b70545622863",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_Deaerating",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 540,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "63edc1f5b27fe804",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_AnalogMode",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 580,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "6f1ffe595dde30a8",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_TimerMode",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 620,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "ebcb7856ebe2cb50",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_SlowMode",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 660,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "66f1be91f8795dd3",
        "type": "mqtt in",
        "z": "36a1d1734752b2cb",
        "name": "",
        "topic": "CIM500/W_Velocity",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 150,
        "y": 700,
        "wires": [
            [
                "fbf4e6942e41664b"
            ]
        ]
    },
    {
        "id": "5dcded8496d81837",
        "type": "modbus-flex-write",
        "z": "36a1d1734752b2cb",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "server": "3c8dd0dd2a7c33cf",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 450,
        "y": 660,
        "wires": [
            [
                "075b8fdec43a80ce",
                "a1c8ce5a9b7475dd"
            ],
            []
        ]
    },
    {
        "id": "e29ff321a62aaf80",
        "type": "modbus-response",
        "z": "36a1d1734752b2cb",
        "name": "",
        "registerShowMax": 20,
        "x": 1310,
        "y": 580,
        "wires": []
    },
    {
        "id": "a1c8ce5a9b7475dd",
        "type": "modbus-response",
        "z": "36a1d1734752b2cb",
        "name": "",
        "registerShowMax": 20,
        "x": 670,
        "y": 660,
        "wires": []
    },
    {
        "id": "8d205d8cc0db7c64",
        "type": "modbus-flex-getter",
        "z": "36a1d1734752b2cb",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "3c8dd0dd2a7c33cf",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 1060,
        "y": 580,
        "wires": [
            [
                "e29ff321a62aaf80",
                "d7da7811fc270a98"
            ],
            []
        ]
    },
    {
        "id": "e43c2a1897cbf75c",
        "type": "debug",
        "z": "36a1d1734752b2cb",
        "name": "debug 21",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 620,
        "wires": []
    },
    {
        "id": "b3fece4a99faa782",
        "type": "comment",
        "z": "36a1d1734752b2cb",
        "name": "WRITE PROCESS",
        "info": "",
        "x": 150,
        "y": 440,
        "wires": []
    },
    {
        "id": "e24cff856cebe718",
        "type": "comment",
        "z": "36a1d1734752b2cb",
        "name": "READ PROCESS",
        "info": "",
        "x": 160,
        "y": 100,
        "wires": []
    },
    {
        "id": "3c8dd0dd2a7c33cf",
        "type": "modbus-client",
        "name": "CIM500/Rasp",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.1.2",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showWarnings": true,
        "showLogs": true
    }
]
  1. I dont know if there is a right or wrong way to use MODBUS, but i am curious if my conecpt seems to be right

  2. WHat i noticed: The MODBUS FLEX WRITE has always for a split second "queue " in its node. Since i read data from my pump every second, its kinda logic to me. long story short. What i ask myself. How can i avoid (in this flow specfic right now) that there wont be any issue that the reading and writing process will disturb each other?!

Also i am happy for constructive input. Love to learn new ways

thank you

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