This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HomeLynk as Modbus TCP/IP slave
#8
I have a problem with the script..
I have 2 LM:
LM1 is the one with this script https://openrb.com/lm-as-modbus-tcp-slave
LM2 is the one that need to read LM1

When I try to read with LM1 my LM2, LM2 return tis error:  LM (TCP 192.168.1.91:502) read failed: Illegal data address

The profile in LM2 is this:

Code:
{ "manufacturer":"LM", "description":"LM", "mapping":[ {"name":"Reg1", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 0, "writable": true}, {"name":"Reg2", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 1, "writable": true}, {"name":"Reg3", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 2, "writable": true}, {"name":"Reg4", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 3, "writable": true}, {"name":"Reg5", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 4, "writable": true}, {"name":"Reg6", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 5, "writable": true}, {"name":"Reg7", "bus_datatype": "int16", "datatype": "uint16", "type": "register", "address": 6, "writable": true} ] }
and the script in LM1 is:
Code:
if not mb then   require('genohm-scada.eibdgm')   require('luamodbus')   -- Elenco mappature bobine, a partire da 0   coils = { '1/1/1' }   -- Elenco mappature dei registri, a partire da 0   registers = { "1/2/0", "1/2/3", "1/2/4", "1/2/9", "1/2/14", "1/2/16", "33/0/1" }   -- Elenco tipo di dati del registro, il conteggio degli elementi deve corrispondere alla tabela dei registri   regdt = { dt.uint16, dt.uint16, dt.uint16, dt.uint16, dt.uint16, dt.uint16, dt.uint16 }   -- Richiamo in scrittura del gr. KNX   function knxgroupwrite(event)     local value     -- Prova a trovare la bobona corrispondente     for id, addr in ipairs(coils) do       if event.dst == addr then         value = knxdatatype.decode(event.datahex, dt.bool)         mb:setcoils(id - 1, value)       end     end     -- Prova a trovare il registro corrispondente     for id, addr in ipairs(registers) do       if event.dst == addr then         value = knxdatatype.decode(event.datahex, regdt[ id ])         mb:setregisters(id - 1, value)       end     end   end   -- richiama bobina in scrittura   function mbwritecoils(coil, value)     local addr = coils[ coil + 1 ]     if addr then       grp.write(addr, value, dt.bool)     end   end   -- registra la chiamata in scrittura   function mbwriteregisters(register, value)     local addr = registers[ register + 1 ]     if addr then       grp.write(addr, value, regdt[ register + 1])     end   end   -- knx group monitor, gestisce le scritture di gruppo   knxclient = eibdgm:new({ timeout = 0.1 })   knxclient:sethandler('groupwrite', knxgroupwrite)   -- modbus slave, ascolta su tutte le interfaccie e porte default 502   mb = luamodbus.tcp()   mb:open('0.0.0.0', 502)   -- Impostazione Slave (Facoltativa)   --mb:setslave(1)   mb:setreceivetimeout(0.1)   mb:setmapping(#coils, 0, #registers, 0)   -- Inizializza bobine   for id, addr in ipairs(coils) do     value = grp.getvalue(addr)     mb:setcoils(id - 1, value)   end   -- Inizializza registri   for id, addr in ipairs(registers) do     value = grp.getvalue(addr)     mb:setregisters(id - 1, value)   end   -- set callbacks for coil and register write   mb:setwritecoilcb(mbwritecoils)   mb:setwriteregistercb(mbwriteregisters) end -- Gestione modbus e KNX mb:handleslave() knxclient:step()
can someone help me?
Reply


Messages In This Thread
HomeLynk as Modbus TCP/IP slave - by permar - 19.03.2019, 12:35
RE: HomeLynk as Modbus TCP/IP slave - by Mirco - 17.09.2020, 08:32

Forum Jump: