07.12.2018, 11:16
This script will set bit 0 if 1/1/1 is on, bit 1 if 1/1/2 is on etc. Adjust as needed and add writing to ModBus register at the end of the script.
Code:
function setbit(value, bitnr)
local mask = bit.lshift(1, bitnr)
return bit.bor(value, mask)
end
value = 0
if grp.getvalue('1/1/1') then
value = setbit(value, 0)
end
if grp.getvalue('1/1/2') then
value = setbit(value, 1)
end
if grp.getvalue('1/1/3') then
value = setbit(value, 2)
end
log(value)