Skip to content

Instantly share code, notes, and snippets.

@jborbely
Created March 8, 2023 21:01
Show Gist options
  • Select an option

  • Save jborbely/985ea5db06884fba200a6fa6944a4c82 to your computer and use it in GitHub Desktop.

Select an option

Save jborbely/985ea5db06884fba200a6fa6944a4c82 to your computer and use it in GitHub Desktop.
Read the data registers of a Vaisala HMP110 probe
import struct
# pip install pymodbus[serial]
from pymodbus.client import ModbusSerialClient
from pymodbus.exceptions import ModbusIOException
def read_holding_registers():
def unpack(r, i):
a, b = r.registers[i-1:i+1]
return struct.unpack('<f', struct.pack('<HH', a, b))[0]
while True:
response = probe.read_holding_registers(address=0, count=28, slave=240)
if not isinstance(response, ModbusIOException):
return {
'relative_humidity': unpack(response, 1),
'temperature': unpack(response, 3),
'dewpoint': unpack(response, 9),
'absolute_humidity': unpack(response, 15),
'mixing_ratio': unpack(response, 17),
'wetbulb_temperature': unpack(response, 19),
'enthalpy': unpack(response, 27),
}
probe = ModbusSerialClient('COM10', method='rtu', baudrate=19200, stopbits=2, parity='N', timeout=1)
probe.connect()
print(read_holding_registers())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment