mb:setregisters() and LM values - 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: mb:setregisters() and LM values (/showthread.php?tid=4179) |
mb:setregisters() and LM values - SigmaTec - 08.08.2022 Hi all, I think I have figured out the method to read a register and write its value to an LM object -------------------------------------------------- --------------------------- result_5, result_6, result_7, result_8 = mb:readregisters(3203, 4) if result_5 then value5 = bit.lshift(result_5, 48) + bit.lshift(result_6, 32) + bit.lshift(result_7, 16) + result_8 ../.. end -------------------------------------------------- --------------------------- But could you explain to me how to do the opposite with the method "mbetregisters(register,value)" from values of LM objects like Uint8, Float32 and Int64? Thank you in advance for your assistance and have a good week. RE: mb:setregisters() and LM values - admin - 08.08.2022 See this: https://forum.logicmachine.net/showthread.php?tid=181&pid=833#pid833 RE: mb:setregisters() and LM values - SigmaTec - 08.08.2022 So, is this correct to write an INT64 into 4 registers? value = event.getvalue() raw = knxdatatype.encode(value, dt.float32).dataraw r1 = raw:byte(1) r2 = raw:byte(2) r3 = raw:byte(3) r4 = raw:byte(4) register = 3204 mbetregisters(register, r4) mbetregisters(register+1, r3) mbetregisters(register+2, r2) mbetregisters(register+3, r1) RE: mb:setregisters() and LM values - admin - 08.08.2022 You won't have event.getvalue() in a resident script. encode call should have correct data type set as the second argument. Code: value = grp.getvalue('32/1/1') RE: mb:setregisters() and LM values - SigmaTec - 08.08.2022 Thank's ! Trying your code with à 12.4 LM object (value = 12345678) I obtain this (writed in log) string: r4 : 24910 | r3 : 188 | r2 : 0 | r1 : 0 string: Value : 12345678 Readed as 106987647664.13 by the Modbus master !!! RE: mb:setregisters() and LM values - admin - 08.08.2022 Modbus does not define word/byte order so there are 4 different ways of encoding an int64 value. Try this: Code: value = grp.getvalue('32/1/1') And this: Code: value = grp.getvalue('32/1/1') RE: mb:setregisters() and LM values - SigmaTec - 08.08.2022 Perfect Admin, the second was the good one ! Thank you for your help, the speed of your answers and your professionalism. |