21.12.2017, 07:14
As far as I understand, only one bit from 0..2 range can be set to 1. For this control I suggest creating 1-byte unsigned integer
object and assign custom values (0 = set bit 0, 1 = set bit 1, 2 = set bit 2) to it so you don't have to create binary objects for each bit.
object and assign custom values (0 = set bit 0, 1 = set bit 1, 2 = set bit 2) to it so you don't have to create binary objects for each bit.
Code:
mode = grp.getvalue('1/1/1') -- 1-byte unsigned integer
paridad = grp.getvalue('1/1/2') -- boolean
control = grp.getvalue('1/1/2') -- boolean
if mode == 2 then
value = 4
elseif mode == 1 then
value = 2
else
value = 1
end
if paridad then
value = value + 8
end
if control then
value = value + 16
end
log(value)