pythonminimalmodbus

Python minimalmodbus reading 16-bit register


We have a heating controller that using 16-bit registers to read data.

Example: register 512 - bit from 0 to 16 is using to read temperature.

This code works fine for this exmaple

#!/usr/bin/env python
import minimalmodbus
import time

minimalmodbus.BAUDRATE = 19200

instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1)

while True:
    temperature1 = instrument.read_register(512, 0, 3)
    temperature2 = instrument.read_register(513, 0, 3)
    temperature3 = instrument.read_register(514, 0, 3)
    temperature4 = instrument.read_register(515, 0, 3)

But this controller also have 516th register with this bit table:

enter image description here

Can't get any data from this register. What the bit operation must be to get 'status' from this register?

I'am googling with no success for like two days. I'am not good with bit operations.

Any answers much appreciated. Thanks!


Solution

  • If what you would like to do is get the statussection from register 516, you could extract the bits you want with Bitwise Operators :

    register516 = instrument.read_register(516)
    status = (register516 >> 7) & 0x7
    

    That will shift and mask the value to get the 3 desired bits corresponding to status.