09.08.2022, 11:38
(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")