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
#11
I just tried it like this and it works fine.
Code:
if not mb then   require('genohm-scada.eibdgm')   require('luamodbus')   -- Elenco mappature bobine, a partire da 0   coils = { '32/1/23' }   -- Elenco mappature dei registri, a partire da 0   registers = { "32/1/21", "32/1/22" }   -- Elenco tipo di dati del registro, il conteggio degli elementi deve corrispondere alla tabela dei registri   regdt = { 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()
profile
Code:
{   "manufacturer": "Embedded Systems",   "description": "LM11",   "mapping": [     { "name": "Output 1", "bus_datatype": 1, "type": "coil", "address": 0, "writable": 1 },     { "name": "Input 1", "bus_datatype": 7, "type": "register", "address": 0,  "writable": 1 },     { "name": "Input 1", "bus_datatype": 7, "type": "register", "address": 1,  "writable": 1 }   ] }
------------------------------
Ctrl+F5
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 Daniel - 17.09.2020, 09:52

Forum Jump: