# Simulating Multiple Modbus Slaves

**URL:** https://discourse.nodered.org/t/simulating-multiple-modbus-slaves/69214
**Category:** General
**Created:** [18 October 2022 18:27 UTC](https://discourse.nodered.org/t/simulating-multiple-modbus-slaves/69214 "2022-10-18T18:27:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vigalent](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vigalent/32/69263_2.png) [@vigalent](https://discourse.nodered.org/u/vigalent)
#### Post date: [18 October 2022 18:27 UTC](https://discourse.nodered.org/t/simulating-multiple-modbus-slaves/69214/1 "2022-10-18T18:27:37Z")

</div>

I'm working on a project whereby I'm using a IOT gateway monitoring multiple systems / sensors that runs an instance of Node-Red.

I'm pulling data back and exposing point values via ModbusTCP (using [node-red-contrib-modbus) to a 3rd party modbus master, but I need to write said data to multiple modbus slaves.

Using the flex write node and have the following code from 2 different functions attempting to write to 2 different slaves. But it seems the flex write is writing to both slaves despite the "unitid" being different in each function?

Does anyone know where I'm going wrong?

```auto
var coil = msg.payload;
msg.payload = {
    'value': coil,
    'fc': 5,
    'unitid': 1,
    'address': 1,
    'quantity': 1
}
return msg

```

and

```auto
var coil = msg.payload;
msg.payload = {
    'value': coil,
    'fc': 5,
    'unitid': 2,
    'address': 1,
    'quantity': 1
}
return msg

```

---

<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: [17 December 2022 18:28 UTC](https://discourse.nodered.org/t/simulating-multiple-modbus-slaves/69214/2 "2022-12-17T18:28:06Z")

</div>

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