This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

KNX - Dali Device Diagnostic telegram Decoding
#1
Hello All,

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

value = event.getvalue()

grp.checkupdate('32/1/1', getbit(value, 6))
grp.checkupdate('32/1/2', getbit(value, 7))

Thank you in andvance.
Reply
#2
You need to apply a bit mask like this:
Code:
addr = bit.band(value, 0x3F)
Reply
#3
(08.05.2019, 13:59)admin Wrote: You need to apply a bit mask like this:
Code:
addr = bit.band(value, 0x3F)

Thank you admin. It works perfectly. So the final code to get the dali device address starting with 1->64 it will be like  this :

Code:
value = event.getvalue()
addr = bit.band(value, 0x3F)

function getbit(value, nr)
value = bit.rshift(value, nr)
return bit.band(value, 1) == 1
end

grp.checkupdate('32/1/50', (addr + 1))
grp.checkupdate('32/1/51', getbit(value, 6))
grp.checkupdate('32/1/52', getbit(value, 7))
Reply
#4
Hi,
If we extented this example to 10 byte object and if we need to decode for example
First Byte
9th bit
10th bit
.
15th bit
3rdbyte

How we can use this code ?

Regards,
Reply
#5
For 10 bytes you need to set data type to 250 byte string.
Then you can split string into bytes like this:
Code:
value = event.getvalue()
bytes = { value:byte(1, #value) }
-- byte 1 is bytes[ 1 ], byte 2 is bytes[ 2 ] and so on
Reply
#6
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)



function getbit(value, nr)

  value = bit.rshift(value, nr)

  return bit.band(value, 1) == 1

end





grp.checkupdate('32/1/1', getbit(value,0))

grp.checkupdate('32/1/2', getbit(value,1))

grp.checkupdate('32/1/3', getbit(value,2))

grp.checkupdate('32/1/4', getbit(value,3))

grp.checkupdate('32/1/5', getbit(value,4))

grp.checkupdate('32/1/6', getbit(value,8))

grp.checkupdate('32/1/7', getbit(value,9))

grp.checkupdate('32/1/8', getbit(value,10))

grp.checkupdate('32/1/9', getbit(value,11))

grp.checkupdate('32/1/10', getbit(value,12))

grp.checkupdate('32/1/11', getbit(value,13))

grp.checkupdate('32/1/12', getbit(value,14))

grp.checkupdate('32/1/13', getbit(value,15))



bytes3 = { value:byte(3, #value) }

bytes4 = { value:byte(4, #value) }

bytes5 = { value:byte(5, #value) }

bytes6 = { value:byte(6, #value) }

bytes7 = { value:byte(7, #value) }

bytes8 = { value:byte(8, #value) }

bytes9 = { value:byte(9, #value) }



grp.checkupdate('32/1/14', bytes3)

grp.checkupdate('32/1/15', bytes4)

grp.checkupdate('32/1/16', bytes5)

grp.checkupdate('32/1/17', bytes6)

grp.checkupdate('32/1/18', bytes7)

grp.checkupdate('32/1/19', bytes8)

grp.checkupdate('32/1/20', bytes9)
grp.checkupdate('32/1/21', bytes10)

Attached Files Image(s)
   
Reply
#7
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

b2 = bytes[ 2 ]
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[ 3 ])
grp.checkupdate('32/1/15', bytes[ 4 ])
grp.checkupdate('32/1/16', bytes[ 5 ])
grp.checkupdate('32/1/17', bytes[ 6 ])
grp.checkupdate('32/1/18', bytes[ 7 ])
grp.checkupdate('32/1/19', bytes[ 8 ])
grp.checkupdate('32/1/20', bytes[ 9 ])
grp.checkupdate('32/1/21', bytes[ 10 ])
Reply
#8
Hi,

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


Attached Files Image(s)
   
.xlsx   Script.xlsx (Size: 10.96 KB / Downloads: 1)
Reply
#9
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

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 ])
Reply


Forum Jump: