Writing 16bit/32 bit Signed Integers to Modbus TCP server on NodeRed

Hi,

I am reading 16 & 32 bit Signed Integers from Modbus RTU registers and trying to write this back to Modbus TCP Server. Basically I am using node-red to convert Modbus RTU read data to Modbus TCP data so that an external client can access it.

Problem:
Modbus TCP write only accepts values in the range 0-65535 (basically unsigned). This creates an issue because 16 bit signed int value such as a temperature value can contain negative values.

Help?
Can you help me find a way to write 16/32 bit signed integer values via Modbus TCP. Basically a good conversion from 16/32 bit signed to unsigned in the range 0-65535 and a way to convert it back at the TCP client.

Node-red-contrib-buffer-parser has this capability.

Check out the built in examples (CTRL-I)

here is an example:

[
    {
        "id": "6be4e067.5a02",
        "type": "buffer-maker",
        "z": "2bd6dc17.504c44",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "uint32be",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 390,
        "y": 420,
        "wires": [
            [
                "aa84dcee.4b5ff8"
            ]
        ]
    },
    {
        "id": "aa84dcee.4b5ff8",
        "type": "buffer-parser",
        "z": "2bd6dc17.504c44",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "data",
                "offset": 0,
                "length": 2,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 670,
        "y": 420,
        "wires": [
            [
                "aebe9ede.e25cf",
                "cff8ce0.a8b63b"
            ]
        ]
    },
    {
        "id": "aebe9ede.e25cf",
        "type": "modbus-write",
        "z": "2bd6dc17.504c44",
        "name": "40236",
        "showStatusActivities": false,
        "showErrors": true,
        "unitid": "3",
        "dataType": "MHoldingRegisters",
        "adr": "40236",
        "quantity": "2",
        "server": "b6c6500c.41cc1",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "x": 850,
        "y": 420,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "b6c6500c.41cc1",
        "type": "modbus-client",
        "name": "SBS2.5",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "192.168.168.55",
        "tcpPort": "502",
        "tcpType": "TCP-RTU-BUFFERED",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": "3",
        "commandDelay": "10",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": false
    }
]

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