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.