09.08.2022, 06:27
If you only need read-only values on the modbus side you can simply periodically update the register values in the resident script itself. Modify register mapping in updateregisters() as needed. Each script must use a unique port (502, 503 etc).
Code:
if not mb then
require('luamodbus')
mb = luamodbus.tcp()
mb:open('0.0.0.0', 502)
mb:setslave(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)
mb:setregisters(regaddr, r4, r3, r2, r1)
end
function updateregisters()
setint64('32/1/1', 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