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.

Write one bit in register modbus
#4
As far as I understand, only one bit from 0..2 range can be set to 1. For this control I suggest creating 1-byte unsigned integer
object and assign custom values (0 = set bit 0, 1 = set bit 1, 2 = set bit 2) to it so you don't have to create binary objects for each bit.

Code:
mode = grp.getvalue('1/1/1') -- 1-byte unsigned integer
paridad = grp.getvalue('1/1/2') -- boolean
control = grp.getvalue('1/1/2') -- boolean

if mode == 2 then
  value = 4
elseif mode == 1 then
  value = 2
else
  value = 1
end

if paridad then
  value = value + 8
end

if control then
  value = value + 16
end

log(value)
Reply


Messages In This Thread
RE: Write one bit in register modbus - by admin - 21.12.2017, 07:14

Forum Jump: