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.

LM as ModbusSlave. Transaction ID error
#1
I have two LMs and I run one script on them to transfer values from LM via Modbus. On one of the LMs everything works fine, on the second "Transaction ID error". Please help me! I'm still quite a beginner.
 
The first LM has package  luamodbus 20160606
On the second LM - luamodbus 20190219

Code:
if not mb then
  require('genohm-scada.eibdgm')
  require('luamodbus')

  -- list of coil mapping, starting from 0
  coils = {}

  -- list of register mapping, starting from 0
  registers = {
    {'40/1/5',dt.float32,0},{'40/1/6',0xFF,1}
}
  holdingRegisters = {
    {'40/1/7',dt.uint16}
}
 
  -- list of register data types, element count must match registers table
   
    -- 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)
        mb:setcoils(id - 1, value)
      end
    end
   
    -- try to find matching holding register
    for id, addr in ipairs(holdingRegisters) do
      if event.dst == addr[1] then
        value = knxdatatype.decode(event.datahex,addr[2])
        mb:setregisters(id-1, value)
      end
      end

    -- try to find matching input register
    for id, addr in ipairs(registers) do
      if event.dst == addr[1] then
        if (addr[2]==dt.float32) then
          value = knxdatatype.decode(string.sub(event.datahex,1,4), dt.uint32)
        mb:setinputregisters(1+addr[3], value)
            value = knxdatatype.decode(string.sub(event.datahex,-4), dt.uint32)
      mb:setinputregisters(addr[3], value)
            elseif (addr[2]==0xFF) then
            else
              value = knxdatatype.decode(event.datahex,addr[2])
              mb:setinputregisters(addr[3], value)
            end
      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 = holdingRegisters[ register + 1 ][1]
    if addr then
  grp.write(addr, value, holdingRegisters[ register + 1][2])
    end
  end

  -- knx group monitor, handles group writes
  knxclient = eibdgm:new({ timeout = 0.1 })
  knxclient:sethandler('groupwrite', knxgroupwrite)

  -- modbus slave, listen on all interfaces and default port 502
  mb = luamodbus.tcp()
  mb:open('0.0.0.0', 502)

   --setting slave id is optional
   --mb:setslave(1)

  mb:setreceivetimeout(0.1)
  mb:setmapping(#coils, 0, #holdingRegisters, #registers)

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

  -- init holding registers
  for id, addr in ipairs(holdingRegisters) do
    value = grp.getvalue(addr[1])
    mb:setregisters(id - 1, value)
  end
 
-- init registers
  for id, addr in ipairs(registers) do
    if (addr[2]==dt.float32) then
    elseif(addr[2]==0xFF) then
    else
      value = grp.getvalue(addr[1])
      mb:setregisters(addr[3], value)
  end
  end
 
  -- set callbacks for coil and register write
  mb:setwritecoilcb(mbwritecoils)
  mb:setwriteregistercb(mbwriteregisters)
end

-- handle modbus and knx
mb:handleslave()
knxclient:step()
Reply


Messages In This Thread
LM as ModbusSlave. Transaction ID error - by ikhy - 25.02.2021, 16:21

Forum Jump: