# Multiple Modbus RTU Slaves causes error

**URL:** <https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783>\
**Category:** Industrial\
**Created:** [4 December 2019 10:12 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783 "2019-12-04T10:12:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [4 December 2019 10:12 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/1 "2019-12-04T10:12:21Z")

</div>

Hi all,

I'm using the[node-red-contrib-modbus](https://flows.nodered.org/node/node-red-contrib-modbus) node, with two slave devices with addresses 1 and 101. Both have the same settings, for RTU-BUFFERED:

Baud rate: 9600  
Data bits: 8  
Stop bits: 1  
Parity: None

I've confirmed that there are no wiring issues and all comms are good. I'm having an issue where setting up 'modbus-read' nodes for both only works if I have one slave set up. Enabling both causes one of them to fail to work.

The test case is as follows:

Two node-red tabs, one with this flow for slave 101 (using a flex getter here but the same happens with a normal modbus-read node):  
 ![50](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/79861280d2da7d44db2cd2113bad681e13fff974.png)

and the other for slave 1:

![11](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7b9f95f6620affa164e8b438c0ed7e21c4a32d63.png)

If I enable both tabs, slave 1 will communicate properly and slave 101 won't (it gets stuck in a loop of 'initialize -\> reconnecting after 2000 msec'). This happens at random - sometimes slave 1 works and slave 101 doesn't, sometimes the other way around. However if I disable one tab, the other modbus-read works fine. So the issue seems to be that only one device can be enabled and read throughout the whole node-red configuration.

As far as I'm aware, this should all be within the modbus RTU stack, as it's simply two slave devices on the same network with the same configuration and different addresses, so not sure of the problem here? I'm hesitant to create an 'issue' on the node-red-contrib-modbus GitHub page until confirm that this is actually a bug.

Here's an export of each flow pictured above:

```auto
[
    {
        "id": "94bb33c0.333ee",
        "type": "modbus-getter",
        "z": "b99ef0d6.d646d8",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "",
        "dataType": "HoldingRegister",
        "adr": "14",
        "quantity": "1",
        "server": "bf70619e.04833",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 300,
        "y": 80,
        "wires": [
            [
                "3c22e6a6.2a0e62"
            ],
            [
                "3c22e6a6.2a0e62"
            ]
        ]
    },
    {
        "id": "ba58a969.c0be08",
        "type": "inject",
        "z": "b99ef0d6.d646d8",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 100,
        "y": 80,
        "wires": [
            [
                "94bb33c0.333ee"
            ]
        ]
    },
    {
        "id": "3c22e6a6.2a0e62",
        "type": "debug",
        "z": "b99ef0d6.d646d8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 540,
        "y": 80,
        "wires": []
    },
    {
        "id": "bf70619e.04833",
        "type": "modbus-client",
        "z": "",
        "name": "Calex Addr",
        "clienttype": "serial",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "tcpHost": "127.0.0.1",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB0",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": 101,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectTimeout": 2000
    }
]

```

```auto
[
    {
        "id": "671858a1.3b5c48",
        "type": "modbus-read",
        "z": "7fed931b.b8862c",
        "name": "Meter L1 Volts",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "unitid": "",
        "dataType": "HoldingRegister",
        "adr": "768",
        "quantity": "1",
        "rate": "15",
        "rateUnit": "m",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "bc1028d0.8535f8",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 130,
        "y": 220,
        "wires": [
            [
                "3d3a6730.138c08",
                "2a504cb9.1e0a44"
            ],
            []
        ]
    },
    {
        "id": "3d3a6730.138c08",
        "type": "debug",
        "z": "7fed931b.b8862c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 150,
        "y": 160,
        "wires": []
    },
    {
        "id": "bc1028d0.8535f8",
        "type": "modbus-client",
        "z": "",
        "name": "ND Multi Display Module",
        "clienttype": "serial",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "tcpHost": "127.0.0.1",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB0",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectTimeout": 2000
    }
]

```

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [4 December 2019 11:45 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/2 "2019-12-04T11:45:20Z")

</div>

I've done some further digging and it looks like my issue is identical to this:

> <https://github.com/BiancoRoyal/node-red-contrib-modbus/issues/145>
>
> Hi, I'm working on a IIOT demostration module and using a Raspberry Pi 3+ for running Node-Red, I already communicated with...

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [4 December 2019 11:52 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/3 "2019-12-04T11:52:59Z")

</div>

Also this:

> <https://github.com/BiancoRoyal/node-red-contrib-modbus/issues/125>
>
> I'm submitting a ... (check one with "x")
> Feature
> ( x) feature request
> What is the motivation / use case for changing the behavior?
> The...

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [5 December 2019 08:24 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/4 "2019-12-05T08:24:54Z")

</div>

Ok...so it looks like there's a fundamental flaw in the node-red-contrib-modbus node whereby you can only set up and communicate with one Modbus RTU slave per serial port, which defeats the object of Modbus...investigating further.

It seems like the contributor is away, however this is such a major issue.

---

<div class="post-metadata">

**Author:** ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)\
**Post date:** [5 December 2019 08:59 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/5 "2019-12-05T08:59:52Z")

