Logic Machine Forum
LM as ModbusSlave. Transaction ID error - 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: LM as ModbusSlave. Transaction ID error (/showthread.php?tid=3196)



LM as ModbusSlave. Transaction ID error - ikhy - 25.02.2021

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()



RE: LM as ModbusSlave. Transaction ID error - admin - 26.02.2021

Why are you trying to use ModBus for data exchange? You can use KNX/IP routing without any scripts for this.


RE: LM as ModbusSlave. Transaction ID error - ikhy - 26.02.2021

We will transfer data to a top system that only understands ModBus. LM will work as a gateway.
Strange that the script with data like int16 works fine. Сould you give me the package luamodbus 20160606 for the test?


RE: LM as ModbusSlave. Transaction ID error - admin - 26.02.2021

Which libmodbus (not luamodbus) package versions do you have on both devices?


RE: LM as ModbusSlave. Transaction ID error - ikhy - 26.02.2021

Yes. Both devices have libmodbus


RE: LM as ModbusSlave. Transaction ID error - admin - 26.02.2021

Tell me the package versions on both devices


RE: LM as ModbusSlave. Transaction ID error - ikhy - 26.02.2021

on old device 3.1.2-4, on new - 3.1.2-5
"Transaction ID error" - on new device


RE: LM as ModbusSlave. Transaction ID error - admin - 26.02.2021

There are no changes related to ModBus TCP between these versions. Check if you have any errors in the Error Log. TCP slave script has been used by many users an no one reported this error before. This might also be an issue in your top system. If it runs on Windows then you can provide a WireShark dump to see what's causing this issue.