Is it possible to dynamically set length for 'buffer maker' and ' buffer parser'

Hi folks,
I am putting together a flow to read and write 32bit floats from/to a PLC using Modbus TCP.

To be honest it took mw way longer than it should have to get my head around the buffer manipulation nodes but I have them working now and can read and right floats... Which is nice!

However if I want to change the quantity of data read I have to alter the trigger for the flex_modbus node and also adjust the lengths for both the buffer nodes.

For context my read ...
my read gets 'some', lets say 6, words from the PLC, these are 'raw' values which I treat as uint16.
This data is used to create a buffer, 12 bytes long.
The buffer is then interpreted as a float32, which is how the PLC is interpreting the same data.

Writing out is a similar process that prepares an array of two uint16 for the flex_write node.

As I said both processes work but I would ideally like to create sub flow that wrap the process in much the same way as the flex-modbus nodes work.

I have tried copying the 'length' path and setting that with a change node but couldn't get it to work.

[
    {
        "id": "8f6909ec361ec4c9",
        "type": "tab",
        "label": "W/R int32 using Modbus",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "ac265d7f498243d9",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 20",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 120,
        "wires": []
    },
    {
        "id": "08ac5471b622f9c9",
        "type": "modbus-flex-getter",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "0ca896640dce56e2",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": true,
        "startDelayTime": "1",
        "x": 570,
        "y": 360,
        "wires": [
            [
                "07802434ebcdba9f",
                "cbe085c3e3b99e77"
            ],
            []
        ]
    },
    {
        "id": "e6a52ab120b8f69b",
        "type": "modbus-flex-write",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "server": "0ca896640dce56e2",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 970,
        "y": 120,
        "wires": [
            [
                "ac265d7f498243d9"
            ],
            []
        ]
    },
    {
        "id": "85600f1e77533ef8",
        "type": "change",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "payload.unitid",
                "pt": "msg",
                "to": "255",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.fc",
                "pt": "msg",
                "to": "modbus.wrd.fc_wn",
                "tot": "global"
            },
            {
                "t": "set",
                "p": "payload.address",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.quantity",
                "pt": "msg",
                "to": "2",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.value",
                "pt": "msg",
                "to": "value",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 120,
        "wires": [
            [
                "e6a52ab120b8f69b"
            ]
        ],
        "info": "{ value: msg.payload, \r\n'fc': 5, \r\n'unitid': 1, \r\n'address': 0 , \r\n'quantity': 1 }"
    },
    {
        "id": "1280270bd9f81893",
        "type": "inject",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "70000",
        "payloadType": "num",
        "x": 210,
        "y": 120,
        "wires": [
            [
                "6bdcda7432a3694b",
                "9331c816dcb7049c"
            ]
        ]
    },
    {
        "id": "d93a7a15489606cd",
        "type": "inject",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "props": [
            {
                "p": "payload.connectorType",
                "v": "TCP",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 210,
        "y": 360,
        "wires": [
            [
                "fc887a65d6d4b2fb"
            ]
        ]
    },
    {
        "id": "fc887a65d6d4b2fb",
        "type": "change",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload.unitid",
                "pt": "msg",
                "to": "255",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.fc",
                "pt": "msg",
                "to": "modbus.wrd.fc_rn",
                "tot": "global"
            },
            {
                "t": "set",
                "p": "payload.address",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.quantity",
                "pt": "msg",
                "to": "6",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 360,
        "wires": [
            [
                "08ac5471b622f9c9"
            ]
        ],
        "info": "{ value: msg.payload, \r\n'fc': 5, \r\n'unitid': 1, \r\n'address': 0 , \r\n'quantity': 1 }"
    },
    {
        "id": "5c2edcb1a6eb0eba",
        "type": "buffer-parser",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "item2",
                "offset": 2,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "uint16be",
                "name": "item1",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "value",
        "msgPropertyType": "str",
        "resultType": "value",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 550,
        "y": 120,
        "wires": [
            [
                "149bf2fff67d82bd",
                "85600f1e77533ef8"
            ]
        ]
    },
    {
        "id": "6bdcda7432a3694b",
        "type": "buffer-maker",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "int32be",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 370,
        "y": 120,
        "wires": [
            [
                "5c2edcb1a6eb0eba",
                "6976a615ad52d613"
            ]
        ]
    },
    {
        "id": "9331c816dcb7049c",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 21",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 360,
        "y": 160,
        "wires": []
    },
    {
        "id": "6976a615ad52d613",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 22",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 160,
        "wires": []
    },
    {
        "id": "149bf2fff67d82bd",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 23",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 160,
        "wires": []
    },
    {
        "id": "1779bdd3cbd63708",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 24",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 220,
        "wires": []
    },
    {
        "id": "5ece56966b7c67b7",
        "type": "modbus-flex-write",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "server": "0ca896640dce56e2",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 970,
        "y": 220,
        "wires": [
            [
                "1779bdd3cbd63708"
            ],
            []
        ]
    },
    {
        "id": "d6fa49d4481da465",
        "type": "change",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "payload.unitid",
                "pt": "msg",
                "to": "255",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.fc",
                "pt": "msg",
                "to": "modbus.wrd.fc_wn",
                "tot": "global"
            },
            {
                "t": "set",
                "p": "payload.address",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.quantity",
                "pt": "msg",
                "to": "2",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "payload.value",
                "pt": "msg",
                "to": "value",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 220,
        "wires": [
            [
                "5ece56966b7c67b7"
            ]
        ],
        "info": "{ value: msg.payload, \r\n'fc': 5, \r\n'unitid': 1, \r\n'address': 0 , \r\n'quantity': 1 }"
    },
    {
        "id": "65ea7fbb4843929b",
        "type": "inject",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-3.142",
        "payloadType": "num",
        "x": 210,
        "y": 220,
        "wires": [
            [
                "03a2179ddd376c93",
                "71feae464e7a38e3"
            ]
        ]
    },
    {
        "id": "964ddf22a39acc72",
        "type": "buffer-parser",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "item2",
                "offset": 2,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "uint16be",
                "name": "item1",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "value",
        "msgPropertyType": "str",
        "resultType": "value",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 550,
        "y": 220,
        "wires": [
            [
                "8a56fe0f46ed61d6",
                "d6fa49d4481da465"
            ]
        ]
    },
    {
        "id": "03a2179ddd376c93",
        "type": "buffer-maker",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "floatbe",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 370,
        "y": 220,
        "wires": [
            [
                "964ddf22a39acc72",
                "d966885f3eab5331"
            ]
        ]
    },
    {
        "id": "71feae464e7a38e3",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 25",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 360,
        "y": 260,
        "wires": []
    },
    {
        "id": "d966885f3eab5331",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 26",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 260,
        "wires": []
    },
    {
        "id": "8a56fe0f46ed61d6",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 27",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 260,
        "wires": []
    },
    {
        "id": "76d2b6224a2544bc",
        "type": "buffer-parser",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "floatbe",
                "name": "item1",
                "offset": 0,
                "length": 3,
                "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": true,
        "setTopic": true,
        "outputs": 1,
        "x": 950,
        "y": 360,
        "wires": [
            [
                "255f8b7a82b99a42"
            ]
        ]
    },
    {
        "id": "07802434ebcdba9f",
        "type": "buffer-maker",
        "z": "8f6909ec361ec4c9",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "uint16be",
                "length": 6,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "swap32",
        "swap2": "swap16",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 770,
        "y": 360,
        "wires": [
            [
                "23bbb69a5093c514",
                "76d2b6224a2544bc"
            ]
        ]
    },
    {
        "id": "cbe085c3e3b99e77",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 28",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 420,
        "wires": []
    },
    {
        "id": "23bbb69a5093c514",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 29",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 420,
        "wires": []
    },
    {
        "id": "255f8b7a82b99a42",
        "type": "debug",
        "z": "8f6909ec361ec4c9",
        "name": "debug 30",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 360,
        "wires": []
    },
    {
        "id": "0ca896640dce56e2",
        "type": "modbus-client",
        "name": "bycplc",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.10.19",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "255",
        "commandDelay": "5",
        "clientTimeout": "500",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "5000",
        "parallelUnitIdsAllowed": true,
        "showWarnings": true,
        "showLogs": true
    }
]

Thanks for looking,
Al

There are two possible solutions

  1. If all of the values to be parsed are of the same type then set length to -1 and it will detect the length of data and return as many of the specified type values as possible.
  2. The parser node itself can be 100% automated via dynamic specification. Ie you can send the parser specification in the message along with the data.

See the built-in help and check out the built-in examples (ctrl-i -> examples)

Cool... Feeling a little silly though as I looked at the help and didn't see the bit that explained using a dynamic spec.
I had realised it was the spec I needed to update, that was how I found it didn't work!

As all the values are the same length/spec, always, I will give the -1, something else I missed apparently, a go....

You star... that works great, thanks a bunch :star_struck:

I need to get better at reading the help... Sorry

Cheers,
Al

1 Like

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