Posts: 32
Threads: 12
Joined: Oct 2015
Reputation:
0
Hello
I've been testing some emergency lights with a KNX/DALI-gateway.
There are two status-objects from each converter:
- DPT244.600 DALI converter status
- DPT245.600 DALI converter test result
In the manual the 2byte and the 6byte object are divided into several results, like converter status, hardware status and so on.
Here are the full explanation on the content of these two objects:
Anyone made a solution for this in LM5/SL/Wiser??
Or maybe another post on this forum I've overlooked?
I would like to have one GA for each status/result in these objects, but can't get it to work.
I've managed to get some HEX-value, but somehow the part in the string with 00 get "lost in translation
"
Have been testing with some of the solutions in this forum, but not sure if I understand it right.
I'm working with a Zennio DALIBOX KNX-gateway at the moment.
Would appreciate all input on this matter
Posts: 8095
Threads: 43
Joined: Jun 2015
Reputation:
471
You can convert event hex-encoded data to table with bytes like this:
Code:
1 2 3 4 5 6
hex =
event.datahex
bytes = {}
for i =
1 , #
hex ,
2 do
bytes [ #
bytes +
1 ] =
tonumber (
hex :
sub (
i ,
i +
1 ),
16 )
end
Then you can use bit operations to extract specific bits from bytes:
Code:
1 2 3 4 5 6 7
cm =
bit.band (
bit.rshift (
bytes [
1 ],
4 ),
0x0F )
hs =
bit.band (
bytes [
1 ],
0x0F )
fp =
bit.band (
bit.rshift (
bytes [
2 ],
6 ),
0x03 )
dp =
bit.band (
bit.rshift (
bytes [
2 ],
4 ),
0x03 )
pp =
bit.band (
bit.rshift (
bytes [
2 ],
2 ),
0x03 )
cf =
bit.band (
bytes [
2 ],
0x03 )
Posts: 138
Threads: 19
Joined: Apr 2018
Reputation:
0
(03.08.2018, 06:18) admin Wrote: You can convert event hex-encoded data to table with bytes like this:
Code:
1 2 3 4 5 6
hex =
event.datahex
bytes = {}
for i =
1 , #
hex ,
2 do
bytes [ #
bytes +
1 ] =
tonumber (
hex :
sub (
i ,
i +
1 ),
16 )
end
Then you can use bit operations to extract specific bits from bytes:
Code:
1 2 3 4 5 6 7
cm =
bit.band (
bit.rshift (
bytes [
1 ],
4 ),
0x0F )
hs =
bit.band (
bytes [
1 ],
0x0F )
fp =
bit.band (
bit.rshift (
bytes [
2 ],
6 ),
0x03 )
dp =
bit.band (
bit.rshift (
bytes [
2 ],
4 ),
0x03 )
pp =
bit.band (
bit.rshift (
bytes [
2 ],
2 ),
0x03 )
cf =
bit.band (
bytes [
2 ],
0x03 )
Hello admin and anyone that may help,
Could you please give me a full example of the script. I would like to have this script in general for anykind of bitset decoding. In my case I need to decode a 1byte message to 8 bits (boolean) and then visualize them so to be able to write a KNX Object or Virtual for each bit. (Please have a look at the attached photo)
But I also have a big project where emergency dali lights are insalled and I would like to be able to decode the status of the converter (1byte and 3bytes) bit by bit.
Regards,
Attached Files
Thumbnail(s)
Posts: 8095
Threads: 43
Joined: Jun 2015
Reputation:
471
Use this event script to get specific bits from an integer value. Make sure to create bit objects manually before running it.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
function getbit (
value ,
nr )
value =
bit.rshift (
value ,
nr )
return bit.band (
value ,
1 ) ==
1
end
value =
event.getvalue ()
grp.checkupdate (
'1/1/1' ,
getbit (
value ,
0 ))
grp.checkupdate (
'1/1/2' ,
getbit (
value ,
1 ))
grp.checkupdate (
'1/1/3' ,
getbit (
value ,
2 ))
grp.checkupdate (
'1/1/4' ,
getbit (
value ,
3 ))
grp.checkupdate (
'1/1/5' ,
getbit (
value ,
4 ))
grp.checkupdate (
'1/1/6' ,
getbit (
value ,
5 ))
Posts: 138
Threads: 19
Joined: Apr 2018
Reputation:
0
(21.09.2018, 10:04) admin Wrote: Use this event script to get specific bits from an integer value. Make sure to create bit objects manually before running it.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
function getbit (
value ,
nr )
value =
bit.rshift (
value ,
nr )
return bit.band (
value ,
1 ) ==
1
end
value =
event.getvalue ()
grp.checkupdate (
'1/1/1' ,
getbit (
value ,
0 ))
grp.checkupdate (
'1/1/2' ,
getbit (
value ,
1 ))
grp.checkupdate (
'1/1/3' ,
getbit (
value ,
2 ))
grp.checkupdate (
'1/1/4' ,
getbit (
value ,
3 ))
grp.checkupdate (
'1/1/5' ,
getbit (
value ,
4 ))
grp.checkupdate (
'1/1/6' ,
getbit (
value ,
5 ))
Thank you for your quick reply. What about decoding 2 or 3 byte objects?
Posts: 8095
Threads: 43
Joined: Jun 2015
Reputation:
471
You can access any value up to 4 bytes the same way. Second argument for getbit function is bit number (starting from 0, up to 31).
You can also access bytes separately by using the code from the first example:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
hex =
event.datahex
bytes = {}
for i =
1 , #
hex ,
2 do
bytes [ #
bytes +
1 ] =
tonumber (
hex :
sub (
i ,
i +
1 ),
16 )
end
function getbit (
value ,
nr )
value =
bit.rshift (
value ,
nr )
return bit.band (
value ,
1 )
end
grp.checkupdate (
'32/1/1' ,
getbit (
bytes [
1 ],
0 ))
grp.checkupdate (
'32/1/2' ,
getbit (
bytes [
1 ],
1 ))
grp.checkupdate (
'32/1/3' ,
getbit (
bytes [
1 ],
2 ))
grp.checkupdate (
'32/1/4' ,
getbit (
bytes [
1 ],
3 ))
grp.checkupdate (
'32/1/5' ,
getbit (
bytes [
1 ],
4 ))
grp.checkupdate (
'32/1/6' ,
getbit (
bytes [
1 ],
5 ))
grp.checkupdate (
'32/1/7' ,
getbit (
bytes [
1 ],
6 ))
grp.checkupdate (
'32/1/8' ,
getbit (
bytes [
1 ],
7 ))
grp.checkupdate (
'32/2/1' ,
getbit (
bytes [
2 ],
0 ))
grp.checkupdate (
'32/2/2' ,
getbit (
bytes [
2 ],
1 ))
grp.checkupdate (
'32/2/3' ,
getbit (
bytes [
2 ],
2 ))
grp.checkupdate (
'32/2/4' ,
getbit (
bytes [
2 ],
3 ))
grp.checkupdate (
'32/2/5' ,
getbit (
bytes [
2 ],
4 ))
grp.checkupdate (
'32/2/6' ,
getbit (
bytes [
2 ],
5 ))
grp.checkupdate (
'32/2/7' ,
getbit (
bytes [
2 ],
6 ))
grp.checkupdate (
'32/2/8' ,
getbit (
bytes [
2 ],
7 ))
Posts: 138
Threads: 19
Joined: Apr 2018
Reputation:
0
(21.09.2018, 10:54) admin Wrote: You can access any value up to 4 bytes the same way. Second argument for getbit function is bit number (starting from 0, up to 31).
You can also access bytes separately by using the code from the first example:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
hex =
event.datahex
bytes = {}
for i =
1 , #
hex ,
2 do
bytes [ #
bytes +
1 ] =
tonumber (
hex :
sub (
i ,
i +
1 ),
16 )
end
function getbit (
value ,
nr )
value =
bit.rshift (
value ,
nr )
return bit.band (
value ,
1 )
end
grp.checkupdate (
'32/1/1' ,
getbit (
bytes [
1 ],
0 ))
grp.checkupdate (
'32/1/2' ,
getbit (
bytes [
1 ],
1 ))
grp.checkupdate (
'32/1/3' ,
getbit (
bytes [
1 ],
2 ))
grp.checkupdate (
'32/1/4' ,
getbit (
bytes [
1 ],
3 ))
grp.checkupdate (
'32/1/5' ,
getbit (
bytes [
1 ],
4 ))
grp.checkupdate (
'32/1/6' ,
getbit (
bytes [
1 ],
5 ))
grp.checkupdate (
'32/1/7' ,
getbit (
bytes [
1 ],
6 ))
grp.checkupdate (
'32/1/8' ,
getbit (
bytes [
1 ],
7 ))
grp.checkupdate (
'32/2/1' ,
getbit (
bytes [
2 ],
0 ))
grp.checkupdate (
'32/2/2' ,
getbit (
bytes [
2 ],
1 ))
grp.checkupdate (
'32/2/3' ,
getbit (
bytes [
2 ],
2 ))
grp.checkupdate (
'32/2/4' ,
getbit (
bytes [
2 ],
3 ))
grp.checkupdate (
'32/2/5' ,
getbit (
bytes [
2 ],
4 ))
grp.checkupdate (
'32/2/6' ,
getbit (
bytes [
2 ],
5 ))
grp.checkupdate (
'32/2/7' ,
getbit (
bytes [
2 ],
6 ))
grp.checkupdate (
'32/2/8' ,
getbit (
bytes [
2 ],
7 ))
Thank you again for the great support. Excellent!!!
Posts: 12
Threads: 5
Joined: Jun 2017
Reputation:
0
13.12.2019, 11:06
(This post was last modified: 13.12.2019, 11:07 by chriscroko .)
What would I piece together from this thread to read out the "DPT245.600 DALI converter test result"? The 6byte signal.
Could you explain in "layman's terms"?
Posts: 8095
Threads: 43
Joined: Jun 2015
Reputation:
471
Use this script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
hex =
event.datahex
bytes = {}
for i =
1 ,
6 do
pos =
1 + (
i -
1 ) *
2
ch =
hex :
sub (
pos ,
pos +
1 )
bytes [
i ] =
tonumber (
ch ,
16 )
or 0
end
ltrf =
bit.band (
bit.rshift (
bytes [
1 ],
4 ),
0x0F )
ltrd =
bit.band (
bytes [
1 ],
0x0F )
ltrp =
bit.band (
bit.rshift (
bytes [
2 ],
4 ),
0x0F )
sf =
bit.band (
bit.rshift (
bytes [
3 ],
6 ),
0x03 )
sd =
bit.band (
bit.rshift (
bytes [
3 ],
4 ),
0x03 )
sp =
bit.band (
bit.rshift (
bytes [
3 ],
2 ),
0x03 )
ldtr =
bit.bor (
bit.lshift (
bytes [
4 ],
8 ),
bytes [
5 ])
lpdtr =
bytes [
6 ]
log (
ltrf ,
ltrd ,
ltrp ,
sf ,
sd ,
sp ,
lpdtr )
Posts: 12
Threads: 5
Joined: Jun 2017
Reputation:
0
(13.12.2019, 11:59) admin Wrote: Use this script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
hex =
event.datahex
bytes = {}
for i =
1 ,
6 do
pos =
1 + (
i -
1 ) *
2
ch =
hex :
sub (
pos ,
pos +
1 )
bytes [
i ] =
tonumber (
ch ,
16 )
or 0
end
ltrf =
bit.band (
bit.rshift (
bytes [
1 ],
4 ),
0x0F )
ltrd =
bit.band (
bytes [
1 ],
0x0F )
ltrp =
bit.band (
bit.rshift (
bytes [
2 ],
4 ),
0x0F )
sf =
bit.band (
bit.rshift (
bytes [
3 ],
6 ),
0x03 )
sd =
bit.band (
bit.rshift (
bytes [
3 ],
4 ),
0x03 )
sp =
bit.band (
bit.rshift (
bytes [
3 ],
2 ),
0x03 )
ldtr =
bit.bor (
bit.lshift (
bytes [
4 ],
8 ),
bytes [
5 ])
lpdtr =
bytes [
6 ]
log (
ltrf ,
ltrd ,
ltrp ,
sf ,
sd ,
sp ,
lpdtr )
The script works and logs the right datasets. What I need now is a way to write out the different parts to different group addresses for BMS purposes. Could you give a hint on how to do this also?
And also thanks for the base script.
Posts: 4956
Threads: 28
Joined: Aug 2017
Reputation:
226
Just add this for every value on the end
grp.checkupdate('32/1/1', ltrf )
------------------------------
Ctrl+F5
Posts: 12
Threads: 5
Joined: Jun 2017
Reputation:
0
(10.01.2020, 09:34) Daniel. Wrote: Just add this for every value on the end
grp.checkupdate('32/1/1', ltrf )
Awesome! Thanks for the tip.