# Converting an array of bytes into a int16 to write in a modbus server(holding register)

**URL:** <https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370>\
**Category:** General\
**Created:** [8 May 2022 14:47 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370 "2022-05-08T14:47:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 14:47 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/1 "2022-05-08T14:47:03Z")

</div>

Hello guys,

I'm trying to convert an array of bytes(16bytes exactly) that I'm receiving from a function to an int16 to be able to enter it in a modbus holding register but I don't understand how to convert it. I tried with the buffer parser and it didn't work (might be that don't know how to use it).

Important Info: I must absolutely do the conversion from this array

Do you know a way to do the conversion?

An example of what I want to be able to do:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6dcad394bc05cd36380cae04d8aa196f38b7b440.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 May 2022 15:01 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/2 "2022-05-08T15:01:20Z")

</div>

The node you will need courtesy of @Steve-Mcl

> **[node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser)**
>
> Node-red nodes to convert values to and from buffer/array. Supports Big/Little Endian, BCD, byte swapping and much more

Have not used this node myself, but seems to be the goto for this requirement

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:04 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/3 "2022-05-08T15:04:43Z")

</div>

I might be really dumb but i tried to use it multiple times looking throught the forums and tutorials but I didn't manage to make it work

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:08 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/4 "2022-05-08T15:08:33Z")

</div>

This what I have when I use It:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/88091f46814eb4578d92701971224a331fa2bfa1.png)

I don't understand the parameters

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:11 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/5 "2022-05-08T15:11:31Z")

</div>

> [@Theodros](#):
>
> I don't understand the parameters

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad15bf28118b86985776923ef65f735f47c80670.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:12 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/6 "2022-05-08T15:12:25Z")

</div>

> [@Theodros](#):
>
> I don't understand the parameters

What does the input data look like and what do you expect out of it?

PS, for modbus, you likely need UINT16be not INT16be

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:20 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/7 "2022-05-08T15:20:40Z")

</div>

So here's my flow

