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 a Modbus slave : number of slaves
#12
(09.08.2022, 11:35)admin Wrote: You're missing a part of the slave script. It should have at least 35 lines, you've posted only 21.

yes, it was only the first lines...
Here is full !
Code:
if not mb then
  require('luamodbus')
  mb = luamodbus.tcp()
 
  res, err = mb:open('0.0.0.0', 502)
  log("mb:open :",res,err)
  res, err = mb:setslave(2)
  log("mb:setslave :",res,err)
 
  log("Modbus slave IN : 502/2")
  function setint64(grpaddr, regaddr)
    local value = grp.getvalue(grpaddr) or 0
    local raw = knxdatatype.encode(value, dt.int64).dataraw
    local r1 = raw:byte(2) * 0x100 + raw:byte(1)
    local r2 = raw:byte(4) * 0x100 + raw:byte(3)
    local r3 = raw:byte(6) * 0x100 + raw:byte(5)
    local r4 = raw:byte(8) * 0x100 + raw:byte(7)

    res, err = mb:setregisters(regaddr, r4, r3, r2, r1)
    log("mb:setregisters :",res,err)
  end

  function updateregisters()
    setint64('0/0/14', 3204)
  end

  mb:setmapping(0, 0, 3300, 0)
  updateregisters()
 
  prev = os.time()
end

mb:handleslave()

curr = os.time()
if curr ~= prev then
  updateregisters()
  prev = curr
end
log("Modbus slave OUT : 502/2")
Reply


Messages In This Thread
RE: LM as a Modbus slave : number of slaves - by SigmaTec - 09.08.2022, 11:38

Forum Jump: