13.07.2020, 14:42
For strings and binary data bytes are ordered from left to right not the other way round.
Just reverse the numbering in your script and it should work.
Just reverse the numbering in your script and it should work.
Code:
value = event.getvalue()
function getbit(value, nr)
value = bit.rshift(value, nr)
return bit.band(value, 1) == 1
end
bytes = { value:byte(1, #value) }
b1 = bytes[ 10 ]
if b1 then
grp.checkupdate('32/1/1', getbit(b1, 0))
grp.checkupdate('32/1/2', getbit(b1, 1))
grp.checkupdate('32/1/3', getbit(b1, 2))
grp.checkupdate('32/1/4', getbit(b1, 3))
grp.checkupdate('32/1/5', getbit(b1, 4))
end
b2 = bytes[ 9 ]
if b2 then
grp.checkupdate('32/1/6', getbit(b2, 0))
grp.checkupdate('32/1/7', getbit(b2, 1))
grp.checkupdate('32/1/8', getbit(b2, 2))
grp.checkupdate('32/1/9', getbit(b2, 3))
grp.checkupdate('32/1/10', getbit(b2, 4))
grp.checkupdate('32/1/11', getbit(b2, 5))
grp.checkupdate('32/1/12', getbit(b2, 6))
grp.checkupdate('32/1/13', getbit(b2, 7))
end
grp.checkupdate('32/1/14', bytes[ 8 ])
grp.checkupdate('32/1/15', bytes[ 7 ])
grp.checkupdate('32/1/16', bytes[ 6 ])
grp.checkupdate('32/1/17', bytes[ 5 ])
grp.checkupdate('32/1/18', bytes[ 4 ])
grp.checkupdate('32/1/19', bytes[ 3 ])
grp.checkupdate('32/1/20', bytes[ 2 ])
grp.checkupdate('32/1/21', bytes[ 1 ])