-
Notifications
You must be signed in to change notification settings - Fork 154
Generic Modbus Devices
This page describes the design of the generic Modbus sensor and device class implementations. The Modbus protocol has a very simple data model, based on digital I/Os (coils and discrete inputs) and 16-bit input and holding registers, which can be read or written (holding registers only).
Most sensor devices provide the measurement value or values in 16-bit holding registers. The data format is in many cases a scaled 16-bit integer value (e.g., temperature in degrees Celsius * 100), or in a pair of two consecutive registers that make up a 32-bit IEEE 754 single-precision floating point number.
Therefore it is possible to implement a generic sensor class that is configured with:
- the service name of the
ModbusMaster
device (for communication with the Modbus device, can be RTU or TCP) - a sample interval (in milliseconds), specifying the interval in which the generic Modbus sensor sends a Read Holding Registers request to the Modbus device to read the value(s)
- the address of the holding register holding the measured value
- the format of the value (e.g., scaled 16-bit integer, single-precision floating-point, etc.)
- meta-data, such as physical quantity measured (e.g., "temperature") and physical unit (e.g., "Cel")
Since some Modbus sensor devices can measure multiple values (e.g., temperature and humidity). This can be covered by either
setting up two separate Sensor objects (one for temperature, one for humidity), or by combining both into a single Sensor
device, with the temperature as the primary value (reported by the value()
) method, and the humidity available by
reading a device property (getPropertyDouble("humidity")
).
Similarly to a generic Sensor implementation, also generic implementations for
IO
,
BooleanSensor
,
Switch
and
Counter
can be provided.
More complex devices, such as drive controllers, however, may need specific device implementations.