int16 on modbus script - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10) +--- Thread: int16 on modbus script (/showthread.php?tid=4053) |
int16 on modbus script - CristianAgata - 22.05.2022 Hi everybody, I've a problem on a script. I'm tring to read a solar inverter ZCSAzzurro. I've problem on negative number. I've made this request: if (res9[2] == nil) then -- Chiamata potenza rete res10=nil res10 = { mb:readregisters(530,dt.int16) } grp.update('Potenza_rete',(res10[1])) log("Grind_power",res10) os.sleep(1.1) else --log("timeout!") mb:close() end But in the log I find the number 32767. But if try to make a read in the modbus scheduler I get -27 (right value) Where am I wronging? Thanks for who will help me. BR Cristian RE: int16 on modbus script - admin - 23.05.2022 Use this: Code: value = mb:readregistervalue(530, 'int16') RE: int16 on modbus script - CristianAgata - 23.05.2022 (23.05.2022, 05:30)admin Wrote: Use this: No, it doesn't work, it gives me an error of 'bad argument #2 ro readregisters (number expect, got string) Best regards Cristian RE: int16 on modbus script - admin - 23.05.2022 Use mb:readregistervalue not mb:readregisters. RE: int16 on modbus script - CristianAgata - 23.05.2022 (23.05.2022, 13:20)admin Wrote: Use mb:readregistervalue not mb:readregisters. Sorry RE: int16 on modbus script - admin - 23.05.2022 The function for reading data with a set data type is called readregistervalue. Just use this code as is: Code: value = mb:readregistervalue(530, 'int16') RE: int16 on modbus script - CristianAgata - 23.05.2022 Thanks man, now it works |