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.

Modbus TCP Slave Problem
#1
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)
Reply


Messages In This Thread
Modbus TCP Slave Problem - by savaskorkmaz - 29.06.2022, 09:06
RE: Modbus TCP Slave Problem - by admin - 29.06.2022, 09:10
RE: Modbus TCP Slave Problem - by admin - 29.06.2022, 09:21

Forum Jump: