Modbus Commands for CloudConnect Gateways

Modbus Commands for CloudConnect Gateways

Modbus is the communication protocol that CloudConnect gateways use to read data from instruments. The gateway sends a polling command to each instrument and the instrument replies with its readings. This article explains how the commands are built, which helps when you check instrument settings or read the gateway's logs.
You usually do not need to write commands yourself. When you add an instrument with the Configurator in TSC Connect, the commands are created from the instrument's model. See Using the Instrument Configurator.

Modbus RTU (RS-485)

Modbus RTU is a serial protocol. On V5 gateways it runs over the RS-485 port. An RTU command contains:
PartWhat it is
Slave ID (device address)Identifies the instrument on the RS-485 line. Each instrument has a unique address from 1 to 247.
Function codeThe operation to perform. Gateways usually use 03 (read holding registers) or 04 (read input registers).
Starting register addressThe first register to read.
Number of registersHow many consecutive registers to read.
CRCA checksum that lets the instrument detect transmission errors.
For example, the command 01 04 0000 004C F1FF reads 76 (hex 4C) input registers, starting at register 0, from the instrument with slave ID 1. F1FF is the CRC.
The RS-485 port settings must match the instrument: baud rate, parity (odd, even or none), data bits, stop bits and flow control.

Modbus TCP (Ethernet)

Modbus TCP carries Modbus commands over an Ethernet network. A TCP command is sent to the instrument's IP address. It starts with the MBAP header, followed by the slave (unit) ID, the function code, the starting register address and the number of registers. There is no CRC, because TCP checks for errors itself.
For example, the command 0001 0000 0006 02 03 0000 0006 has the header 000100000006, slave ID 2, function code 03, starting register 0 and 6 registers.

Modbus ASCII

In Modbus ASCII, each byte is sent as two ASCII characters. A message starts with a colon (:, hex 3A) and ends with a carriage return and line feed (hex 0D 0A). It contains the slave ID, function code, starting register address, number of registers and an LRC checksum.
To calculate the LRC:
  1. Add up all the data bytes in the message, before converting them to ASCII and without the colon and the final CR LF.
  2. Discard any carry beyond 8 bits.
  3. Take the two's complement of the result. This is the LRC byte.
The sum of all the bytes and the LRC is then zero.

Related articles

  1. Connecting Meters and Sensors to a CloudConnect V5 Gateway – wire RS-485, 4-20 mA and Modbus TCP instruments.
  2. Configuring Polling and Ports on a CloudConnect V5 Gateway – set the polling interval, analog channels and RS-485 port.
  3. CloudConnect Gateway Error Codes – what error codes 101, 102, 103 and 105 mean.
  4. Running Diagnostics and Viewing Logs on a CloudConnect V5 Gateway – check connectivity, instruments and logs on the gateway.
  5. Using the Instrument Configurator – configure an instrument on a gateway step by step.