Logic Machine Forum
Modbus TCP Slave Problem - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Modbus TCP Slave Problem (/showthread.php?tid=4117)



Modbus TCP Slave Problem - savaskorkmaz - 29.06.2022

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)
        mbConfusedetcoils(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 ])
        mbConfusedetregisters(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 })
  knxclientConfusedethandler('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
  -- mbConfusedetslave(1)

  mbConfusedetreceivetimeout(0.1)
  mbConfusedetmapping(#coils, 0, #registers, 0)

  -- init coils
  for id, addr in ipairs(coils) do
    value = grp.getvalue(addr)
    mbConfusedetcoils(id - 1, value)
  end

  -- init registers
  for id, addr in ipairs(registers) do
    value = grp.getvalue(addr)
    mbConfusedetregisters(id - 1, value)
  end

  -- set callbacks for coil and register write
  mbConfusedetwritecoilcb(mbwritecoils)
  mbConfusedetwriteregistercb(mbwriteregisters)
end

-- handle modbus and knx
mb:handleslave()
knxclient:loop(0.1)


RE: Modbus TCP Slave Problem - admin - 29.06.2022

Replace
Code:
mb:open('192.168.1.70', 502)
With
Code:
mb:open('0.0.0.0', 502)



RE: Modbus TCP Slave Problem - savaskorkmaz - 29.06.2022

(29.06.2022, 09:10)admin Wrote: Replace
Code:
mb:open('192.168.1.70', 502)
With
Code:
mb:open('0.0.0.0', 502)

I changed and i received same result. There is no firewall on the system.


RE: Modbus TCP Slave Problem - admin - 29.06.2022

Do a complete script restart via disable/enable. The same script works fine for me with listen IP changed to 0.0.0.0.