16bit to 1byte - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: 16bit to 1byte (/showthread.php?tid=373) |
16bit to 1byte - duvelken - 16.08.2016 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 RE: 16bit to 1byte - MarkVersluis - 16.08.2016 Code: grp.write('1/1/1', modbusvalue, dt.scale) or Code: value = knxdatatype.decode(modbusvalue, dt.scale) Something like that? RE: 16bit to 1byte - admin - 17.08.2016 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) Also, I would suggest using profiles instead of scripts. |