12.09.2022, 06:07
This example will create Modbus TCP slave on port 502. It will log all requests/responses.
Code:
require('luamodbus')
mb = luamodbus.tcp()
mb:open('0.0.0.0', 502)
mb:setmapping(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF)
debug = {}
mb:setdebug(function(ch)
debug[ #debug + 1 ] = ch
end)
while true do
mb:handleslave()
if #debug > 0 then
log(table.concat(debug))
debug = {}
end
end