# Multiple reads / out is getting out of sync

**URL:** <https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304>\
**Category:** General\
**Created:** [24 September 2020 17:42 UTC](https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304 "2020-09-24T17:42:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmoel](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bmoel](https://discourse.nodered.org/u/bmoel)\
**Post date:** [24 September 2020 17:42 UTC](https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304/1 "2020-09-24T17:42:05Z")

</div>

Hi,

I'm trying to find a good way to use the ModBus flex getter to read multiple registers and store the returned values in variables. I use the a function node and the following syntax to read the ModBus registers I need. The only way I could find to organize. I then use a split node (split into single vlaus and join them again into one array using the indeks when assigning a specific values to a variable.

Somehow it works most of the time, but then suddenly the order is not right anymore e.g. all values are shifted one or more positions, as if the send.msg is not done in the right order.

var msg1 = {payload:{'fc': 3, 'unitid': 1, 'address': 20120,'quantity': 1}};  
var msg2 = {payload:{ 'fc': 3, 'unitid': 1, 'address': 21770 , 'quantity': 27}};  
var msg3 = {payload:{ 'fc': 3, 'unitid': 1, 'address': 20101 , 'quantity': 1}};  
var msg4 = {payload:{ 'fc': 3, 'unitid': 1, 'address': 20260 , 'quantity': 1}};  
var msg5 = {payload:{ 'fc': 3, 'unitid': 1, 'address': 20148, 'quantity': 1}};  
var msg6 = {payload:{ 'fc': 4, 'unitid': 1, 'address': 5432 , 'quantity': 1}};  
node.send (msg1);  
node.send (msg2);  
node.send (msg3);  
node.send (msg4);  
node.send (msg5);  
node.send (msg6);

after the flex getter I then split - join all into on arrays and assign the read values to variables.

var readarray2= msg.payload;  
//  
global.set("OM",readarray2[0]); // Operating Mode  
global.set("SS",readarray2[1]); // System State  
global.set("SFS",readarray2[2]); // Inlet fan current %  
global.set("EFS",readarray2[3]); // Extract fan current %  
global.set("BP",readarray2[4]); // Bypass  
global.set("AH",readarray2[5]); // afterheating in %  
global.set("CS",readarray2[6]); // Compressor 0=OFF 100=ON  
global.set("RH",readarray2[7]); // Average air humidity  
global.set("PH",readarray2[8]); // Preheating in %  
global.set("BES",readarray2[19]); // Boiler Electric supply  
global.set("Alarm",readarray2[23]); // Boiler Electric supply  
global.set("Vpause",readarray2[28]); // Ventilation 0=OFF 1=ON  
global.set("Tset",readarray2[29]/10); // Temp user setpoint  
global.set("Fset",readarray2[30]-=100); // Fan user set 1,2,3,4  
global.set("Rmode",readarray2[31]); // Current regulation mode

Is this a good practice using the flex getter i or could you suggest me a better way to the read and assigned rad values to variables.

Thank you very much in advance.

---

<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:** [24 September 2020 19:33 UTC](https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304/2 "2020-09-24T19:33:53Z")

</div>

Hi ..  
maybe you are trying to read too fast ?  
In the Modbus Flex Getter device configuration can you try to increase the Queue delay ?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/99c886e920f6471dd11694563455e278b2f104de.png)

Also you may use the Modbus Queue Info node to monitor the queued messages. You dont need to wire this node to anyware .. but simply configure it to monitor your device.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77536c88b8228f69c09aa71e20d033b67b149f0d.png)

---

<div class="post-metadata">

**Author:** ![bmoel](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bmoel](https://discourse.nodered.org/u/bmoel)\
**Post date:** [27 September 2020 08:45 UTC](https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304/3 "2020-09-27T08:45:33Z")

</div>

Thanks for tip UnnorN. I found a way to deal with it. It might be a bit clunky, but it works flawless and until now I have not seen any errors in terms of missing reading or shifted values. I assigned a topic to each message and use the switch node and the assigned topic to make sure that the respective readings goes to the right output.

var msg1 = {payload:{'fc': 4, 'unitid': 1, 'address': 20280, 'quantity': 20}};  
var msg2 = {payload:{'fc': 4, 'unitid': 1, 'address': 20520, 'quantity': 4}};  
var msg3 = {payload:{'fc': 3, 'unitid': 1, 'address': 20440, 'quantity': 1}};  
var msg4 = {payload:{'fc': 4, 'unitid': 1, 'address': 22490, 'quantity': 1}};  
msg1.topic="msg1";  
msg2.topic="msg2";  
msg3.topic="msg3";  
msg4.topic="msg4";  
node.send (msg1);  
node.send (msg2);  
node.send (msg3);  
node.send (msg4);

and in the switch node I just identify the message and direct them to the right output using msg.topic=

---

<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:** [26 November 2020 08:45 UTC](https://discourse.nodered.org/t/multiple-reads-out-is-getting-out-of-sync/33304/4 "2020-11-26T08:45:37Z")

</div>

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