# Write data into modbus server

**URL:** <https://discourse.nodered.org/t/write-data-into-modbus-server/85809>\
**Category:** General\
**Created:** [23 February 2024 12:44 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809 "2024-02-23T12:44:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRABHAKAR82](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PRABHAKAR82](https://discourse.nodered.org/u/PRABHAKAR82)\
**Post date:** [23 February 2024 12:44 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/1 "2024-02-23T12:44:20Z")

</div>

```auto
[
    {
        "id": "d957bb780997c872",
        "type": "modbus-write",
        "z": "7568dacddffb4c49",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "1",
        "dataType": "MHoldingRegisters",
        "adr": "1",
        "quantity": "125",
        "server": "3831b0d8d7adf795",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 300,
        "y": 740,
        "wires": [
            [
                "5e1212b9e016eec8"
            ],
            []
        ]
    },
    {
        "id": "d57eedf18e3284b4",
        "type": "inject",
        "z": "7568dacddffb4c49",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[127,136,216,101,31,31,31,35,35,35,215,215,215,20,20,20,0,0,0,0,0,0,0,0,0,10,10,10,3,3,3,3,3,3,65,65,65,81,0,0,0,0,0,0,0,0,0,0,0,87,136,216,101,33,33,33,39,39,39,215,215,215,20,20,20,0,0,0,0,0,0,0,0,0,6,6,6,10,10,10,6,6,6,69,69,69,96,0,0,0,0,0,0,0,0,0,0,0,99,99,99,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9]",
        "payloadType": "json",
        "x": 130,
        "y": 740,
        "wires": [
            [
                "d957bb780997c872",
                "1f4d3f3b3138b69c"
            ]
        ]
    },
    {
        "id": "5e1212b9e016eec8",
        "type": "modbus-flex-server",
        "z": "7568dacddffb4c49",
        "name": "",
        "logEnabled": false,
        "serverAddress": "192.168.0.114",
        "serverPort": "1025",
        "responseDelay": 100,
        "unitId": 1,
        "delayUnit": "ms",
        "coilsBufferSize": 20000,
        "registersBufferSize": 20000,
        "minAddress": 0,
        "splitAddress": 10000,
        "funcGetCoil": "function getFlexCoil(addr, unitID) {\n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\treturn node.coils.readUInt8(addr * node.bufferFactor) \n\t} \n}",
        "funcGetDiscreteInput": "function getFlexDiscreteInput(addr, unitID) {\n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.coils.readUInt8(addr * node.bufferFactor) \n\t} \n}",
        "funcGetInputRegister": "function getFlexInputRegister(addr, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor) \n\t} \n}",
        "funcGetHoldingRegister": "function getFlexHoldingRegsiter(addr, unitID) { \n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor) \n\t} \n}",
        "funcSetCoil": "function setFlexCoil(addr, value, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\tnode.coils.writeUInt8(value, addr * node.bufferFactor) \n\t} \n}",
        "funcSetRegister": "function setFlexRegister(addr, value, unitID) { \n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\tnode.registers.writeUInt16BE(value, addr * node.bufferFactor) \n\t} \n}",
        "showErrors": false,
        "x": 540,
        "y": 740,
        "wires": [
            [],
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "1f4d3f3b3138b69c",
        "type": "debug",
        "z": "7568dacddffb4c49",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 820,
        "wires": []
    },
    {
        "id": "3831b0d8d7adf795",
        "type": "modbus-client",
        "name": "",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.0.114",
        "tcpPort": "1025",
        "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
    }
]

```

I write 125 tag data successfully into holding register, but if I increase array size data is not written on Modbus server. Is it possible to write 1000 length array data into Modbus server.

datatype-INT

---

<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:** [23 February 2024 12:58 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/2 "2024-02-23T12:58:56Z")

</div>

> [@PRABHAKAR82](#):
>
> Is it possible to write 1000 length array data into Modbus server

No. the protocol structure can only fit a certain number of values into a transmission. If you inspect the protocol, you will see it uses a `byte` to specify the "byte count" in message. Since each WD is 2 bytes, the maximum number of WDs a transmission can have is 255/2 (rounded down that is 127) but then there is other data in a packet. Some say the max length is 123 some say 125. Different implementations of the protocol set limits, some don't.

In short, you will have to do multiple transmissions.

I suggest, for easy maintenance of flows, you group them into a size of 100 WDs.

* * *

All that said, the modbus-server node itself _may_ permit an alterative means of initialising the internal memory areas of the server node (i.e. not using the modbus protocol) but i dont know.

---

<div class="post-metadata">

**Author:** ![PRABHAKAR82](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PRABHAKAR82](https://discourse.nodered.org/u/PRABHAKAR82)\
**Post date:** [23 February 2024 13:06 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/4 "2024-02-23T13:06:07Z")

</div>

Could you please give me example? this will help us.

---

<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:** [23 February 2024 13:07 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/5 "2024-02-23T13:07:38Z")

</div>

> [@PRABHAKAR82](#):
>
> Could you please give me example?

An example of what?

this ↓

> [@Steve-Mcl](#):
>
> I suggest, for easy maintenance of flows, you group them into a size of 100 WDs

or this ↓

> [@Steve-Mcl](#):
>
> All that said, the modbus-server node itself _may_ permit an alterative means of initialising the internal memory areas of the server node (i.e. not using the modbus protocol) but i dont know

---

<div class="post-metadata">

**Author:** ![PRABHAKAR82](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PRABHAKAR82](https://discourse.nodered.org/u/PRABHAKAR82)\
**Post date:** [23 February 2024 13:09 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/6 "2024-02-23T13:09:41Z")

</div>

> [@Steve-Mcl](#):
>
> I suggest, for easy maintenance of flows, you group them into a size of 100 WDs

for this.if you have any example

---

<div class="post-metadata">

**Author:** ![PRABHAKAR82](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PRABHAKAR82](https://discourse.nodered.org/u/PRABHAKAR82)\
**Post date:** [23 February 2024 13:12 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/7 "2024-02-23T13:12:24Z")

</div>

whatever method is used, my aim is to write 1000 tag data into 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:** [23 February 2024 13:12 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/8 "2024-02-23T13:12:45Z")

</div>

um, sure. but it is pretty much taking what you have already and doing it 10 times!

I dont have modbus nodes installed ATM and I dont have your data so here is a mock up...

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

I suggest, like I did in the picture ↑, you do these in series (not in parallel) to avoid congestion and timeouts.

---

<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:** [23 May 2024 13:13 UTC](https://discourse.nodered.org/t/write-data-into-modbus-server/85809/9 "2024-05-23T13:13:06Z")

</div>

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