18.01.2016, 12:57
Due to 2-byte <> 4-byte conversion, you need to use two uint16 objects: 2/1/2 and 2/1/3 in this example. Float16 object address is 2/1/1.
1. Add a script to float16 object, it will split the value and write it to 2/1/2 and 2/1/3. Change 15.15.255 to your LM physical address so this script is only triggered from KNX bus but not from LM internally.
2. Attach a script to 2/1/3 (second uint16 object). It converts two uint16 regs to float32 internally and then writes the value to float16 object.
1. Add a script to float16 object, it will split the value and write it to 2/1/2 and 2/1/3. Change 15.15.255 to your LM physical address so this script is only triggered from KNX bus but not from LM internally.
Code:
if event.src ~= '15.15.255' and event.src ~= 'local' then
value = event.getvalue()
raw = knxdatatype.encode(value, dt.float32).dataraw
r1 = raw:byte(1) * 0x100 + raw:byte(2)
r2 = raw:byte(3) * 0x100 + raw:byte(4)
grp.update('2/1/2', r1, dt.uint16)
grp.update('2/1/3', r2, dt.uint16)
end
2. Attach a script to 2/1/3 (second uint16 object). It converts two uint16 regs to float32 internally and then writes the value to float16 object.
Code:
require('luamodbus')
r1 = grp.getvalue('2/1/2')
r2 = grp.getvalue('2/1/3')
value = luamodbus.convert('float32', r1, r2)
grp.write('2/1/1', value, dt.float16)