# Modbus\_assign a string to different int-values

**URL:** <https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736>\
**Category:** General\
**Created:** [20 March 2023 09:14 UTC](https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736 "2023-03-20T09:14:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)\
**Post date:** [20 March 2023 09:14 UTC](https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736/1 "2023-03-20T09:14:37Z")

</div>

Hello.

I hope my topic is kinda right. I am experimenting with MODBUS (again).  
Today i try to read a WarningCode and an AlarmCode from my pump via MODBUS.

There a 2 adresses to read out warning and Alarm.

Alarm = 216  
Warning 217

Depedning on the type of alarm or warning, the respective adress gives different integers.  
for example for adress 217 (warning): 208 (error 1), 57 (error 2) ... and so on..

My question now: I know i could do it with a simple function and if statements. I read the more "elegant" way for such scenarios is to user buffersparser. Now i am a bit confused how to user the bufferparser so assgin the integer to a string-output(errormessage).

```auto
[
    {
        "id": "916fba86ba4e53b4",
        "type": "modbus-flex-getter",
        "z": "4b39b758866405c2",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "server": "0e3ec676f3e39293",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "x": 1740,
        "y": 180,
        "wires": [
            [
                "9839a3a7df26be41",
                "191f1d8a2c779968"
            ],
            []
        ]
    },
    {
        "id": "9839a3a7df26be41",
        "type": "modbus-response",
        "z": "4b39b758866405c2",
        "name": "",
        "registerShowMax": 20,
        "x": 1760,
        "y": 100,
        "wires": []
    },
    {
        "id": "a5ccc76734177a20",
        "type": "function",
        "z": "4b39b758866405c2",
        "name": "Read_216",
        "func": "msg.payload =\n{\n value: msg.payload,\n 'fc': 3,\n 'unitid': 0,\n 'address': 216,\n 'quantity': 2\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1530,
        "y": 180,
        "wires": [
            [
                "916fba86ba4e53b4"
            ]
        ]
    },
    {
        "id": "ba033e6638e9c713",
        "type": "inject",
        "z": "4b39b758866405c2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "2",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1340,
        "y": 180,
        "wires": [
            [
                "a5ccc76734177a20"
            ]
        ]
    },
    {
        "id": "191f1d8a2c779968",
        "type": "buffer-parser",
        "z": "4b39b758866405c2",
        "name": "buffer parser",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "AlarmCode",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "string",
                "name": "WarningCode",
                "offset": 2,
                "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": 2010,
        "y": 180,
        "wires": [
            [
                "a900d3925b31634f"
            ]
        ]
    },
    {
        "id": "a900d3925b31634f",
        "type": "debug",
        "z": "4b39b758866405c2",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 2180,
        "y": 100,
        "wires": []
    },
    {
        "id": "0e3ec676f3e39293",
        "type": "modbus-client",
        "name": "CIM500",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "10.240.6.39",
        "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
    }
]

```

Thank you

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [20 March 2023 11:04 UTC](https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736/2 "2023-03-20T11:04:34Z")

</div>

> [@Manuel\_o](#):
>
> Now i am a bit confused how to user the bufferparser so assgin the integer to a string-output(errormessage).

Hello Manuel .. you cannot do this with buffer-parser, as far as i know.  
buffer-parser does its job converting the buffer from Modbus to whatever type the value is ( int in this case )  
and its up to you to later re-assign those integers to an actual human readable error.

As you suggested a Function node after buffer-parser is a good way.

---

<div class="post-metadata">

**Author:** ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)\
**Post date:** [27 March 2023 07:05 UTC](https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736/3 "2023-03-27T07:05:56Z")

</div>

thank your again to all for the reply. I ve done it with functions at the end. =)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 May 2023 07:06 UTC](https://discourse.nodered.org/t/modbus-assign-a-string-to-different-int-values/76736/4 "2023-05-26T07:06:14Z")

</div>

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