Hi,
I'm trying to read a sequence of global variables and send a message for each of them.
This is my code:
var Reg = "FFFF"; // Address of Register, 16 bit
var RegH = "FF"; //MSB
var RegL = "FF"; //LSB
var Value = "FF"; //Value for Reg
var PL = ["FF","FF"]; //LSB, Value
for (let i = 1; i < 6; i++){
Reg = global.get('Reg'+i);
Value = global.get('Val'+i);
RegH = Reg.substring(0, 2);
//RegH =parseInt(RegH, 16);
RegL = Reg.substring(2, 4);
//RegL =parseInt(RegL, 16);
//Value =parseInt(Value, 16);
PL = [RegL,Value];
msg.pltable= ["MSB: "+RegH,"LSB: "+RegL,"Value: "+Value, i];
msg.command=RegH;
msg.payload = PL;
return msg;
}
The global variables are named Reg1...Reg5 and Val1...Val5. so I want to get Reg+i and Val+i globals and for each couple send a message.
The function send only the first couple Reg1, Val1 and stops.
The globals have data and if manual addressing i, the output message is formed with right values.
If "return msg;" is outside the for cycle, the function, obviously, sends the last (5th) couple.
Seems a very symple function but I can't find the mistake.