Frames, the data model, register addressing, and function codes.
Updated 2026-09-27
This reference goes one level deeper than our quick introduction. It covers how a Modbus message is built, how the data model works, how registers are addressed, what every exception code means, and the byte-level layout of every public function code.
Introduction
Modbus is an application layer protocol. It defines the messages that two devices exchange, but not the wire those messages travel on. It uses a client/server architecture: a client (typically a SCADA, HMI, or PLC) sends a request, and a server (a PLC, meter, drive, or I/O module) answers it.
Modbus is currently carried over:
A variety of serial interfaces, including RS-232, RS-422, and RS-485
Modbus Plus, a token-passing network using HDLC
TCP/IP over 802.3 Ethernet, known as Modbus TCP
Modbus communication stack
The Modbus application layer sits on top. Serial Modbus and Modbus Plus carry it directly, while Modbus TCP wraps it in TCP and IP before it goes out over Ethernet.
Client and Server Protocol
Modbus is a client/server protocol. The client starts every transaction with a request, and the server answers with a response. A server never sends data on its own.
Frame Structure
Every Modbus message is a frame made of four parts:
additional address
function code
data
error check.
General Modbus frame
The whole frame is the Application Data Unit (ADU). The function code and data together make up the Protocol Data Unit (PDU).
The PDU stays exactly the same no matter what network it travels across. The ADU changes to suit the network: serial adds a server address and a CRC or LRC, while TCP adds something called an MBAP header and relies on TCP for error checking.
This guide focuses on the PDU, with some supporting information about ADUs on different networks.
Protocol Data Unit
Function code field
A function code is how a client tells the server what to do — it's the verb that explains whether a register is to be written to, read from, or diagnostic data is to be retrieved. The function code is one byte, with allowed values of 1 to 255. Codes 128 to 255 are reserved for exception responses, and a function code of 0 is invalid. Some function codes also carry sub-function codes, which let a single function code support several different actions.
Data field
The data field sent from client to server holds any extra information the server needs to carry out the requested function, such as a starting address and a quantity. If the function needs no extra information, the data field can be empty.
Three PDU types
The client always sends the request PDU, and if the server is able to successfully process the request, it returns the response PDU with the data field filled in with information that corresponds to the function code specified in the request. If the server has an error while processing the request, the server returns the exception response so the client can understand what went wrong and can handle it.
The structure of the three PDU types is listed in the table below:
PDU
Field
Size
Request (mb_req_pdu)
Function code
1 byte
Data, contents depend on the function code
n bytes
Response (mb_rsp_pdu)
Function code
1 byte
Data, contents depend on the function code
n bytes
Exception response (mb_excep_rsp_pdu)
Exception function code, same function code from request but leading bit set to 1
1 byte
Exception code, from the list of Modbus exception codes
1 byte
PDU and ADU size
A Modbus PDU is limited to 253 bytes, because that was the largest size that could travel on the original serial network, where the whole ADU was capped at 256 bytes.
The MBAP header on Modbus TCP is made of a 2-byte transaction ID, a 2-byte protocol ID (always 0), a 2-byte length, and a 1-byte unit ID.
Byte order
Modbus uses big-endian encoding for addresses and data. When a 16-bit value is sent, the most significant byte goes first. For example, the value 0x1234 is sent as 0x12 followed by 0x34. No byte order is specified for values larger than 16 bits. If a device vendor has a 32-bit or 64-bit number stored across multiple registers, the word order for how that number is stored is left up to the manufacturer, and you'll need to consult their documentation.
The Modbus data model
Modbus defines four tables:
Table
Size
Access
Discrete inputs
Single bit
Read only
Coils
Single bit
Read/write
Input registers
16 bits
Read only
Holding registers
16 bits
Read/write
The data a device actually holds in memory is mapped to one or more of these tables. The Modbus specification does not say how a device must store its data. The device only has to provide a way to map its data to the tables.
For example, you'll see later that a client can use function code 4 to read input register 3, and function code 2 to read discrete input 7. It is quite possible that input register 3 and discrete input 7 point at the same physical bits in the device's memory.
Some devices overlap the tables on the same memory:
Modbus tables overlapping shared blocks of device memory
Others keep each table in its own area of memory:
Modbus tables mapped to separate device memory
Always check the device's documentation to find out which approach it uses.
⚙ Note for the Field
Modicon PLCs, which were the first to use what became the Modbus protocol, adopted a convention of prefixing every Modbus address with a single number to indicate what Modbus table that address belonged too. This is not part of the Modbus standard, but has become very common among Modbus servers to follow that same convention in their documentation. The convention is as follows:
Prefix
Table
Example
0
Coils
000001
1
Discrete Inputs
100001
3
Input registers
300001
4
Holding registers
400001
Modbus register addressing
The Modbus protocol requires a PDU to reference a register between 0 and 65535. However, in the data model, registers are numbered 1 to n. That means the register number sent in the PDU is one less than the data model register it refers to. For example, holding register 1 is requested as address 0x0000 in the PDU.
⚙ Note for the Field
Manufacturers and applications may break from the convention used in the Modbus specification when presenting register addresses to users.
In data sheets for Modbus servers, the manufacturer may list the first Modbus element at address 0, because they're referring to the value of the address sent in the PDU. Other times, they may list the first address as 400001, where the "4" prefix they use represents a holding register and "1" represents the first holding register. Usually when manufacturers list registers with a prefix, the PDU should not include the prefix. However, sometimes, manufacturers do expect that prefix in the PDU.
Always perform physical testing on the device you're working with to sort through these nuances.
Modbus response codes
On success, the server's response includes the same function code the client sent in its request.
On error, the server's response includes the client's function code with its first bit set to 1 (function code | 0x80). For example, a failed read of holding registers (0x03) comes back as 0x83. An exception code follows the function code, and is one of these:
Code
Name
Meaning
0x01
Invalid function
The server does not support the function code
0x02
Invalid register address
The requested address, or address plus quantity, is outside the server's range
0x03
Invalid data value
A value in the request data is not allowed, such as a bad quantity
0x04
Server device failure
An unrecoverable error happened while the server was carrying out the request
0x05
Acknowledge
The server accepted the request but needs a long time to finish it
0x06
Server busy
The server is busy with a long-running command; the client should retry later
0x08
Memory parity error
The server found a parity error in its memory while reading a file record
0x0A
Gateway path unavailable
A gateway could not set up a path to the target device
0x0B
Gateway target device failed to respond
A gateway got no response from the target device
Function code categories
Modbus function codes fall into three categories:
Public function codes are defined, documented, and validated by the Modbus organization, and are guaranteed to be unique.
User-defined function codes are the ranges 65 to 72 and 100 to 110. Vendors can use them for their own functions, with no guarantee of uniqueness.
Reserved function codes are used by some companies for legacy products and are not available for public use.
Public function code definitions
Each function below lists a description, the request fields, the success response fields, the error response fields, and an example request and response. Examples show the PDU only, broken down into request and response fields. Values are hexadecimal unless marked as ASCII text.
01 (0x01) Read Coils
Reads the on/off status of 1 to 2000 contiguous coils. The response packs coil values into bytes, one bit per coil, with the lowest coil in the lowest bit of the first byte. Unused bits in the final byte are padded with zeros.
Request
Field
Size
Value
Function code
1 byte
0x01
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of coils
2 bytes
0x0001 to 0x07D0 (1 to 2000)
Success Response
Field
Size
Value
Function code
1 byte
0x01
Byte count
1 byte
N = quantity of coils / 8 (rounded up).
Coil Status Byte 1
1 byte
Packed coil bits
Coil Status Byte 2
1 byte
Packed coil bits
...
Coil Status Byte N
1 byte
Packed coil bits
Error Response
Field
Size
Value
Error code
1 byte
0x81
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read coils 20-39 in the server.
Data In Server Before Read
Modbus Address
Value
Coil 20
0x01 (ON)
Coil 21
0x00 (OFF)
Coil 22
0x01 (ON)
Coil 23
0x01 (ON)
Coil 24
0x00 (OFF)
Coil 25
0x00 (OFF)
Coil 26
0x01 (ON)
Coil 27
0x01 (ON)
Coil 28
0x01 (ON)
Coil 29
0x01 (ON)
Coil 30
0x00 (OFF)
Coil 31
0x01 (ON)
Coil 32
0x00 (OFF)
Coil 33
0x01 (ON)
Coil 34
0x01 (ON)
Coil 35
0x00 (OFF)
Coil 36
0x01 (ON)
Coil 37
0x00 (OFF)
Coil 38
0x01 (ON)
Coil 39
0x01 (ON)
Request
Field
Size
Value
Function code
1 byte
0x01
Starting address
2 bytes
0x0013 (19)*
Quantity of coils
2 bytes
0x0014 (20)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x01
Byte count
1 byte
0x03 (3)
Coil Status Byte 1
1 byte
0b11001101 0xCD
Coil Status Byte 2
1 byte
0b01101011 0x6B
Coil Status Byte 3
1 byte
0b00001101 0x0D
02 (0x02) Read Discrete Inputs
Reads the on/off status of 1 to 2000 contiguous discrete inputs. Values are packed one bit per input, the same way as Read Coils.
Request
Field
Size
Value
Function code
1 byte
0x02
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of inputs
2 bytes
0x0001 to 0x07D0 (1 to 2000)
Success Response
Field
Size
Value
Function code
1 byte
0x02
Byte count
1 byte
N = quantity of inputs / 8 (rounded up).
Discrete Input Status Byte 1
1 byte
Packed input bits
Discrete Input Status Byte 2
1 byte
Packed input bits
...
Discrete Input Status Byte N
1 byte
Packed input bits
Error Response
Field
Size
Value
Error code
1 byte
0x82
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read discrete inputs 197-218 in the server.
Data In Server Before Read
Modbus Address
Value
Discrete input 197
0x00 (OFF)
Discrete input 198
0x00 (OFF)
Discrete input 199
0x01 (ON)
Discrete input 200
0x01 (ON)
Discrete input 201
0x00 (OFF)
Discrete input 202
0x01 (ON)
Discrete input 203
0x00 (OFF)
Discrete input 204
0x01 (ON)
Discrete input 205
0x01 (ON)
Discrete input 206
0x01 (ON)
Discrete input 207
0x00 (OFF)
Discrete input 208
0x01 (ON)
Discrete input 209
0x01 (ON)
Discrete input 210
0x00 (OFF)
Discrete input 211
0x01 (ON)
Discrete input 212
0x01 (ON)
Discrete input 213
0x01 (ON)
Discrete input 214
0x00 (OFF)
Discrete input 215
0x01 (ON)
Discrete input 216
0x00 (OFF)
Discrete input 217
0x01 (ON)
Discrete input 218
0x01 (ON)
Request
Field
Size
Value
Function code
1 byte
0x02
Starting address
2 bytes
0x00C4 (196)*
Quantity of inputs
2 bytes
0x0016 (22)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x02
Byte count
1 byte
0x03 (3)
Input Status Byte 1
1 byte
0b10101100 0xAC
Input Status Byte 2
1 byte
0b11011011 0xDB
Input Status Byte 3
1 byte
0b00110101 0x35
03 (0x03) Read Holding Registers
Reads 1 to 125 contiguous holding registers. In the response data field, each register is two bytes, with the high byte of the register value transmitted first.
Request
Field
Size
Value
Function code
1 byte
0x03
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of registers
2 bytes
0x0001 to 0x007D (1 to 125)
Success Response
Field
Size
Value
Function code
1 byte
0x03
Byte count
1 byte
2 x N, where N = quantity of registers
Register Value 1
2 bytes
data with high byte followed by low byte
Register Value 2
2 bytes
data with high byte followed by low byte
...
Register Value N
2 bytes
data with high byte followed by low byte
Error Response
Field
Size
Value
Error code
1 byte
0x83
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read holding registers 108-110 in the server.
Data In Server Before Read
Modbus Address
Value
Holding register 108
0x022B (555)
Holding register 109
0x0000 (0)
Holding register 110
0x0064 (100)
Request
Field
Size
Value
Function code
1 byte
0x03
Starting address
2 bytes
0x006B (107)*
Quantity of registers
2 bytes
0x0003 (3)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x03
Byte count
1 byte
0x06 (6)
Register 108 value
2 bytes
0x022B (555)
Register 109 value
2 bytes
0x0000 (0)
Register 110 value
2 bytes
0x0064 (100)
04 (0x04) Read Input Registers
Reads 1 to 125 contiguous input registers. In the response data field, each register is two bytes, with the high byte of the register value transmitted first.
Request
Field
Size
Value
Function code
1 byte
0x04
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of input registers
2 bytes
0x0001 to 0x007D (1 to 125)
Success Response
Field
Size
Value
Function code
1 byte
0x04
Byte count
1 byte
2 x N, where N = quantity of input registers
Analog Input Status 1
2 bytes
data with high byte followed by low byte
Analog Input Status 2
2 bytes
data with high byte followed by low byte
...
Analog Input Status N
2 bytes
data with high byte followed by low byte
Error Response
Field
Size
Value
Error code
1 byte
0x84
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read one input register, at address 9, in the server.
Data In Server Before Read
Modbus Address
Value
Input register 9
0x000A (10)
Request
Field
Size
Value
Function code
1 byte
0x04
Starting address
2 bytes
0x0008 (8)*
Quantity of input registers
2 bytes
0x0001 (1)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x04
Byte count
1 byte
0x02 (2)
Input register 9 value
2 bytes
0x000A (10)
05 (0x05) Write Single Coil
Sets a single coil ON or OFF. 0xFF00 turns the coil on and 0x0000 turns it off; any other value is invalid. The normal response echoes the request.
Request
Field
Size
Value
Function code
1 byte
0x05
Output address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Output value
2 bytes
0x0000 (OFF) or 0xFF00 (ON)
Success Response
Field
Size
Value
Function code
1 byte
0x05
Output address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Output value
2 bytes
0x0000 (OFF) or 0xFF00 (ON)
Error Response
Field
Size
Value
Error code
1 byte
0x85
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to turn ON the coil at address 173 in the server.
Request
Field
Size
Value
Function code
1 byte
0x05
Output address
2 bytes
0x00AC (172)
Output value
2 bytes
0xFF00 (ON)
Success Response
Field
Size
Value
Function code
1 byte
0x05
Output address
2 bytes
0x00AC (172)
Output value
2 bytes
0xFF00 (ON)
Data In Server After Write
Modbus Address
Value
Coil 173
0x01 (ON)
06 (0x06) Write Single Register
Writes one holding register. The normal response echoes the request. In the request and response data field, the register is two bytes, with the high byte of the register value transmitted first.
Request
Field
Size
Value
Function code
1 byte
0x06
Register address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Register value
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Success Response
Field
Size
Value
Function code
1 byte
0x06
Register address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Register value
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Error Response
Field
Size
Value
Error code
1 byte
0x86
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to write the value 3 to the holding register at address 2 in the server.
Request
Field
Size
Value
Function code
1 byte
0x06
Register address
2 bytes
0x0001 (1)
Register value
2 bytes
0x0003 (3)
Success Response
Field
Size
Value
Function code
1 byte
0x06
Register address
2 bytes
0x0001 (1)
Register value
2 bytes
0x0003 (3)
Data In Server After Write
Modbus Address
Value
Holding register 2
0x0003 (3)
07 (0x07) Read Exception Status (serial line only)
Reads eight exception status outputs from a remote device. What each bit means is defined by the device vendor.
Request
Field
Size
Value
Function code
1 byte
0x07
Success Response
Field
Size
Value
Function code
1 byte
0x07
Output data
1 byte
0x00 to 0xFF (0 to 255)
Error Response
Field
Size
Value
Error code
1 byte
0x87
Exception code
1 byte
0x01 or 0x04
Example
Client requests to read the server’s eight exception status outputs.
Request
Field
Size
Value
Function code
1 byte
0x07
Success Response
Field
Size
Value
Function code
1 byte
0x07
Output data
1 byte
0b01101101 0x6D
Fictional Vendor Exception Status Definition
Exception
Bit Index
Status
Digital Input Fault
0
Active
Digital Output Fault
1
Inactive
Analog Input Fault
2
Active
Analog Output Fault
3
Active
Network Fault
4
Inactive
Memory Fault
5
Active
Program Fault
6
Active
Firmware Fault
7
Inactive
08 (0x08) Diagnostics (serial line only)
Runs a set of tests on the communication link between client and server, selected by a 2-byte sub-function code. Common sub-functions include 0x00 Return Query Data, 0x01 Restart Communications Option, 0x02 Return Diagnostic Register, 0x04 Force Listen Only Mode, and 0x0A Clear Counters and Diagnostic Register. For a detailed reference of all sub function codes, see Modbus Application Protocol Specification.
Request
Field
Size
Value
Function code
1 byte
0x08
Sub-function
2 bytes
See above
Data
depends on sub-function
depends on sub-function
Success Response
Field
Size
Value
Function code
1 byte
0x08
Sub-function
2 bytes
Same as request
Data
depends on sub-function
depends on sub-function
Error Response
Field
Size
Value
Error code
1 byte
0x88
Exception code
1 byte
0x01, 0x03, or 0x04
Example
Client requests that the server run Return Query Data, an echo test using the value 0xA537. The server returns the same value in its response.
Request
Field
Size
Value
Function code
1 byte
0x08
Sub-function
2 bytes
0x0000
Data
2 bytes
0xA537
Success Response
Field
Size
Value
Function code
1 byte
0x08
Sub-function
2 bytes
0x0000
Data
2 bytes
0xA537
11 (0x0B) Get Comm Event Counter (serial line only)
Returns a status word and an event count from the server's communication event counter. The counter increases once for every successfully completed message. The status word indicates if the server is currently processing a request (busy), or if it is waiting for a request (ready).
Request
Field
Size
Value
Function code
1 byte
0x0B
Success Response
Field
Size
Value
Function code
1 byte
0x0B
Status
2 bytes
0x0000 (ready) or 0xFFFF (busy)
Event count
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Error Response
Field
Size
Value
Error code
1 byte
0x8B
Exception code
1 byte
0x01 or 0x04
Example
Client requests to read the communication event counter in the server. The server reports a busy status and an event count of 264.
Request
Field
Size
Value
Function code
1 byte
0x0B
Success Response
Field
Size
Value
Function code
1 byte
0x0B
Status
2 bytes
0xFFFF (busy)
Event count
2 bytes
0x0108 (264)
12 (0x0C) Get Comm Event Log (serial line only)
Returns a status word, event count, message count, and a field of event bytes from the server.
The message count is the number of messages processed by the server since its last restart, clear counters operation, or power-up. It is identical to the count returned by 08 (0x08) Diagnostics, sub-function 0x0B Return Bus Message Count.
The event bytes field contains 0 to 64 bytes. Each byte records the status of one Modbus send or receive operation in the server. Events are stored in chronological order, with byte 0 containing the most recent event. Each new event byte pushes out the oldest byte from the field.
Request
Field
Size
Value
Function code
1 byte
0x0C
Success Response
Field
Size
Value
Function code
1 byte
0x0C
Byte count
1 byte
N = 6 + number of event bytes (0 to 64).
Status
2 bytes
0x0000 or 0xFFFF
Event count
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Message count
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Events
N − 6 bytes
Event log
Error Response
Field
Size
Value
Error code
1 byte
0x8C
Exception code
1 byte
0x01 or 0x04
Interpreting the Event Byte
Each event byte identifies a receive event, a send event, entry into listen-only mode, or a communication restart. Bit 0 is the least significant bit.
Remote Device Modbus Receive Event
The server records this event when a request is received, before processing it. Bit 7 is always 1. The other used bits are set to 1 when their corresponding condition is true.
Status
Bit Index
Not used
0
Communication error
1
Not used
2
Not used
3
Character overrun
4
Currently in listen-only mode
5
Broadcast received
6
Receive event identifier (always 1)
7
Remote Device Modbus Send Event
The server records this event when it finishes processing a request, whether it returns a normal response, an exception response, or no response. Bit 7 is always 0 and bit 6 is always 1. The remaining bits are set to 1 when their corresponding condition is true.
Status
Bit Index
Read exception sent (exception codes 0x01 to 0x03)
0
Server abort exception sent (exception code 0x04)
1
Server busy exception sent (exception codes 0x05 to 0x06)
2
Server program NAK exception sent (exception code 0x07)
3
Write timeout error occurred
4
Currently in listen-only mode
5
Send event identifier (always 1)
6
Send event identifier (always 0)
7
Remote Device Entered Listen-Only Mode
An event byte with the value 0x04 indicates that the server entered listen-only mode. This is a complete event-byte value, not an individual status bit.
Remote Device Initiated Communication Restart
An event byte with the value 0x00 (0) indicates that the server's communications port was restarted.
Example
Client requests to read the communication event log in the server. The server returns a ready status, an event count of 264, a message count of 289, and two event bytes: 0x04 and 0x00.
Request
Field
Size
Value
Function code
1 byte
0x0C
Success Response
Field
Size
Value
Function code
1 byte
0x0C
Byte count
1 byte
0x08 (8)
Status
2 bytes
0x0000 (ready)
Event count
2 bytes
0x0108 (264)
Message count
2 bytes
0x0121 (289)
Event Byte 1
1 byte
0x04 (listen mode)
Event Byte 2
1 byte
0x00 (Communications Restart)
15 (0x0F) Write Multiple Coils
Sets each coil in a sequence of 1 to 1968 coils ON or OFF. Values are packed one bit per coil, like 01 (0x01) Read Coils.
Request
Field
Size
Value
Function code
1 byte
0x0F
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of outputs
2 bytes
0x0001 to 0x07B0 (1 to 1968)
Byte count
1 byte
N = quantity of coils / 8 (rounded up).
Coil Status Byte 1
1 byte
Packed coil bits
Coil Status Byte 2
1 byte
Packed coil bits
...
Coil Status Byte N
1 byte
Packed coil bits
Success Response
Field
Size
Value
Function code
1 byte
0x0F
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of outputs
2 bytes
0x0001 to 0x07B0 (1 to 1968)
Error Response
Field
Size
Value
Error code
1 byte
0x8F
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to write coils 20-29 in the server.
Request
Field
Size
Value
Function code
1 byte
0x0F
Starting address
2 bytes
0x0013 (19)*
Quantity of outputs
2 bytes
0x000A (10)
Byte count
1 byte
0x02 (2)
Coil Status Byte 1
1 byte
0b11001101 0xCD
Coil Status Byte 2
1 byte
0b00000001 0x01
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x0F
Starting address
2 bytes
0x0013 (19)*
quantity of coils
2 bytes
0x000A (10)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Data In Server After Write
Modbus Address
Value
Coil 20
0x01 (ON)
Coil 21
0x00 (OFF)
Coil 22
0x01 (ON)
Coil 23
0x01 (ON)
Coil 24
0x00 (OFF)
Coil 25
0x00 (OFF)
Coil 26
0x01 (ON)
Coil 27
0x01 (ON)
Coil 28
0x01 (ON)
Coil 29
0x00 (OFF)
16 (0x10) Write Multiple Registers
Writes a block of 1 to 123 contiguous holding registers.
Request
Field
Size
Value
Function code
1 byte
0x10
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of registers
2 bytes
0x0001 to 0x007B (1 to 123)
Byte count
1 byte
2 x N, where N = quantity of registers
Register Value 1
2 bytes
data with high byte followed by low byte
Register Value 2
2 bytes
data with high byte followed by low byte
...
Register Value N
2 bytes
data with high byte followed by low byte
Success Response
Field
Size
Value
Function code
1 byte
0x10
Starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity of registers
2 bytes
0x0001 to 0x007B (1 to 123)
Error Response
Field
Size
Value
Error code
1 byte
0x90
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to write holding registers 2-3 in the server.
Request
Field
Size
Value
Function code
1 byte
0x10
Starting address
2 bytes
0x0001 (1)*
Quantity of registers
2 bytes
0x0002 (2)
Byte count
1 byte
0x04 (4)
Register 2 value
2 bytes
0x000A (10)
Register 3 value
2 bytes
0x0102 (258)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x10
Starting address
2 bytes
0x0001 (1)*
Quantity of registers
2 bytes
0x0002 (2)
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Data In Server After Write
Modbus Address
Value
Holding register 2
0x000A (10)
Holding register 3
0x0102 (258)
17 (0x11) Report Server ID (serial line only)
Reads the type, current status, and other device-specific information about a server.
Request
Field
Size
Value
Function code
1 byte
0x11
Success Response
Field
Size
Value
Function code
1 byte
0x11
Byte count
1 byte
N = server ID byte size + 1 run indicator byte + additional data byte size
Server ID
Device specific
Device specific
Run indicator status
1 byte
0x00 (off) or 0xFF (on)
Additional data
Device specific
Device specific
Error Response
Field
Size
Value
Error code
1 byte
0x91
Exception code
1 byte
0x01 or 0x04
Example
Client requests to read the server’s identification and run status. In this device-specific example, the server returns server ID 0x2A, a running status, and one byte of additional data.
Request
Field
Size
Value
Function code
1 byte
0x11
Success Response
Field
Size
Value
Function code
1 byte
0x11
Byte count
1 byte
0x03 (3)
Server ID
1 byte
0x2A (42)
Run indicator status
1 byte
0xFF (ON)
Additional data
1 byte
0x01
20 (0x14) Read File Record
Reads file records from the server.
A file is an organization of 10,000 records, addressed from 0x0000 to 0x270F (0 to 9999). Record numbers are used directly: for example, record 12 is addressed as 0x000C (12), without subtracting 1.
One request can read references. A reference is a pointer to a range of records within the file. If multiple references are included in a single request, they can read non-contiguous (separate) records in different files. However, a reference itself always refers to a contiguous (non-separate) range of records. Each reference is referred to as a 'sub-request' when included in a request and it is defined by a 7-byte format as follows:
Reference type: 1 byte, which must be 0x06 (6).
File number: 2 bytes.
Starting record number within the file: 2 bytes.
Record length: 2 bytes, specifying the number of registers to read.
The requested data, together with all other fields in the expected response, must fit within the maximum Modbus PDU length of 253 bytes. Request data lengths are measured in bytes, while record lengths are measured in registers.
The normal response contains one 'sub-response' for each 'sub-request'. The response data length (byte count) field gives the total combined number of bytes in all 'sub-responses'. Each 'sub-response' also contains its own byte count, followed by the reference type and the requested data.
Request
Field
Size
Value
Function code
1 byte
0x14
Byte count
1 byte
0x07 to 0xF5 (7 to 245)
Sub-request x, reference type
1 byte
0x06
Sub-request x, file number
2 bytes
0x0001 to 0xFFFF (1 to 65535)
Sub-request x, record number
2 bytes
0x0000 to 0x270F (0 to 9999)
Sub-request x, record length
2 bytes
N = Number of records to read, specified in register count
Success Response
Field
Size
Value
Function code
1 byte
0x14
Response data length
1 byte
0x07 to 0xF5 (7 to 245)
Sub-request x, file response length
1 byte
0x07 to 0xF5 (7 to 245)
Sub-request x, reference type
1 byte
0x06
Sub-request x, record data
N x 2 bytes
record data
Error Response
Field
Size
Value
Error code
1 byte
0x94
Exception code
1 byte
0x01, 0x02, 0x03, 0x04, or 0x08
Example
Client requests to read two registers from file 4, starting at record 1, and two registers from file 3, starting at record 9, in the server. Both reads are included in one request as two sub-requests.
Request
Field
Size
Value
Function code
1 byte
0x14
Byte count
1 byte
0x0E
Sub-request 1, reference type
1 byte
0x06
Sub-request 1, file number
2 bytes
0x0004
Sub-request 1, record number
2 bytes
0x0001
Sub-request 1, record length
2 bytes
0x0002
Sub-request 2, reference type
1 byte
0x06
Sub-request 2, file number
2 bytes
0x0003
Sub-request 2, record number
2 bytes
0x0009
Sub-request 2, record length
2 bytes
0x0002
Success Response
Field
Size
Value
Function code
1 byte
0x14
Response data length
1 byte
0x0C
Sub-request 1, file response length
1 byte
0x05
Sub-request 1, reference type
1 byte
0x06
Sub-request 1, record data
4 bytes
0D FE 00 20
Sub-request 2, file response length
1 byte
0x05
Sub-request 2, reference type
1 byte
0x06
Sub-request 2, record data
4 bytes
33 CD 00 40
21 (0x15) Write File Record
Writes records to files in the server's memory. See 20 (0x14) Read File Record for file nomenclature definitions. The normal response echoes the request.
Request
Field
Size
Value
Function code
1 byte
0x15
Request data length
1 byte
0x09 to 0xFB (9 to 251)
Sub-request x, reference type
1 byte
0x06
Sub-request x, file number
2 bytes
0x0001 to 0xFFFF (1 to 65535)
Sub-request x, record number
2 bytes
0x0000 to 0x270F (0 to 9999)
Sub-request x, record length
2 bytes
N = Number of records to write, specified in register count
Sub-request x, record data
2 X N bytes
record data
Success Response
Field
Size
Value
All fields
Same as request
Echo of the request
Error Response
Field
Size
Value
Error code
1 byte
0x95
Exception code
1 byte
0x01, 0x02, 0x03, 0x04, or 0x08
Example
Client requests to write three record values—0x06AF, 0x04BE, and 0x100D—to file 4, starting at record 7, in the server.
Request
Field
Size
Value
Function code
1 byte
0x15
Request data length
1 byte
0x0D
Reference type
1 byte
0x06
File number
2 bytes
0x0004
Record number
2 bytes
0x0007
Record length
2 bytes
0x0003
Record data
6 bytes
06 AF 04 BE 10 0D
Success Response
Field
Size
Value
Function code
1 byte
0x15
Request data length
1 byte
0x0D
Reference type
1 byte
0x06
File number
2 bytes
0x0004
Record number
2 bytes
0x0007
Record length
2 bytes
0x0003
Record data
6 bytes
06 AF 04 BE 10 0D
22 (0x16) Mask Write Register
Changes individual bits in one holding register using an AND mask and an OR mask. The result is: (current value AND And_Mask) OR (Or_Mask AND (NOT And_Mask)). The normal response echoes the request.
Request
Field
Size
Value
Function code
1 byte
0x16
Reference address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
And_Mask
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Or_Mask
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Success Response
Field
Size
Value
All fields
Same as request
Echo of the request
Error Response
Field
Size
Value
Error code
1 byte
0x96
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to apply And_Mask 0x00F2 and Or_Mask 0x0025 to the holding register at address 5 in the server. The server changes its current value from 0x0012 to 0x0017.
Data In Server Before Write
Modbus Address
Value
Holding register 5
Current Contents
0b00000000 00010010 0x0012 (18)
Request
Field
Size
Value
Function code
1 byte
0x16
Reference address
2 bytes
0x0004
And_Mask
2 bytes
0b00000000 11110010 0x00F2
Or_Mask
2 bytes
0b00000000 00100101 0x0025
Success Response
Field
Size
Value
Function code
1 byte
0x16
Reference address
2 bytes
0x0004
And_Mask
2 bytes
0b00000000 11110010 0x00F2
Or_Mask
2 bytes
0b00000000 00100101 0x0025
Data In Server After Write
Modbus Address
Value
Holding register 5
Current Contents
0b00000000 00010010
And_Mask
0b00000000 11110010
(1) (Current Contents And And_Mask)
0b00000000 00010010
Or_Mask
0b00000000 00100101
NOT And_Mask
0b11111111 00001101
(2) (Or_Mask AND (NOT And_Mask))
0b00000000 00000101
(1) (Current Contents And And_Mask)
0b00000000 00010010
(2) (Or_Mask AND (NOT And_Mask))
0b00000000 00000101
(1) OR (2)
0b00000000 00010111 0x0017 (23)
23 (0x17) Read/Write Multiple Registers
Performs one write and one read in a single transaction. The write is carried out before the read.
Request
Field
Size
Value
Function code
1 byte
0x17
Read starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity to read
2 bytes
0x0001 to 0x007D (1 to 125)
Write starting address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Quantity to write
2 bytes
0x0001 to 0x0079 (1 to 121)
Write byte count
1 byte
N = 2 x quantity to write
Write register values
N bytes
Values to write
Success Response
Field
Size
Value
Function code
1 byte
0x17
Byte count
1 byte
2 x N, where N = quantity to read
Register Value 1
2 bytes
data with high byte followed by low byte
Register Value 2
2 bytes
data with high byte followed by low byte
...
Register Value N
2 bytes
data with high byte followed by low byte
Error Response
Field
Size
Value
Error code
1 byte
0x97
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to write holding registers 15-17 and read holding registers 4-9 in the server. The value written to each register is 0x00FF. Both operations are included in one request, and the server performs the write before the read.
Data In Server Before Read
Server values after the write. Registers 4 to 9 are returned in the response; registers 15 to 17 contain the values written by the request.
Modbus Address
Value
Holding register 4
0x00FE (254)
Holding register 5
0x0ACD (2765)
Holding register 6
0x0001 (1)
Holding register 7
0x0003 (3)
Holding register 8
0x000D (13)
Holding register 9
0x00FF (255)
Holding register 15
0x00FF (255)
Holding register 16
0x00FF (255)
Holding register 17
0x00FF (255)
Request
Field
Size
Value
Function code
1 byte
0x17
Read starting address
2 bytes
0x0003 (3)*
Quantity to read
2 bytes
0x0006 (6)
Write starting address
2 bytes
0x000E (14)*
Quantity to write
2 bytes
0x0003 (3)
Write byte count
1 byte
0x06
Register 15 value
2 bytes
0x00FF
Register 16 value
2 bytes
0x00FF
Register 17 value
2 bytes
0x00FF
* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.
Success Response
Field
Size
Value
Function code
1 byte
0x17
Byte count
1 byte
0x0C (12)
Register 4 value
2 bytes
0x00FE
Register 5 value
2 bytes
0x0ACD
Register 6 value
2 bytes
0x0001
Register 7 value
2 bytes
0x0003
Register 8 value
2 bytes
0x000D
Register 9 value
2 bytes
0x00FF
24 (0x18) Read FIFO Queue
Reads the contents of a first-in, first-out queue of registers. The queue count register is returned first, followed by up to 31 queued values.
Request
Field
Size
Value
Function code
1 byte
0x18
FIFO pointer address
2 bytes
0x0000 to 0xFFFF (0 to 65535)
Success Response
Field
Size
Value
Function code
1 byte
0x18
Byte count
2 bytes
N = 2 FIFO count bytes + 2 x FIFO count.
FIFO count
2 bytes
0x0000 to 0x001F (0 to 31)
FIFO values
N − 2 bytes
Queued register data
Error Response
Field
Size
Value
Error code
1 byte
0x98
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read the FIFO queue in the server using PDU pointer address 0x04DE. The server returns a FIFO count of two followed by the queued values 0x01B8 and 0x1284.
Data In Server Before Read
The FIFO pointer 0x04DE addresses the count register; the two queued register values follow it.
Modbus Address
Value
Holding register 1247 — FIFO count
0x0002 (2)
Holding register 1248 — FIFO value 1
0x01B8 (440)
Holding register 1249 — FIFO value 2
0x1284 (4740)
Request
Field
Size
Value
Function code
1 byte
0x18
FIFO pointer address
2 bytes
0x04DE
Success Response
Field
Size
Value
Function code
1 byte
0x18
Byte count
2 bytes
0x0006 (6)
FIFO count
2 bytes
0x0002
FIFO value 1
2 bytes
0x01B8
FIFO value 2
2 bytes
0x1284
43 (0x2B) Encapsulated Interface Transport
Tunnels other service requests and method calls inside a Modbus PDU. The MEI (Modbus Encapsulated Interface) type byte says which interface is being used. Two MEI types are defined: 0x0D CANopen General Reference, and 0x0E Read Device Identification.
Request
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0D or 0x0E
MEI type specific data
N bytes
N = number of interface-specific request data bytes; contents depend on MEI type.
Success Response
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
Echo of request
MEI type specific data
N bytes
N = number of interface-specific response data bytes; contents depend on MEI type.
Error Response
Field
Size
Value
Error code
1 byte
0xAB
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
43 / 13 (0x2B / 0x0D) CANopen General Reference
Carries CANopen requests and responses inside Modbus, so a Modbus client can reach objects in a CANopen device through a gateway. The MEI type specific data follows the CANopen general reference format, and the response echoes the MEI type with the CANopen result.
Request
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0D
CANopen request data
N bytes
N = number of CANopen request data bytes; contents follow the CANopen general reference format.
Success Response
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0D
CANopen response data
N bytes
N = number of CANopen response data bytes; contents follow the CANopen general reference format.
Error Response
Field
Size
Value
Error code
1 byte
0xAB
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
43 / 14 (0x2B / 0x0E) Read Device Identification
Reads identification information about a device as a set of objects. Objects 0x00 to 0x02 (vendor name, product code, revision) are the basic set and are required. Objects 0x03 to 0x06 (vendor URL, product name, model name, user application name) are the regular set. Objects 0x80 to 0xFF are extended and vendor defined. The Read Device ID code selects basic (01), regular (02), extended (03), or one individual object (04).
Request
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0E
Read Device ID code
1 byte
01, 02, 03, or 04
Object ID
1 byte
0x00 to 0xFF (0 to 255)
Success Response
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0E
Read Device ID code
1 byte
Echo of request
Conformity level
1 byte
Supported access level
More follows
1 byte
0x00 (no) or 0xFF (yes)
Next object ID
1 byte
Object to request next
Number of objects
1 byte
N = number of identification objects returned.
Object ID / length / value
Repeated N times
Object data
Error Response
Field
Size
Value
Error code
1 byte
0xAB
Exception code
1 byte
0x01, 0x02, 0x03, or 0x04
Example
Client requests to read the basic device identification objects in the server, starting at object 0x00. The server returns its vendor name, product code, and revision.
Request
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0E
Read Device ID code
1 byte
0x01
Object ID
1 byte
0x00
Success Response
Field
Size
Value
Function code
1 byte
0x2B
MEI type
1 byte
0x0E
Read Device ID code
1 byte
0x01
Conformity level
1 byte
0x01
More follows
1 byte
0x00
Next object ID
1 byte
0x00
Number of objects
1 byte
0x03
Vendor name object ID
1 byte
0x00
Vendor name length
1 byte
0x16
Vendor name value
22 bytes
Company identification (ASCII)
Product code object ID
1 byte
0x01
Product code length
1 byte
0x0F
Product code value
15 bytes
Product code XX (ASCII)
Revision object ID
1 byte
0x02
Revision length
1 byte
0x05
Revision value
5 bytes
V2.11 (ASCII)
Where SimServe fits
Every function code and exception above can be exercised against a simulated Modbus device in SimServe, so you can check your SCADA's handling of register offsets, byte order, and error responses before you connect to real equipment.