28.03.2025, 11:13
When trying to implement communication with this device I always get the error "Bad file descriptor".
This LM uses both Modbus RTU ports with a different configuration.
This is the RTU port configuration:
This LM uses both Modbus RTU ports with a different configuration.
Code:
require('luamodbus')
buffer = {}
function logger(c)
table.insert(buffer, c)
end
local mb2 = luamodbus.rtu()
mb2:open('/dev/rs485-2', 19200, 'E', 8, 1, 'H')
mb2:connect()
mb2:setslave(1)
mb2:setdebug(logger)
values,err=mb2:writereadregisters(0,6,12,0x0A,0x1AE0F,0x0,0x1)
log(table.concat(buffer))
mb2:close()
This is the RTU port configuration: