LogicMachine Forum
Modbus 8bit low and high - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Modbus 8bit low and high (/showthread.php?tid=3216)



Modbus 8bit low and high - toujour - 11.03.2021

Hi,

how can I create a profile (or a Script ) to read and write this modbus word (Register 21) ?




BR,
Alberto


RE: Modbus 8bit low and high - Daniel - 12.03.2021

Try this, you may need to subtract -1 from the register.
Code:
if not mb then require('luamodbus') mb = luamodbus.rtu() mb:open('/dev/RS485', 9600, 'E', 8, 1, 'H') mb:connect() end mb:setslave(1) value = mb:readregisters(21) address = bit.rshift(value, 8) baudrate = value-address*256 log(address,baudrate) newaddress = 2 newbaudrate = 1 reg=newaddress*256 + newbaudrate mb:writeregisters(21, reg)