# Modbus flow for multiple reads

**URL:** <https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577>\
**Category:** General\
**Created:** [2 February 2023 02:52 UTC](https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577 "2023-02-02T02:52:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [2 February 2023 02:52 UTC](https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577/1 "2023-02-02T02:52:22Z")

</div>

There are numerous posts regarding this topic, but none of them are specific to my question.

I need to talk to 36 inverters. I'm using node-red-contrib-modbus 5.25.0, serial RTU.  
In order to perform a good flow and queue messages, I'm using Modbus-Flex-Getter node.

My basic approach is:

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

If an inverter is off-line, I catch it and set a flag for off-line.

However, I still need to specify different function nodes for each id. Is it possible to make an array of objects?

I can't get it to work:

```auto
msg.payload = [];

msg.payload[0] = { 
    value: msg.payload, 
    'fc': _fc, 
    'unitid': 1, 
    'address': _PXXXX,
    'quantity': _qty 
    };

msg.payload[1] = {
    value: msg.payload,
    'fc': _fc,
    'unitid': 2,
    'address': _PXXXX,
    'quantity': _qty
};

```

Besides, after checking that the inverter is off-line, is there a way to change the pooling rate dynamic?  
For exempla: I check speed every 500ms. But since I get the first off-line message from the inverter, I can way 5s to test it again.

---

<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:** [4 February 2023 13:38 UTC](https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577/2 "2023-02-04T13:38:49Z")

</div>

> [@thalesmaoa](#):
>
> Is it possible to make an array of objects?

Hello .. this is my approach using an array of objects for the **Modbus-Flex-Sequencer**

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

**Flow :**

[flows.json](https://discourse.nodered.org/uploads/short-url/f7l9hXkm23ZeRVn6cpzymLTBn3e.json) (35.2 KB)

1. Initially i create a global Context **mbConfig** variable that holds the modbus configuration of how the reply of each modbus request will be translated by the buffer parser node.
2. In **sequences** function i create the array configuration for each modbus request (used by **Modbus-Flex-Sequencer** )
3. Handle errors with the **error** function which basically fills context with null values for any offline devices
4. setGlobal function updates **mbValues** global Context with valid values

> [@thalesmaoa](#):
>
> is there a way to change the pooling rate dynamic?

I dont think there is an easy way of doing this as the delay settings are in the Modbus client config node  
and cannot be independently set for each request.

Hope it helps

---

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [5 February 2023 18:19 UTC](https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577/3 "2023-02-05T18:19:41Z")

</div>

You have no idea how much. Thanks a lot. You gave me a lot of ideas.

Here is my approach:

1. Define a global node using JSON:  

2. Queue the messages an serialize them:  

3. Catch the messages with no response and set an increment before trying again:  

If the message is catch, it will noot pass queue until it fills an iteration.

Thanks a lot

---

<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:** [19 February 2023 18:20 UTC](https://discourse.nodered.org/t/modbus-flow-for-multiple-reads/74577/4 "2023-02-19T18:20:25Z")

</div>

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