Professional Documents
Culture Documents
Modbus Protocol
Modbus » Protocol Help Contents
Introduction
The Modbus Protocol was originally developed by Modicon (now part of Schneider Electric).
Modbus was developed as a
communication protocol for Modicon PLC Devices.
The original Modbus Protocol specification, published in 1979,
describes
Serial Communications where data is transmitted one bit at a time.
A later update to the standard, called Modbus TCP,
describes how to use Modbus in TCP/IP networks.
The rest of this article describes the Modbus protocol is more detail:
The structure of a modbus message is the same for both requests and responses:
The exact format of the message depends on the variant of Modbus protocol used:
Modbus ASCII
Modbus ASCII uses a subset of the ASCII character set to send modbus messages over Serial Communications.
Modbus ASCII messages start with the colon (:) character (ASCII 58).
Modbus ASCII messages end with carriage return
(ASCII 13) and line feed (ASCII 10) characters.
Between the start and end characters only hexadecimal characters 0 to 9 and
A to F are allowed.
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 1/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
The structure of a Modbus ASCII message is:
Where:
The Unit Address field is the PLC Address encoded as 2 hexadecimal characters.
The Message field is a Modbus PDU where each byte is encoded as 2 hexadecimal characters.
The maximum length of
the Message field is is 506 characters.
The LRC field is the Longitudinal Redundancy Check of the Address and Message fields.
The maximum Modbus ASCII message length is 513 characters.
Modbus RTU
Modbus RTU uses 8-bit Serial Communications to send Modbus messages.
Where:
The Unit Address field is the PLC Address encoded as single byte.
The Message field is a Modbus PDU.
The maximum length of the Message field is is 253 bytes.
The CRC field is the Cyclic Redundancy Check of the Unit Address and Message fields.
The maximum Modbus RTU message length is 256 bytes.
Modbus TCP
Modbus TCP uses a TCP/IP link to send and receive Modbus messages.
Where:
Unit Address
Note: Real Modbus TCP devices use the Unit Address field in different ways:
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 2/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
Modbus RTU over TCP is a non-standard variant of Modbus TCP that includes the CRC from the Modbus RTU message.
Where:
Modbus PDU
The Modbus Protocol supports these PDU:
Modbus Read Coils, function code 01, reads between 1 and 2000 output coils (bits) from the PLC.
The normal response varies in length from 3 bytes up to 252 bytes depending on the number of coils requested:
Note: The total number of bytes returned is 2 + (CoilCount + 7) / 8, where CoilCount is the number of coils requested.
For
example a request for 1 coil, will return 3 bytes.
A request for 8 coils will also return 3 bytes.
A request for 9 coils will
return 4 bytes.
The largest request possible is for 2000 coils, which will return 252 bytes.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 3/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
Example:
Read 12 coils starting at 00033 from a PLC at address 2.
Response with coils 00040 and 00042 set and all others
clear :
Request Response
Modbus 3A 30 32 30 31 30 30 32 30 30 30 30 43 44 3A 30 32 30 31 30 32 38 30 30 32 37
ASCII 31 0D 0A 39 0D 0A
Modbus 02 01 00 20 00 0C 3D F6 02 01 02 80 02 1D FD
RTU
Modbus 00 05 00 00 00 06 02 01 00 20 00 0C 00 05 00 00 00 05 02 01 02 80 02
TCP
Note: The PDU part of each request and response is shown in Blue.
Modbus Read Discrete Inputs, function code 02, reads between 1 and 2000 inputs from the PLC.
The normal response varies in length from 3 bytes up to 252 bytes depending on the number of inputs requested:
Note: The total number of bytes returned is 2 + (InputCount + 7) / 8. InputCount is the number of inputs requested.
For
example a request for 1 input, will return 3 bytes.
A request for 8 inputs will also return 3 bytes.
A request for 9 inputs will
return 4 bytes.
The largest request possible is for 2000 inputs, which will return 252 bytes.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
Example:
Read 16 inputs starting at 10501 from a PLC at address 1.
Response with inputs 10501 and 10503 set and all
others clear :
Request Response
Modbus 3A 30 31 30 32 30 31 46 34 30 30 32 30 45 3A 30 31 30 32 30 32 30 35 30 30 46
ASCII 38 0D 0A 36 0D 0A
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 4/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
Modbus 01 02 01 F4 00 20 39 DC 01 02 02 05 00 BA E8
RTU
Modbus 00 0A 00 00 00 06 01 02 01 F4 00 20 00 0A 00 00 00 05 01 02 02 05 00
TCP
Note: The PDU part of each request and response is shown in Blue.
Modbus Read Holding Registers, function code 03, reads between 1 and 125 holding registers from the PLC.
The normal response varies in length from 4 bytes up to 252 bytes depending on the number of holding registers requested:
Note: The total number of bytes returned is 2 + 2 * RegisterCount, where RegisterCount is the number of holding
registers requested.
For example a request for 1 holding register, will return 4 bytes.
A request for 2 holding registers will
return 6 bytes.
A request for 125 holding registers will return 252 bytes.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
Example:
Read 2 holding registers starting at address 40601 from a PLC at address 1.
Response returns register 40601
value 1000, and register 40602 value 5000:
Request Response
Modbus 3A 30 31 30 33 30 32 35 38 30 30 30 3A 30 31 30 33 30 34 30 33 45 38 31 33 38
ASCII 32 41 30 0D 0A 38 37 32 0D 0A
Modbus 01 03 02 58 00 02 44 60 01 03 04 03 E8 13 88 77 15
RTU
Modbus 00 0F 00 00 00 06 01 03 02 58 00 02 00 0F 00 00 00 07 01 03 04 03 E8 13 88
TCP
Note: The PDU part of each request and response is shown in Blue.
Modbus Read Input Registers, function code 04, reads between 1 and 125 input registers from the PLC.
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 5/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
The normal response varies in length from 4 bytes up to 252 bytes depending on the number of input registers requested:
Note: The total number of bytes returned is 2 + 2 * RegisterCount, where RegisterCount is the number of input registers
requested.
For example a request for 1 input register, will return 4 bytes.
A request for 2 input registers will return 6 bytes.
A request for 125 input registers will return 252 bytes.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
Example:
Read 2 input registers starting at address 30201 from a PLC at address 1.
Response returns register 30201 value
10000, and register 30202 value 50000:
Request Response
Modbus 3A 30 31 30 34 30 30 43 38 30 30 30 3A 30 31 30 34 30 34 32 37 31 30 43 33 35
ASCII 32 33 31 0D 0A 30 41 44 0D 0A
Modbus 01 04 00 C8 00 02 F0 35 01 04 04 27 10 C3 50 A0 39
RTU
Modbus 00 14 00 00 00 06 01 04 00 C8 00 02 00 14 00 00 00 07 01 04 04 27 10 C3 50
TCP
Note: The PDU part of each request and response is shown in Blue.
Modbus Write Single Coil, function code 05, writes a single coil to the PLC.
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 6/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
If the PLC detects an error, for example an address that is not available, an error response will be sent:
Request Response
Modbus 3A 30 31 30 35 30 30 36 34 46 46 30 30 3A 30 31 30 35 30 30 36 34 46 46 30 30
ASCII 39 37 0D 0A 39 37 0D 0A
Modbus 01 05 00 64 FF 00 CD E5 01 05 00 64 FF 00 CD E5
RTU
Modbus 00 19 00 00 00 06 01 05 00 64 FF 00 00 19 00 00 00 06 01 05 00 64 FF 00
TCP
Note: The PDU part of each request and response is shown in Blue.
Modbus Write Single Register, function code 06, writes a single register to the PLC.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
Request Response
Modbus 3A 30 31 30 36 30 30 36 34 33 41 39 38 3A 30 31 30 36 30 30 36 34 33 41 39 38
ASCII 43 33 0D 0A 43 33 0D 0A
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 7/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
Modbus 01 06 00 64 3A 98 98 DB 01 06 00 64 3A 98 98 DB
RTU
Modbus 00 1E 00 00 00 06 01 06 00 64 3A 98 00 1E 00 00 00 06 01 06 00 64 3A 98
TCP
Note: The PDU part of each request and response is shown in Blue.
If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:
Example: In the PLC at address 28, set register 40101 to 1000 and register 40102 to 2000.
Request Response
Modbus 3A 31 43 31 30 30 30 36 34 30 30 30 32 30 34 30 33 3A 31 43 31 30 30 30 36 34 30
ASCII 45 38 30 37 44 38 41 30 0D 0A 30 30 32 36 45 0D 0A
Modbus 1C 10 00 64 00 02 04 03 E8 07 D8 19 02 1C 10 00 64 00 02 03 9A
RTU
Modbus 00 23 00 00 00 0B 1C 10 00 64 00 02 04 03 E8 07 D8 00 23 00 00 00 06 1C 10 00 64
TCP 00 02
Note: The PDU part of each request and response is shown in Blue.
Code Description
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 8/9
12/8/21, 11:27 AM Modbus Protocol Overview with Examples
01h Illegal function
02h Illegal data address
03h Illegal data value
04h Slave device failure
Further Information
Modbus Data Address Format
To learn how modbus data addresses are presented in human readable form.
Modbus Driver
Glossary
Fernhill SCADA Version 3.78 (20211130.3). Copyright © 2012-2021 Fernhill Software Ltd: All rights reserved.
https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html#dataTypes 9/9