09.07.2026, 06:40
If you need to change the unit number dynamically then you should use scripts with a single write of multiple registers. The Modbus device might only handle a small number of parallel TCP connections which leads to communication issues.
Try logging the result of connect/write:
Try logging the result of connect/write:
Code:
mb = require('luamodbus').tcp()
mb:open('192.168.1.1', 502)
res, err = mb:connect()
if res then
res, err = mb:writeregisters(1, 2, 3)
if not res then
log('write failed', err)
end
else
log('connection failed', err)
end
mb:close()