13.03.2023, 15:40
Hello Daniel,
I need to use the LM as modbus TCP slave and I'm trying to use the universal TCP script. The modbus master is the IP 192.168.2.108 and using the communication port 503, the LM is slave Id 3. I just need to write registers from 2002 to 2090 and read registers from 2102 to 2190. I've been trying just to read registers but I get a message error:
"Modbus Universal 13.03.2023 16:37:00
Resident script:6: Address not available
stack traceback:
[C]: in function 'assert'"
I need to use the LM as modbus TCP slave and I'm trying to use the universal TCP script. The modbus master is the IP 192.168.2.108 and using the communication port 503, the LM is slave Id 3. I just need to write registers from 2002 to 2090 and read registers from 2102 to 2190. I've been trying just to read registers but I get a message error:
"Modbus Universal 13.03.2023 16:37:00
Resident script:6: Address not available
stack traceback:
[C]: in function 'assert'"
Code:
local mb = require('user.mbtcp')
local copas = require('copas')
local socket = require('socket')
local address = '192.168.2.108'
local port = 503
local server = assert(socket.bind(address, port))
mb.setmapping({
['3'] = {
coils = {
},
registers = {
[2104] = '32/5/4',
[2105] = '32/5/5',
[2106] = '32/5/6',
[2107] = '32/5/7',
}
}
})
mb.setswap('w')
mb.setfloat16precision(2)
local function handler(sock)
copas.setErrorHandler(function(msg)
if msg ~= nil then
log(msg)
end
end)
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()