openhab/openhab — pull request #1109 by rmayr (2014-06-02 09:04:19+00:00)
Title: Make modbus binding more flexible. Special case: Drexel&Weiß heat pump and air conditioning

This set of changes introduces another global config option readmultipleregisters to select between modbus read commands 0x3 and 0x4 and documents the behaviour of writemultipleregisters at least in source code. Additionally, it is now possible to pass the read timeout for modbus commands in the binding configuration and to specify a "step" width that defines how many registers are read from the slave in one go. For some modbus slaves, e.g. the Drexel&Weiß heatpumps and air conditioning controllers, only a limited (or fixed) set of registers can be read at a time. With the changes in this pull request, interfacing with Drexel&Weiß is now possible, although more changes will be required on a higher level to allow efficient use of this binding for more than a few modbus addresses.

Example configuration file that read and writes a single parameter in Drexel&Weiß systems (which is represented by 2 modbus registers):

openhab.cfg:
# these are read/only
modbus:serial.dw3.connection=/dev/ttyUSB1:19200:500
modbus:serial.dw3.id=1
modbus:serial.dw3.start=230
modbus:serial.dw3.length=2
modbus:serial.dw3.step=2
modbus:serial.dw3.type=input

# these are read/write
modbus:serial.dw4.connection=/dev/ttyUSB1:19200:500
modbus.serial.dw4.id=1
modbus:serial.dw4.start=5016
modbus:serial.dw4.length=2
# always read 2 words at a time
modbus:serial.dw4.step=2
modbus:serial.dw4.type=holding

items/drexelweiss.items:
Group Heating

/* address 230, second byte */
Number Co2 "CO2 Konzentration" (Heating) {modbus="dw3:1"}
/* address 5016, second byte */
Number Dw_TempTarget "Raum-Solltemperatur [%d]" (Heating) {modbus="dw4:1"}

Combining the two registers into a single openHAB item is still to be done, and I would appreciate input by openHAB core devs on how best to do this. I already have an XML file with all registers supported by D&W, their data types (always represented by 2 modbus registers, but mapping to different high-level interpretations), their data ranges, and physical units of measurements. I plan to use XSLT to generate item definitions from this (in case it every changes), but will need more Java code support for the mapping. The question is where to put these mappings. The modbus binding doesn't seem the right place to do it.