#!/usr/bin/env python
# Modbus uitlezen
# Apparaat: F2000TSM - AT-VLD-VLH-V1307 (TEMP/HUM/CO2 meter)
#
# Script gemaakt door S. Ebeltjes (domoticx.nl)
# Kopieren (of delen hiervan) is verboden zonder toestemming van de eigenaar!
from __future__ import division
import pymodbus
import serial
from pymodbus.pdu import ModbusRequest
from pymodbus.client.sync import ModbusSerialClient as ModbusClient #initialize a serial RTU client instance
from pymodbus.transaction import ModbusRtuFramer
from pymodbus.constants import Endian # Nodig voor 32-bit float getallen (2 registers / 4 bytes)
from pymodbus.payload import BinaryPayloadDecoder # Nodig voor 32-bit float getallen (2 registers / 4 bytes)
from pymodbus.payload import BinaryPayloadBuilder # Nodig om 32-bit floats te schrijven naar register
import f2000tsmthco2_conf
try:
client = ModbusClient(method = f2000tsmth_conf.method, port = f2000tsmth_conf.port, stopbits = f2000tsmth_conf.stopbits, bytesize = f2000tsmth_conf.bytesize, parity = f2000tsmth_conf.parity, baudrate = f2000tsmth_conf.baudrate, timeout = f2000tsmth_conf.timeout, retries = f2000tsmth_conf.retries)
connection = client.connect()
except:
print "Modbus connectie error / F2000TSM - AT-VLD-VLH-V1307"
# LEES CO2 uit
def co2(appid):
try:
data = client.read_input_registers(0, 2, unit=appid)
decoder = BinaryPayloadDecoder.fromRegisters(data.registers, endian=Endian.Big)
client.close()
return round(decoder.decode_32bit_float(), 2)
except:
print "Modbus register error (co2)"
return 0
# LEES Temperatuur uit
def temp(appid):
try:
data = client.read_input_registers(2, 2, unit=appid)
decoder = BinaryPayloadDecoder.fromRegisters(data.registers, endian=Endian.Big)
client.close()
return round(decoder.decode_32bit_float(), 2)
except:
print "Modbus register error (temp)"
return 0
# LEES Luchtvochtigheid uit
def hum(appid):
try:
data = client.read_input_registers(4, 2, unit=appid)
decoder = BinaryPayloadDecoder.fromRegisters(data.registers, endian=Endian.Big)
client.close()
return round(decoder.decode_32bit_float(), 2)
except:
print "Modbus register error (hum)"
return 0