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 that you accept these cookies being set.

16bit to 1byte
#1
hi guys,

i need to scale a modbus input which is 16bit to use as a knx scale object to get 0-255 for my lighting control.
the modbus output registers of the device are fixed at 16bit.

what is the best way to scale this ?

thx in advance
Reply
#2
Code:
grp.write('1/1/1', modbusvalue, dt.scale)

or

Code:
value = knxdatatype.decode(modbusvalue, dt.scale)


Something like that?
Reply
#3
If your modbus device is using full 16-bit range [0..65535], you can use bit shift to discard lowest 8 bits:
Code:
value = bit.rshift(value, 8)
grp.write('1/1/1', value, dt.uint8) -- force value range to [0..255]

Also, I would suggest using profiles instead of scripts.
Reply


Forum Jump: