10.10.2025, 18:34
HI,
what is the max amount of register I can map on LM as modbus slave?
what is the max amount of register I can map on LM as modbus slave?
Code:
local mb = require('user.mbslave')
local copas = require('copas')
local socket = require('socket')
local address = '*'
local port = 502
local server = assert(socket.bind(address, port))
mb.setswap('w')
mb.setfloat16precision(2)
mb.setmapping({
['*'] = {
coils = {
[0] = '0/0/1',
[1] = '0/0/3',
[2] = '0/0/4',
},
discreteinputs = {
[0] = '1/0/1',
[1] = '1/0/3',
[2] = '1/0/4',
},
registers = {
[0] = '1/1/4',
[1] = '1/1/10',
[3] = '32/1/6',
[5] = '32/1/13',
},
inputregisters = {
[0] = '2/1/4',
[1] = '2/1/10',
}
}
})
local function handler(sock)
copas.setErrorHandler(log)
sock = copas.wrap(sock)
sock:settimeout(60)
while true do
local res, err = mb.tcphandler(sock)
if not res then
break
end
end
sock:close()
end
copas.addserver(server, handler, 60)
copas.loop()