29.06.2022, 09:06
Hi,
I have LM5 with 202112 firmware. I need modbus TCP Slave function and i arranged my residence script like below. I tried with modbus PLC and with some free modbus tool for connection but i received an error like
"COMMUNICATION ERROR
No connection could be made because the target machine actively refused it 192.168.1.81:502 "
My PC IP 192.1681.70 and LM IP is 192.168.1.81 . Is there a problem with 202112 firmware or there is another problem with script ?
Regards
if not mb then
require('genohm-scada.eibdgm')
require('luamodbus')
-- list of coil mapping, starting from 0
coils = { '0/1/112', '0/7/112' }
-- list of register mapping, starting from 0
registers = { '30/1/1', '30/1/2' }
-- list of register data types, element count must match registers table
regdt = { dt.int8, dt.int8 }
-- knx group write callback
function knxgroupwrite(event)
local value
-- try to find matching coil
for id, addr in ipairs(coils) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, dt.bool)
mbetcoils(id - 1, value)
end
end
-- try to find matching register
for id, addr in ipairs(registers) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, regdt[ id ])
mbetregisters(id - 1, value)
end
end
end
-- coil write callback
function mbwritecoils(coil, value)
local addr = coils[ coil + 1 ]
if addr then
grp.write(addr, value, dt.bool)
end
end
-- register write callback
function mbwriteregisters(register, value)
local addr = registers[ register + 1 ]
if addr then
grp.write(addr, value, regdt[ register + 1])
end
end
-- knx group monitor, handles group writes
knxclient = eibdgm:new({ timeout = 0.1 })
knxclientethandler('groupwrite', knxgroupwrite)
-- modbus slave, listen on all interfaces and default port 502
mb = luamodbus.tcp()
mb:open('192.168.1.70', 502)
-- setting slave id is optional
-- mbetslave(1)
mbetreceivetimeout(0.1)
mbetmapping(#coils, 0, #registers, 0)
-- init coils
for id, addr in ipairs(coils) do
value = grp.getvalue(addr)
mbetcoils(id - 1, value)
end
-- init registers
for id, addr in ipairs(registers) do
value = grp.getvalue(addr)
mbetregisters(id - 1, value)
end
-- set callbacks for coil and register write
mbetwritecoilcb(mbwritecoils)
mbetwriteregistercb(mbwriteregisters)
end
-- handle modbus and knx
mb:handleslave()
knxclient:loop(0.1)
I have LM5 with 202112 firmware. I need modbus TCP Slave function and i arranged my residence script like below. I tried with modbus PLC and with some free modbus tool for connection but i received an error like
"COMMUNICATION ERROR
No connection could be made because the target machine actively refused it 192.168.1.81:502 "
My PC IP 192.1681.70 and LM IP is 192.168.1.81 . Is there a problem with 202112 firmware or there is another problem with script ?
Regards
if not mb then
require('genohm-scada.eibdgm')
require('luamodbus')
-- list of coil mapping, starting from 0
coils = { '0/1/112', '0/7/112' }
-- list of register mapping, starting from 0
registers = { '30/1/1', '30/1/2' }
-- list of register data types, element count must match registers table
regdt = { dt.int8, dt.int8 }
-- knx group write callback
function knxgroupwrite(event)
local value
-- try to find matching coil
for id, addr in ipairs(coils) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, dt.bool)
mbetcoils(id - 1, value)
end
end
-- try to find matching register
for id, addr in ipairs(registers) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, regdt[ id ])
mbetregisters(id - 1, value)
end
end
end
-- coil write callback
function mbwritecoils(coil, value)
local addr = coils[ coil + 1 ]
if addr then
grp.write(addr, value, dt.bool)
end
end
-- register write callback
function mbwriteregisters(register, value)
local addr = registers[ register + 1 ]
if addr then
grp.write(addr, value, regdt[ register + 1])
end
end
-- knx group monitor, handles group writes
knxclient = eibdgm:new({ timeout = 0.1 })
knxclientethandler('groupwrite', knxgroupwrite)
-- modbus slave, listen on all interfaces and default port 502
mb = luamodbus.tcp()
mb:open('192.168.1.70', 502)
-- setting slave id is optional
-- mbetslave(1)
mbetreceivetimeout(0.1)
mbetmapping(#coils, 0, #registers, 0)
-- init coils
for id, addr in ipairs(coils) do
value = grp.getvalue(addr)
mbetcoils(id - 1, value)
end
-- init registers
for id, addr in ipairs(registers) do
value = grp.getvalue(addr)
mbetregisters(id - 1, value)
end
-- set callbacks for coil and register write
mbetwritecoilcb(mbwritecoils)
mbetwriteregistercb(mbwriteregisters)
end
-- handle modbus and knx
mb:handleslave()
knxclient:loop(0.1)