</div>

When dealing with Modbus RTU, see to it that the communication traffic should be consider. When Master is trying to poll data from Slave 1, the master should dedicate its connection to the Slave 1, the same thing to slave 2. WIth modbus RTU, only 1 slave can be connected at a time. Maybe with your settings, there is a collision of data where the Master is trying to communicate on Both Slaves at the same time. Try to change their Polling rate.

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [5 December 2019 09:27 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/6 "2019-12-05T09:27:59Z")

</div>

I've tried this using the `node-red-contrib-serial-modbus` node, with success. This proves that the hardware setup is correct and that multiple serial slaves can be interfaced with, as per the modbus spec. I can't use this node for my setup however as it gives no ability to tune timeouts, reconnects etc, hence my dependancy on `node-red-contrib-modbus`.

Using `node-red-contrib-modbus` I have also set up two slaves with different polling times (6 seconds and 8 seconds), with the first having a 'delay on start' of 1 second, therefore their rates should not interfere. This still doesn't work as the node tries to initialise both slaves at the same time, causing the collision issue.

FYI - proper buffering of messages to be sent over a resource-constraint serial connection sits well within the modbus spec.

---

<div class="post-metadata">

**Author:** ![bianco-royal](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bianco-royal](https://discourse.nodered.org/u/bianco-royal)\
**Post date:** [5 December 2019 09:29 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/7 "2019-12-05T09:29:18Z")

</div>

Feel free to contribute if are able to test!

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [5 December 2019 09:31 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/8 "2019-12-05T09:31:45Z")

</div>

Hi @bianco-royal - awesome to hear from you 🙂 I'm just working my way through the codebase. I'm not a native javascript developer so it's not second nature to me, so may struggle to improve. It looks like there's a need to initialise and queue based on the server being used, opposed to the slave address of each modbus device.

I am definitely able to test. I have a test rig setup with 2 modbus slaves, but also have a larger remote setup with 10 slaves, all on a single serial port.

---

<div class="post-metadata">

**Author:** ![bianco-royal](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bianco-royal](https://discourse.nodered.org/u/bianco-royal)\
**Post date:** [5 December 2019 09:33 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/9 "2019-12-05T09:33:02Z")

</div>

I could build a pre-release with some ideas to fix it and you could test it.(?)

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [5 December 2019 09:33 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/10 "2019-12-05T09:33:50Z")

</div>

I'd be more than happy to do this @bianco-royal - would you like to continue the comms here or shall I open a new issue on GitHub where the both of us can track better?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![bianco-royal](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bianco-royal](https://discourse.nodered.org/u/bianco-royal)\
**Post date:** [5 December 2019 09:34 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/11 "2019-12-05T09:34:52Z")

</div>

Please, open an issue for that with reference to this!

---

<div class="post-metadata">

**Author:** ![joearkay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joearkay/32/1442_2.png) [@joearkay](https://discourse.nodered.org/u/joearkay)\
**Post date:** [5 December 2019 09:46 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/12 "2019-12-05T09:46:33Z")

</div>

@bianco-royal: [https://github.com/BiancoRoyal/node-red-contrib-modbus/issues/161](https://github.com/BiancoRoyal/node-red-contrib-modbus/issues/161)

---

<div class="post-metadata">

**Author:** ![Hasitha\_Sudasinghe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hasitha_sudasinghe/32/22710_2.png) [@Hasitha\_Sudasinghe](https://discourse.nodered.org/u/Hasitha_Sudasinghe)\
**Post date:** [25 May 2020 07:40 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/13 "2020-05-25T07:40:49Z")

</div>

Can you please help me with my case?

> [@Modbus RS485 to USB communication](https://discourse.nodered.org/t/modbus-rs485-to-usb-communication/27074):
>
> Im trying to communicate Schneider PM1200 energy meter with Node red. There i have used Brainbox US-324 RS485 to USB converter and i have successfully check my path via modscan. As per Schneider data sheet i want to read 3709 Float holding register to Node red. I have tried my best to do that and still i could not be able to do what i want to do. Can anyone here help me please. I will add my project below. Baud rate= 19.2K ,Parity = Even , Device ID = 1, Com port = 3 Thank you. [{"id":"2da7…

---

<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:** [24 July 2020 07:40 UTC](https://discourse.nodered.org/t/multiple-modbus-rtu-slaves-causes-error/18783/14 "2020-07-24T07:40:52Z")

</div>

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