Messages

All Modbus TCP messages consist of an MBAP header (Modbus Application Protocol), a function code, and a data payload.

The MBAP header contains the following fields:

Modbus Application Protocol Header

Field

Length (Bytes)

Description

Transaction ID

2

Used for transaction pairing. The Modbus Client sets the value and the Server (the sensor) copies the value into its responses.

Protocol ID

2

Always set to 0.

Length

2

Byte count of the rest of the message, including the Unit identifier and data fields.

Unit ID

1

Used for intra-system routing purpose. The Modbus Client sets the value and the Server (the sensor) copies the value into its responses.

Modbus Application Protocol Specification describes the standard function codes in detail. Gocator supports the following function codes:

Modbus Function Code

Function Code

Name

Data Size (bits)

Description

3

Read Holding Registers

16

Read multiple data values from the sensor.

4

Read Input Registers

16

Read multiple data values from the sensor.

6

Write Single Register

16

Send a command or parameter to the sensor.

16

Write Multiple Registers

16

Send a command and parameters to the sensor.

The data payload contains the registers that can be accessed by Modbus TCP messages. If a message accesses registers that are invalid, a reply with an exception is returned. Modbus Application Protocol Specification defines the exceptions and describes the data payload format for each function code.

The sensor data includes 16-bit, 32-bit, and 64-bit data. All data are sent in big endian format, with the 32-bit and 64-bit data spread out into two and four consecutive registers.

32-bit Data Format

Register

Name

Bit Position

0

32-bit Word 1

31 .. 16

1

32-bit Word 0

15 .. 0

64-bit Data Format

Register

Name

Bit Position

0

64-bit Word 3

63 .. 48

1

64-bit Word 2

47 .. 32

2

64-bit Word 1

31 .. 16

3

64-bit Word 0

15 .. 0