31.10.2024, 10:42
Try using writemultipleregisters (function code 16):
If your script is a resident then your original code will only work once because the connection is closed after the first write and since mb variable is still defined new connection won't be open.
If you want to share RTU connection between multiple scripts you should either create a profile or use mbproxy: https://forum.logicmachine.net/showthrea...7#pid22637
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
mb:connect()
--writing 10 into register 168
res, err = mb:writemultipleregisters(168, 10)
log(res, err)
mb:close()
If your script is a resident then your original code will only work once because the connection is closed after the first write and since mb variable is still defined new connection won't be open.
If you want to share RTU connection between multiple scripts you should either create a profile or use mbproxy: https://forum.logicmachine.net/showthrea...7#pid22637