Modbus Protocol Stack Cheatsheet
Modbus Protocol Stack Cheatsheet
OSI Layers Modbus RTU Modbus Plus Modbus TCP/IP ADU Application Data Unit
Application Layer (L7) Modbus Application Layer HDLC High level Data Link Control
Presentation Layer (L6) MB MODBUS Protocol
Session Layer (L5) MBAP MODBUS Application Protocol
Transport Layer (L4) TCP (Port 502) PDU Protocol Data Unit
Network Layer (L3) IP Modbus Master Modbus Client
Link Layer (L2) Master / Slave Modbus+ / HDLC Ethernet II / 802.3 / MAC / LLC Modbus Slave Modbus Server
Physical Layer (L1) RS-232 / RS-485 Physical Layer Ethernet Physical Layer
ADDRESS (Modbus Application Protocol Header) PDU (Protocol Data Unit) Error Check
TRANSACTION IDENTIFIER PROTOCOL IDENTIFIER LENGTH UNIT IDENTIFIER FUNCTION CODE DATA Modbus TCP
2 bytes 2 bytes 2 bytes 1 byte
RS232 / RS485 ADU = 253 bytes + Server address (1 byte) + CRC (2 bytes) = 256 bytes.
TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes.
The server simply echoes to the request the original function code. The server returns a code that is equivalent to the original function code from the
request PDU with its most significant bit set to logic 1 (Hex 0x80).
by Seda Narli
Modbus Transaction State Diagram Modbus Addressing Model
Wait for a MB
indication Receive MB indication Device Application Modbus Data Model Modbus PDU Addresses
Validate function
code
Read Input 0
Invalid 1
ExceptionCode = 1
.
Valid Discrete Input .
Validate data .
address 1
.
Invalid Coils .
ExceptionCode = 2 Read Coils 4
5
Valid
1 Read Registers 1
Validate data value 2
Input Registers .
.
Invalid
ExceptionCode = 3 1
Valid .
Holding Registers . Read Registers 54
Execute MB function 55
Invalid
ExceptionCode = 4, 5, 6
Mapping
Valid Application Specific Modbus Standard
Send Modbus exception Send Modbus
response response
by Seda Narli
Modbus Function Code Categories Modbus Function Codes
Code Hex Function Operation Type
127 01 01 Read Coils Reads the bit data (N bits)
Public Function Codes 02 02 Read Discrete Inputs Reads the bit data Single Bit
110 05 05 Write Single Coil Writes the bit data (one bit) Access
15 0F Write Multiple Coils Writes the bit data (N bits)
User Defined Function Codes
100 03 03 Read Holding Registers Reads the integer type/character type/status word floating-point type data (N words)
Public Function Codes
04 04 Read Input Register Reads the integer type/character type/status word floating-point type data
72 Data
User Defined Function Codes 06 06 Write Single Register Writes the integer type/character type/status word floating-point type data (one word)
Access
16 Bit Access
65 16 10 Write Multiple Registers Writes the integer type/character type/status word floating-point type data (N words)
Public Function Codes Modifies the contents of a specified holding register using a combination of an AND
22 16 Mask Write Register mask, and OR mask, and the register’s current contents.
1 23 17 Read/Write Multiple Registers One read operation and one write operation in a single Modbus transaction.
24 18 Read FIFO queue Reads the contents of a FIFO queue of register in a remote device.
20 14 Read File Record Performs a file record read. File Record
21 15 Write File Record Performs a file record write. Access
07 07 Read Exception Status Reads contents of eight Exception Status outputs in a remote device.
08 08 Diagnostic (Serial Line) Tests for the checking to communication and internal error.
11 0B Get Com event counter Gets status word and an event count from the remote device’s comm event counter.
Diagnostics
Gets status word, event count, message count, and field of event bytes from remote
12 0C Get Com Event Log device.
17 11 Report Server ID (Serial Line) Reads the current status and other information specific to a remote device.