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
#7
(22.12.2016, 10:47)admin Wrote: You can use this helper function:
Code:
function getbit(value, nr)
  value = bit.rshift(value, nr)
  return bit.band(value, 1)
end

value = mb:readregisters(123)
if value then
  dampers_open = getbit(value, 0)
  fire_dampers_open = getbit(value, 1)
  ...
end

Its work for read any bit of 16bit register.

i also write any bit of 16bit register this like..

Code:
function updatebit(bit_value, ModbusAddress, bit_no)
  ????
  ????
  ????
end



For example;

Code:
 updatebit (true, 123, 0)
 updatebit (false, 123, 5)
1. --
before modbus 123 register: 1010 1101 0110 1011 (=44.395)
after modbus 123 register: 1010 1101 0110 1010 (=44.394)
2.--
before modbus 123 register: 1010 1101 0110 1010 (=44.394)
after modbus 123 register: 1010 1101 0100 1010 (=44.362)
Reply


Messages In This Thread
RE: Modbus, getting bits in a register - by Simuzer - 10.11.2024, 09:14

Forum Jump: