Multiple reads / out is getting out of sync

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.

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

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

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=

1 Like