```auto
[
    {
        "id": "1378ba83.90c825",
        "type": "tab",
        "label": "Read file",
        "disabled": false,
        "info": ""
    },
    {
        "id": "20b32e98.5e9fb2",
        "type": "file in",
        "z": "1378ba83.90c825",
        "name": "Requête1",
        "filename": "C:\\Users\\Theodros\\Documents\\GRTgaz\\NODE-RED_GRTgaz\\Tables modbus\\Requete1.csv",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 300,
        "y": 460,
        "wires": [
            [
                "a8436e2f.135fe"
            ]
        ]
    },
    {
        "id": "a8436e2f.135fe",
        "type": "csv",
        "z": "1378ba83.90c825",
        "name": "",
        "sep": ",",
        "hdrin": false,
        "hdrout": "all",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "label",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 450,
        "y": 460,
        "wires": [
            [
                "9e327bbf.9c3c58",
                "93cf18f7.648228"
            ]
        ]
    },
    {
        "id": "9e327bbf.9c3c58",
        "type": "debug",
        "z": "1378ba83.90c825",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 420,
        "wires": []
    },
    {
        "id": "93cf18f7.648228",
        "type": "function",
        "z": "1378ba83.90c825",
        "name": "REMPLISSAGE",
        "func": "msg.options = msg.payload.map((el, index) => {\n\nreturn { [el.label] : index }\n \n})\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 540,
        "wires": [
            [
                "a33a2128.40e88"
            ]
        ]
    },
    {
        "id": "9232e59c366097f5",
        "type": "file in",
        "z": "1378ba83.90c825",
        "name": "Requête2",
        "filename": "C:\\Users\\Theodros\\Documents\\GRTgaz\\NODE-RED_GRTgaz\\Tables modbus\\Requete2.csv",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 300,
        "y": 700,
        "wires": [
            [
                "46283feae83669d0"
            ]
        ]
    },
    {
        "id": "bfa7ea1854572131",
        "type": "debug",
        "z": "1378ba83.90c825",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 660,
        "wires": []
    },
    {
        "id": "7b54af6a49744acb",
        "type": "function",
        "z": "1378ba83.90c825",
        "name": "REMPLISSAGE",
        "func": "msg.options = msg.payload.map((el, index) => {\n\nreturn { [el.label] : index }\n \n})\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 780,
        "wires": [
            [
                "7a1076f8bb47d19f"
            ]
        ]
    },
    {
        "id": "55ca832546785f2b",
        "type": "file in",
        "z": "1378ba83.90c825",
        "name": "Requête3",
        "filename": "C:\\Users\\Theodros\\Documents\\GRTgaz\\NODE-RED_GRTgaz\\Tables modbus\\Requete3.csv",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 300,
        "y": 960,
        "wires": [
            [
                "db9bd5da2b417c25"
            ]
        ]
    },
    {
        "id": "4661fbad8601b1c4",
        "type": "debug",
        "z": "1378ba83.90c825",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 920,
        "wires": []
    },
    {
        "id": "fcf264a7e9715206",
        "type": "function",
        "z": "1378ba83.90c825",
        "name": "REMPLISSAGE",
        "func": "msg.options = msg.payload.map((el, index) => {\n\nreturn { [el.label] : index }\n \n})\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 1040,
        "wires": [
            [
                "99de5655e7178068"
            ]
        ]
    },
    {
        "id": "a33a2128.40e88",
        "type": "ui_dropdown",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "",
        "tooltip": "",
        "place": "Select option",
        "group": "671cb6d0f0a7d1c7",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "S1",
        "topicType": "str",
        "className": "",
        "x": 860,
        "y": 540,
        "wires": [
            [
                "b7b1f645eb9b83c0"
            ]
        ]
    },
    {
        "id": "4dd9ce82a81007d0",
        "type": "ui_button",
        "z": "1378ba83.90c825",
        "name": "",
        "group": "ac5f4946e8c230e7",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "label": "button",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "date",
        "topic": "topic",
        "topicType": "msg",
        "x": 70,
        "y": 700,
        "wires": [
            [
                "20b32e98.5e9fb2",
                "9232e59c366097f5",
                "55ca832546785f2b"
            ]
        ]
    },
    {
        "id": "458310f8128b08be",
        "type": "ui_switch",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "671cb6d0f0a7d1c7",
        "order": 2,
        "width": "1",
        "height": "1",
        "passthru": true,
        "decouple": "false",
        "topic": "B1",
        "topicType": "str",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 850,
        "y": 480,
        "wires": [
            [
                "b7b1f645eb9b83c0"
            ]
        ]
    },
    {
        "id": "46283feae83669d0",
        "type": "csv",
        "z": "1378ba83.90c825",
        "name": "",
        "sep": ",",
        "hdrin": false,
        "hdrout": "all",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "label",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 450,
        "y": 700,
        "wires": [
            [
                "bfa7ea1854572131",
                "7b54af6a49744acb"
            ]
        ]
    },
    {
        "id": "db9bd5da2b417c25",
        "type": "csv",
        "z": "1378ba83.90c825",
        "name": "",
        "sep": ",",
        "hdrin": false,
        "hdrout": "all",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "label",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 450,
        "y": 960,
        "wires": [
            [
                "fcf264a7e9715206",
                "4661fbad8601b1c4"
            ]
        ]
    },
    {
        "id": "b4e1c71defe23048",
        "type": "link in",
        "z": "1378ba83.90c825",
        "name": "Valeur choix1",
        "links": [
            "79e4d93ab0c66a1c"
        ],
        "x": 165,
        "y": 1380,
        "wires": [
            [
                "5a6587d2222c2220"
            ]
        ]
    },
    {
        "id": "f71362bbb83da4c9",
        "type": "link in",
        "z": "1378ba83.90c825",
        "name": "choix1",
        "links": [
            "16abf2150784fc77"
        ],
        "x": 165,
        "y": 1440,
        "wires": [
            [
                "5a6587d2222c2220"
            ]
        ]
    },
    {
        "id": "d0b9e76692aadad7",
        "type": "ui_button",
        "z": "1378ba83.90c825",
        "name": "",
        "group": "671cb6d0f0a7d1c7",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "envoyer",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "topic",
        "topicType": "msg",
        "x": 200,
        "y": 1220,
        "wires": [
            []
        ]
    },
    {
        "id": "5a6587d2222c2220",
        "type": "function",
        "z": "1378ba83.90c825",
        "name": "Adressage",
        "func": "table = [];\nadressage = [];\nvar num = msg.payload.S1; //Chiffre allant de 0 à 79\nvar val = msg.payload.B1; // booléen\n\nfor(i = 0; i<79 ; i++){\ntable[i] = 0 ;\n}\n\ntable[num] = val; //On assigne une valeur à l'adresse saisie\n\nif(num < 15){\n for(i = 0; i<16 ; i++){\n adressage[i] = table[i]; //It returns the whole table\n } \n \n}\n\nmsg.payload = adressage;\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 1400,
        "wires": [
            [
                "19f79ff39da8bb1b"
            ]
        ]
    },
    {
        "id": "6ee3aaf7d2238cc2",
        "type": "change",
        "z": "1378ba83.90c825",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "selected",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1200,
        "y": 500,
        "wires": [
            []
        ]
    },
    {
        "id": "e72aa291dd82fd34",
        "type": "change",
        "z": "1378ba83.90c825",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "selected",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 1280,
        "wires": [
            [
                "5a6587d2222c2220"
            ]
        ]
    },
    {
        "id": "b7b1f645eb9b83c0",
        "type": "join",
        "z": "1378ba83.90c825",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1010,
        "y": 500,
        "wires": [
            [
                "6ee3aaf7d2238cc2"
            ]
        ]
    },
    {
        "id": "7a1076f8bb47d19f",
        "type": "ui_dropdown",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "",
        "tooltip": "",
        "place": "Select option",
        "group": "846c632af12c3e74",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "S1",
        "topicType": "str",
        "className": "",
        "x": 860,
        "y": 780,
        "wires": [
            [
                "7007a963b3ae03c0"
            ]
        ]
    },
    {
        "id": "c9957cf08822b7a0",
        "type": "ui_switch",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "846c632af12c3e74",
        "order": 2,
        "width": "1",
        "height": "1",
        "passthru": true,
        "decouple": "false",
        "topic": "B1",
        "topicType": "str",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 850,
        "y": 720,
        "wires": [
            [
                "7007a963b3ae03c0"
            ]
        ]
    },
    {
        "id": "eeac4a72b9dc5d0e",
        "type": "change",
        "z": "1378ba83.90c825",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "selected",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1200,
        "y": 740,
        "wires": [
            []
        ]
    },
    {
        "id": "7007a963b3ae03c0",
        "type": "join",
        "z": "1378ba83.90c825",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1010,
        "y": 740,
        "wires": [
            [
                "eeac4a72b9dc5d0e"
            ]
        ]
    },
    {
        "id": "99de5655e7178068",
        "type": "ui_dropdown",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "",
        "tooltip": "",
        "place": "Select option",
        "group": "25e2db2699b87ee1",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "S1",
        "topicType": "str",
        "className": "",
        "x": 860,
        "y": 1040,
        "wires": [
            [
                "5676a3cd7ef5e23d"
            ]
        ]
    },
    {
        "id": "3dd6b08423eb1dd1",
        "type": "ui_switch",
        "z": "1378ba83.90c825",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "25e2db2699b87ee1",
        "order": 2,
        "width": "1",
        "height": "1",
        "passthru": true,
        "decouple": "false",
        "topic": "B1",
        "topicType": "str",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 850,
        "y": 980,
        "wires": [
            [
                "5676a3cd7ef5e23d"
            ]
        ]
    },
    {
        "id": "5fc121eeade2156a",
        "type": "change",
        "z": "1378ba83.90c825",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "selected",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1200,
        "y": 1000,
        "wires": [
            []
        ]
    },
    {
        "id": "5676a3cd7ef5e23d",
        "type": "join",
        "z": "1378ba83.90c825",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1010,
        "y": 1000,
        "wires": [
            [
                "5fc121eeade2156a"
            ]
        ]
    },
    {
        "id": "3ffeefaa5596a04c",
        "type": "debug",
        "z": "1378ba83.90c825",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 810,
        "y": 1400,
        "wires": []
    },
    {
        "id": "8d613ded2d4ecc2e",
        "type": "ui_button",
        "z": "1378ba83.90c825",
        "name": "",
        "group": "671cb6d0f0a7d1c7",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Valider",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "date",
        "topic": "topic",
        "topicType": "msg",
        "x": 190,
        "y": 1280,
        "wires": [
            [
                "e72aa291dd82fd34"
            ]
        ]
    },
    {
        "id": "19f79ff39da8bb1b",
        "type": "buffer-parser",
        "z": "1378ba83.90c825",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "item1",
                "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": 630,
        "y": 1400,
        "wires": [
            [
                "3ffeefaa5596a04c"
            ]
        ]
    },
    {
        "id": "671cb6d0f0a7d1c7",
        "type": "ui_group",
        "name": "Requête 1",
        "tab": "3f071cb9a3d49f7f",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "ac5f4946e8c230e7",
        "type": "ui_group",
        "name": "Initialisation des listes déroulantes",
        "tab": "3f071cb9a3d49f7f",
        "order": 4,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "846c632af12c3e74",
        "type": "ui_group",
        "name": "Requête 2",
        "tab": "3f071cb9a3d49f7f",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "25e2db2699b87ee1",
        "type": "ui_group",
        "name": "Requête 3",
        "tab": "3f071cb9a3d49f7f",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "3f071cb9a3d49f7f",
        "type": "ui_tab",
        "name": "COMPRESSEUR",
        "icon": "COMPRESSEUR",
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:23 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/8 "2022-05-08T15:23:46Z")

</div>

I'm inputing data from the dashboard as a number (0 or 1) and putting it inside a first array going from 0 to 79. Then from this array, I extract 16 numbers that i put inside another array to then convert it into an UINT16be  
(I don't know if It's clear)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:28 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/9 "2022-05-08T15:28:58Z")

</div>

Show me what the data in flow.selected looks like.

Better still, copy some actual input data (using the copy value button)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8b1ec40e896fdc450ad00f0e6695f26379715b4.png)

Then explain what that data should be.

e.g. if you show my flow.selected has [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] what should it look like before it goes to modbus?

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:29 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/10 "2022-05-08T15:29:14Z")

</div>

- The first problem might be that I'm inputing numbers in the array (wich are already integer if i'm not wrong), but than how do I feel up my first array with boolean numbers

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:31 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/11 "2022-05-08T15:31:04Z")

</div>

Here's how it looks like

{"S1":0,"B1":1}

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e2776f8ddd1c7941971c9f23df8e529bce0986b.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:32 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/12 "2022-05-08T15:32:08Z")

</div>

How do you expect to make 16 integers from 2 values?

Please explain exactly what you expect the output to be?

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:33 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/13 "2022-05-08T15:33:59Z")

</div>

I actually have 16, I'm making a drawing. It might be easier to understand

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:42 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/14 "2022-05-08T15:42:23Z")

</div>

First the person will select the value It wants (B1 = 1 or 0) and wich variable it want's to change (S1 going from 0 to 79) :

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/111c38e74f199c985366662e54fbdeacf80d7506.png)

When validated,  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/0519ab325b990e15a8df4a85cc2f0484080e0675.png)

I'm putting the value of B1 in an array at the adress S1:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66969ede372d760f236f772c5a7d94d5852c5e3a.png)

The last and missing part is the conversion.

And If you ask why a table of 79, It is because there's 79 variables that can be selected and modified.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:46 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/15 "2022-05-08T15:46:27Z")

</div>

ok, so how do you write to modbus - all 79 values at once? or upon value change + button press?

I dont understand where 16 comes into this?

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:49 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/16 "2022-05-08T15:49:40Z")

</div>

Depending on wich variable the person choose (line 15-17 on the last code pic) I will return a table of 16 that will be converted to UINT16be and after a button press will be sent to write to the holding register of a modbus server.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 15:56 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/17 "2022-05-08T15:56:55Z")

</div>

I am slowly extracting the necessary info from you and trying to peice this together.

correct me if any of this is wrong...

- User selects a parameter
- User sets a TRUE or FALSE (1 or 0)
- User "stores this" setting in flow memory
- Once user has entered all 16 values, you want to create a 1 WORD (16 bit) value from the 16 "bits" entered - then you write this to ModBus?

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 15:58 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/18 "2022-05-08T15:58:55Z")

</div>

No problem It's hard to understand when you're not the one coding.

He just enter one value but that's exactly It 👍

---

<div class="post-metadata">

**Author:** ![Theodros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/theodros/32/61068_2.png) [@Theodros](https://discourse.nodered.org/u/Theodros)\
**Post date:** [8 May 2022 16:00 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/19 "2022-05-08T16:00:06Z")

</div>

Thank you for taking your time with my problem

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2022 16:02 UTC](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370/20 "2022-05-08T16:02:21Z")

</div>

ok, nearly there.

If the user enters 1 for address 0 then that would make `{"S1":0,"B1":1}` right?

So what value do you want to write to ModBus? Why are you looping 16 times?

What might make it easier to see the bigger picture by providing a few examples.

e.g.

- user selects address 2 & enters 0, I would get `{"S1":2,"B1":0}` and would expect to write xxxx to ModBus at address yyyy?
- user selects address 15 & enters 1, I would get `{"S1":15,"B1":1}` and would expect to write xxxx to ModBus at address yyyy?

[Next page](https://discourse.nodered.org/t/converting-an-array-of-bytes-into-a-int16-to-write-in-a-modbus-server-holding-register/62370.md?page=2)
