Skip to content

Modbus

Reference documents

MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b

Needed information

Modbus TCP

measure target slave address size modbus function cast type
compartment1_temperature 192.168.0.100:502 1 2048 1 read input registers uint16
... ... ... ... ... ... ...

Modbus RTU (RS485 or RS232)

measure type speed frame slave address size modbus function cast type
compartment1_temperature RS232 19200 8N1 1 2048 1 read input registers uint16
compartment2_temperature RS485 19200 8N1 1 2048 1 read input registers int16
... ... ... ... ... ... ... ... ...

Measure

A unique friendly name of the measurement, e.g. overall_energy_consumption, compartment1_temperature, compartment2_temperature

Target

The target IP in the form of IP:port, e.g. 192.168.0.100:502

Type

Either RS232 or RS485; RS485 refers to half-duplex.

Speed

Serial speed (in bps) and e.g. 19200, 9600, ...

Frame

Frame format <data_bits><parity><stop_bits>, e.g. 8N1, 8E1, ...

Slave, Address, Size

Modbus parameters to address a specific measurement

Modbus function

Can be one of the following:

read holding registers
read input registers

read holding registers: function 0x03, read input registers: function 0x04.

Cast type

Can be one of the following:

uint16
uint32
int16
int32
float32
float32ByteSwap
int32ByteSwap
uint32ByteSwap

All readings should be Bigendian coded. ByteSwap is an exception, where the two Bigendian 16-bit halves are swapped: decoding is implemented as follows for example for float32ByteSwap: B0, B1, B2, B3 are the 4 received octets and float32(B2, B3, B0, B1) is the resulting float32 value.

In case cast type size in bits does not match with the correct amount of bits of the modbus query, then the measurement will not be acquired. As an example, this measure will not be acquired because the query return 16 bit, while casting requires 32 bit:

compartment1_temperature | 192.168.0.100:502 | 1 | 2048 | 1 | read input registers | uint32