Modbus/TCP Module Basics

Description

Modbus is available in masters as an interface with the following features:

  • Read/write process data

  • Port configuration

  • Port/device diagnostics

  • Read/write ISDU data

Access is via the TCP/IP interface using the IP address of the device and Port 502 (example: 192.168.1.1:502). The response time depends on the data written/read.

Structure of a Modbus/TCP message

A Modbus/TCP message is structured as follows:

Modbus/TCP message structure

Byte 0

Byte 1

Byte 2

Byte 3

Byte 4

Byte 5

Byte 6

Byte 7

Byte 8

Byte 9…n

Transaction ID

Protocol ID

Length

Unit ID

Function Code

Databyte 1

Databyte 2…n

MBAP header

PDU

Modbus/TCP message

The protocol ID must be 0, as it indicates that the message is a Modbus message.

The Unit ID can be arbitrary. It is not used because the IP address already identifies a device. But its value will be echoed back in the response.

General

  • All numbers are decimal numbers, unless they are specified with 0x = hexadecimal, e.g.: 0x1B.

  • All data is organized as UINT16 unless otherwise specified.

  • The length is organized in UINT16 by default, unless otherwise specified, e.g. length in [bytes] or bit length.

  • The mapping of the byte sequence uses Big Endianness, see example in Index 10.

Function Codes

The following function codes are implemented:

  • Read holding register (0x03)

  • Write several registers (0x10)

Error Responses

The following responses are reported in the event of an error:

Error Code

Description

0x00

No error. Last command successful.

0x01

Bad Function Code

0x02

Wrong Register Address

0x03

Invalid value

0x04

Slave error (IO-Link fails)

Even if the start register is valid, reading too many registers leads to Bad Register Address.

Slave errors occur when the IO-Link interface triggers errors.