10.11.2024, 09:14
(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)
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)