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.

Modbus, getting bits in a register
#2
Hi,


If you read a 16 bits integer register you can get back value 0 to 65535, but when this register is used as single bit (not coil) you probably get back only value 0 or 1 out of this register.

To use that value for a 1 bit KNX value you can simply transfer it to boolean by using this:

Code:
value = mb:readregisters(123)
if value == 0 or value == 1 then
 value = toboolean(value)
 grp.write('1/1/1', value)
end
To set 16 bits register value to 2 byte signed you can use this code:
Code:
r1 = mb:readregisters(124)
value = lmcore.inttohex(r1, 2)
value = knxdatatype.decode(value, dt.int16)

BR,
Erwin
Reply


Messages In This Thread
RE: Modbus, getting bits in a register - by Erwin van der Zwart - 22.12.2016, 00:20

Forum Jump: