Can anyone please help me decoding a 1 byte object as mentioned below?
1-byte object to transmit and read out the error status of individual DALI operating devices connected to the system.
The following bit assignment is used:
Bit 0...5: Number of the DALI operating device (0...63)
Bit 6: Lamp error ("0" = No error, "1" = Error)
Bit 7: Electronic ballast error ("0" = No error, "1" = Error)
I could use the following code to get the status of the last two bits but I don't know how to convert the first 6 bits to integer and write the value to a virtual object.
Code:
function getbit(value, nr)
value = bit.rshift(value, nr)
return bit.band(value, 1) == 1
end
13.07.2020, 13:03 (This post was last modified: 13.07.2020, 13:04 by savaskorkmaz.)
Hi,
When i changed the data type to 250 byte string original object data comes from KNX ( 0000005A000000FF0001 ) looks on Logic Machine like ( Z�▯ ) . Please check it out the object logs screenshot which is attached.
Event Script is not working when the value is ( Z�▯ )
We need 13 bits and 8 bytes it means total 21 points from 1 10 bytes objects. Can you check the script below also?
Regards,
value = event.getvalue()
addr = bit.band(value, 0xAF)
Since the input is split into bytes you only get bits 0..7 for each byte. The value in object logs is how the binary string looks like. You can try switching data type to 14 byte HEX.
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[ 1 ]
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
When we used your corrected script , script is worked for both 250 byte and 14 byte HEX and the results are same. But encoded values were not correct. I attached a screenshot and excel list about what we expected and what happened. As you can see in attached picture or excel file, our expected results and values that are coming from script are different.
Data from KNX : 0000005A000000FF0001 250 byte datapoint view in LM : Z�▯ 14 byte HEX datapoint view in LM : 5AFFFD01
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.
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