Knowledge Center
Getting Started25 min readSCADAmatic Engineering

Modbus: a detailed reference

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 application layerFUNCTION CODE + DATA (PDU)TCPIPEthernet 802.3MODBUS TCPModbus serial lineRS-232 / 422 / 485Modbus PlusProprietary HDLCETHERNETSERIALMODBUS PLUS
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:

  1. additional address

  2. function code

  3. data

  4. error check.

APPLICATION DATA UNIT (ADU)PROTOCOL DATA UNIT (PDU)Additional addressFunction codeDataError checkMEDIA SPECIFICSAME ON EVERY MEDIAMEDIA SPECIFIC
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:

PDUFieldSize
Request (mb_req_pdu)Function code1 byte
Data, contents depend on the function coden bytes
Response (mb_rsp_pdu)Function code1 byte
Data, contents depend on the function coden bytes
Exception response (mb_excep_rsp_pdu)Exception function code, same function code from request but leading bit set to 11 byte
Exception code, from the list of Modbus exception codes1 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.

NetworkADU calculationMaximum ADU
Serial RTU1 (server address) + 253 (PDU) + 2 (CRC)256 bytes
Serial ASCII1 (start ":") + 2 (address) + 506 (PDU as hex characters) + 2 (LRC) + 2 (CR LF)513 characters
Modbus TCP7 (MBAP header) + 253 (PDU)260 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:

TableSizeAccess
Discrete inputsSingle bitRead only
CoilsSingle bitRead/write
Input registers16 bitsRead only
Holding registers16 bitsRead/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 DATA MODELDEVICE MEMORYDiscrete inputs1 BIT · READ ONLYCoils1 BIT · READ/WRITEInput registers16 BIT · READ ONLYHolding registers16 BIT · READ/WRITEInput shared data block1 WORD (16 BITS)BYTE 1BYTE 00123456789101112131415ONE PHYSICAL AREAOutput shared data block1 WORD (16 BITS)BYTE 1BYTE 00123456789101112131415ONE PHYSICAL AREA
Modbus tables overlapping shared blocks of device memory

Others keep each table in its own area of memory:

MODBUS DATA MODELDEVICE MEMORYDiscrete inputs1 BIT · READ ONLYCoils1 BIT · READ/WRITEInput registers16 BIT · READ ONLYHolding registers16 BIT · READ/WRITEInput bitsOutput bitsAnalog inputsSetpoints
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:

PrefixTableExample
0Coils000001
1Discrete Inputs100001
3Input registers300001
4Holding registers400001

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:

CodeNameMeaning
0x01Invalid functionThe server does not support the function code
0x02Invalid register addressThe requested address, or address plus quantity, is outside the server's range
0x03Invalid data valueA value in the request data is not allowed, such as a bad quantity
0x04Server device failureAn unrecoverable error happened while the server was carrying out the request
0x05AcknowledgeThe server accepted the request but needs a long time to finish it
0x06Server busyThe server is busy with a long-running command; the client should retry later
0x08Memory parity errorThe server found a parity error in its memory while reading a file record
0x0AGateway path unavailableA gateway could not set up a path to the target device
0x0BGateway target device failed to respondA 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
FieldSizeValue
Function code1 byte0x01
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of coils2 bytes0x0001 to 0x07D0 (1 to 2000)
Success Response
FieldSizeValue
Function code1 byte0x01
Byte count1 byteN = quantity of coils / 8 (rounded up).
Coil Status Byte 11 bytePacked coil bits
Coil Status Byte 21 bytePacked coil bits
...
Coil Status Byte N1 bytePacked coil bits
Error Response
FieldSizeValue
Error code1 byte0x81
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to read coils 20-39 in the server.

Data In Server Before Read
Modbus AddressValue
Coil 200x01 (ON)
Coil 210x00 (OFF)
Coil 220x01 (ON)
Coil 230x01 (ON)
Coil 240x00 (OFF)
Coil 250x00 (OFF)
Coil 260x01 (ON)
Coil 270x01 (ON)
Coil 280x01 (ON)
Coil 290x01 (ON)
Coil 300x00 (OFF)
Coil 310x01 (ON)
Coil 320x00 (OFF)
Coil 330x01 (ON)
Coil 340x01 (ON)
Coil 350x00 (OFF)
Coil 360x01 (ON)
Coil 370x00 (OFF)
Coil 380x01 (ON)
Coil 390x01 (ON)
Request
FieldSizeValue
Function code1 byte0x01
Starting address2 bytes0x0013 (19)*
Quantity of coils2 bytes0x0014 (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
FieldSizeValue
Function code1 byte0x01
Byte count1 byte0x03 (3)
Coil Status Byte 11 byte0b11001101
0xCD
Coil Status Byte 21 byte0b01101011
0x6B
Coil Status Byte 31 byte0b00001101
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
FieldSizeValue
Function code1 byte0x02
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of inputs2 bytes0x0001 to 0x07D0 (1 to 2000)
Success Response
FieldSizeValue
Function code1 byte0x02
Byte count1 byteN = quantity of inputs / 8 (rounded up).
Discrete Input Status Byte 11 bytePacked input bits
Discrete Input Status Byte 21 bytePacked input bits
...
Discrete Input Status Byte N1 bytePacked input bits
Error Response
FieldSizeValue
Error code1 byte0x82
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to read discrete inputs 197-218 in the server.

Data In Server Before Read
Modbus AddressValue
Discrete input 1970x00 (OFF)
Discrete input 1980x00 (OFF)
Discrete input 1990x01 (ON)
Discrete input 2000x01 (ON)
Discrete input 2010x00 (OFF)
Discrete input 2020x01 (ON)
Discrete input 2030x00 (OFF)
Discrete input 2040x01 (ON)
Discrete input 2050x01 (ON)
Discrete input 2060x01 (ON)
Discrete input 2070x00 (OFF)
Discrete input 2080x01 (ON)
Discrete input 2090x01 (ON)
Discrete input 2100x00 (OFF)
Discrete input 2110x01 (ON)
Discrete input 2120x01 (ON)
Discrete input 2130x01 (ON)
Discrete input 2140x00 (OFF)
Discrete input 2150x01 (ON)
Discrete input 2160x00 (OFF)
Discrete input 2170x01 (ON)
Discrete input 2180x01 (ON)
Request
FieldSizeValue
Function code1 byte0x02
Starting address2 bytes0x00C4 (196)*
Quantity of inputs2 bytes0x0016 (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
FieldSizeValue
Function code1 byte0x02
Byte count1 byte0x03 (3)
Input Status Byte 11 byte0b10101100
0xAC
Input Status Byte 21 byte0b11011011
0xDB
Input Status Byte 31 byte0b00110101
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
FieldSizeValue
Function code1 byte0x03
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of registers2 bytes0x0001 to 0x007D (1 to 125)
Success Response
FieldSizeValue
Function code1 byte0x03
Byte count1 byte2 x N, where N = quantity of registers
Register Value 12 bytesdata with high byte followed by low byte
Register Value 22 bytesdata with high byte followed by low byte
...
Register Value N2 bytesdata with high byte followed by low byte
Error Response
FieldSizeValue
Error code1 byte0x83
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to read holding registers 108-110 in the server.

Data In Server Before Read
Modbus AddressValue
Holding register 1080x022B (555)
Holding register 1090x0000 (0)
Holding register 1100x0064 (100)
Request
FieldSizeValue
Function code1 byte0x03
Starting address2 bytes0x006B (107)*
Quantity of registers2 bytes0x0003 (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
FieldSizeValue
Function code1 byte0x03
Byte count1 byte0x06 (6)
Register 108 value2 bytes0x022B (555)
Register 109 value2 bytes0x0000 (0)
Register 110 value2 bytes0x0064 (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
FieldSizeValue
Function code1 byte0x04
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of input registers2 bytes0x0001 to 0x007D (1 to 125)
Success Response
FieldSizeValue
Function code1 byte0x04
Byte count1 byte2 x N, where N = quantity of input registers
Analog Input Status 12 bytesdata with high byte followed by low byte
Analog Input Status 22 bytesdata with high byte followed by low byte
...
Analog Input Status N2 bytesdata with high byte followed by low byte
Error Response
FieldSizeValue
Error code1 byte0x84
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to read one input register, at address 9, in the server.

Data In Server Before Read
Modbus AddressValue
Input register 90x000A (10)
Request
FieldSizeValue
Function code1 byte0x04
Starting address2 bytes0x0008 (8)*
Quantity of input registers2 bytes0x0001 (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
FieldSizeValue
Function code1 byte0x04
Byte count1 byte0x02 (2)
Input register 9 value2 bytes0x000A (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
FieldSizeValue
Function code1 byte0x05
Output address2 bytes0x0000 to 0xFFFF (0 to 65535)
Output value2 bytes0x0000 (OFF) or 0xFF00 (ON)
Success Response
FieldSizeValue
Function code1 byte0x05
Output address2 bytes0x0000 to 0xFFFF (0 to 65535)
Output value2 bytes0x0000 (OFF) or 0xFF00 (ON)
Error Response
FieldSizeValue
Error code1 byte0x85
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to turn ON the coil at address 173 in the server.

Request
FieldSizeValue
Function code1 byte0x05
Output address2 bytes0x00AC (172)
Output value2 bytes0xFF00 (ON)
Success Response
FieldSizeValue
Function code1 byte0x05
Output address2 bytes0x00AC (172)
Output value2 bytes0xFF00 (ON)
Data In Server After Write
Modbus AddressValue
Coil 1730x01 (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
FieldSizeValue
Function code1 byte0x06
Register address2 bytes0x0000 to 0xFFFF (0 to 65535)
Register value2 bytes0x0000 to 0xFFFF (0 to 65535)
Success Response
FieldSizeValue
Function code1 byte0x06
Register address2 bytes0x0000 to 0xFFFF (0 to 65535)
Register value2 bytes0x0000 to 0xFFFF (0 to 65535)
Error Response
FieldSizeValue
Error code1 byte0x86
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to write the value 3 to the holding register at address 2 in the server.

Request
FieldSizeValue
Function code1 byte0x06
Register address2 bytes0x0001 (1)
Register value2 bytes0x0003 (3)
Success Response
FieldSizeValue
Function code1 byte0x06
Register address2 bytes0x0001 (1)
Register value2 bytes0x0003 (3)
Data In Server After Write
Modbus AddressValue
Holding register 20x0003 (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
FieldSizeValue
Function code1 byte0x07
Success Response
FieldSizeValue
Function code1 byte0x07
Output data1 byte0x00 to 0xFF (0 to 255)
Error Response
FieldSizeValue
Error code1 byte0x87
Exception code1 byte0x01 or 0x04

Example

Client requests to read the server’s eight exception status outputs.

Request
FieldSizeValue
Function code1 byte0x07
Success Response
FieldSizeValue
Function code1 byte0x07
Output data1 byte0b01101101
0x6D
Fictional Vendor Exception Status Definition
ExceptionBit IndexStatus
Digital Input Fault0Active
Digital Output Fault1Inactive
Analog Input Fault2Active
Analog Output Fault3Active
Network Fault4Inactive
Memory Fault5Active
Program Fault6Active
Firmware Fault7Inactive

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
FieldSizeValue
Function code1 byte0x08
Sub-function2 bytesSee above
Datadepends on sub-functiondepends on sub-function
Success Response
FieldSizeValue
Function code1 byte0x08
Sub-function2 bytesSame as request
Datadepends on sub-functiondepends on sub-function
Error Response
FieldSizeValue
Error code1 byte0x88
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x08
Sub-function2 bytes0x0000
Data2 bytes0xA537
Success Response
FieldSizeValue
Function code1 byte0x08
Sub-function2 bytes0x0000
Data2 bytes0xA537

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
FieldSizeValue
Function code1 byte0x0B
Success Response
FieldSizeValue
Function code1 byte0x0B
Status2 bytes0x0000 (ready) or 0xFFFF (busy)
Event count2 bytes0x0000 to 0xFFFF (0 to 65535)
Error Response
FieldSizeValue
Error code1 byte0x8B
Exception code1 byte0x01 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
FieldSizeValue
Function code1 byte0x0B
Success Response
FieldSizeValue
Function code1 byte0x0B
Status2 bytes0xFFFF (busy)
Event count2 bytes0x0108 (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 status word and event count are identical to those returned by Get 11 (0x0B) Get Comm Event Counter.

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
FieldSizeValue
Function code1 byte0x0C
Success Response
FieldSizeValue
Function code1 byte0x0C
Byte count1 byteN = 6 + number of event bytes (0 to 64).
Status2 bytes0x0000 or 0xFFFF
Event count2 bytes0x0000 to 0xFFFF (0 to 65535)
Message count2 bytes0x0000 to 0xFFFF (0 to 65535)
EventsN − 6 bytesEvent log
Error Response
FieldSizeValue
Error code1 byte0x8C
Exception code1 byte0x01 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.

StatusBit Index
Not used0
Communication error1
Not used2
Not used3
Character overrun4
Currently in listen-only mode5
Broadcast received6
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.

StatusBit 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 occurred4
Currently in listen-only mode5
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
FieldSizeValue
Function code1 byte0x0C
Success Response
FieldSizeValue
Function code1 byte0x0C
Byte count1 byte0x08 (8)
Status2 bytes0x0000 (ready)
Event count2 bytes0x0108 (264)
Message count2 bytes0x0121 (289)
Event Byte 11 byte0x04 (listen mode)
Event Byte 21 byte0x00 (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
FieldSizeValue
Function code1 byte0x0F
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of outputs2 bytes0x0001 to 0x07B0 (1 to 1968)
Byte count1 byteN = quantity of coils / 8 (rounded up).
Coil Status Byte 11 bytePacked coil bits
Coil Status Byte 21 bytePacked coil bits
...
Coil Status Byte N1 bytePacked coil bits
Success Response
FieldSizeValue
Function code1 byte0x0F
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of outputs2 bytes0x0001 to 0x07B0 (1 to 1968)
Error Response
FieldSizeValue
Error code1 byte0x8F
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to write coils 20-29 in the server.

Request
FieldSizeValue
Function code1 byte0x0F
Starting address2 bytes0x0013 (19)*
Quantity of outputs2 bytes0x000A (10)
Byte count1 byte0x02 (2)
Coil Status Byte 11 byte0b11001101
0xCD
Coil Status Byte 21 byte0b00000001
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
FieldSizeValue
Function code1 byte0x0F
Starting address2 bytes0x0013 (19)*
quantity of coils2 bytes0x000A (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 AddressValue
Coil 200x01 (ON)
Coil 210x00 (OFF)
Coil 220x01 (ON)
Coil 230x01 (ON)
Coil 240x00 (OFF)
Coil 250x00 (OFF)
Coil 260x01 (ON)
Coil 270x01 (ON)
Coil 280x01 (ON)
Coil 290x00 (OFF)

16 (0x10) Write Multiple Registers

Writes a block of 1 to 123 contiguous holding registers.

Request
FieldSizeValue
Function code1 byte0x10
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of registers2 bytes0x0001 to 0x007B (1 to 123)
Byte count1 byte2 x N, where N = quantity of registers
Register Value 12 bytesdata with high byte followed by low byte
Register Value 22 bytesdata with high byte followed by low byte
...
Register Value N2 bytesdata with high byte followed by low byte
Success Response
FieldSizeValue
Function code1 byte0x10
Starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity of registers2 bytes0x0001 to 0x007B (1 to 123)
Error Response
FieldSizeValue
Error code1 byte0x90
Exception code1 byte0x01, 0x02, 0x03, or 0x04

Example

Client requests to write holding registers 2-3 in the server.

Request
FieldSizeValue
Function code1 byte0x10
Starting address2 bytes0x0001 (1)*
Quantity of registers2 bytes0x0002 (2)
Byte count1 byte0x04 (4)
Register 2 value2 bytes0x000A (10)
Register 3 value2 bytes0x0102 (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
FieldSizeValue
Function code1 byte0x10
Starting address2 bytes0x0001 (1)*
Quantity of registers2 bytes0x0002 (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 AddressValue
Holding register 20x000A (10)
Holding register 30x0102 (258)

17 (0x11) Report Server ID (serial line only)

Reads the type, current status, and other device-specific information about a server.

Request
FieldSizeValue
Function code1 byte0x11
Success Response
FieldSizeValue
Function code1 byte0x11
Byte count1 byteN = server ID byte size + 1 run indicator byte + additional data byte size
Server IDDevice specificDevice specific
Run indicator status1 byte0x00 (off) or 0xFF (on)
Additional dataDevice specificDevice specific
Error Response
FieldSizeValue
Error code1 byte0x91
Exception code1 byte0x01 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
FieldSizeValue
Function code1 byte0x11
Success Response
FieldSizeValue
Function code1 byte0x11
Byte count1 byte0x03 (3)
Server ID1 byte0x2A (42)
Run indicator status1 byte0xFF (ON)
Additional data1 byte0x01

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:

  1. Reference type: 1 byte, which must be 0x06 (6).
  2. File number: 2 bytes.
  3. Starting record number within the file: 2 bytes.
  4. 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
FieldSizeValue
Function code1 byte0x14
Byte count1 byte0x07 to 0xF5 (7 to 245)
Sub-request x, reference type1 byte0x06
Sub-request x, file number2 bytes0x0001 to 0xFFFF (1 to 65535)
Sub-request x, record number2 bytes0x0000 to 0x270F (0 to 9999)
Sub-request x, record length2 bytesN = Number of records to read, specified in register count
Success Response
FieldSizeValue
Function code1 byte0x14
Response data length1 byte0x07 to 0xF5 (7 to 245)
Sub-request x, file response length1 byte0x07 to 0xF5 (7 to 245)
Sub-request x, reference type1 byte0x06
Sub-request x, record dataN x 2 bytesrecord data
Error Response
FieldSizeValue
Error code1 byte0x94
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x14
Byte count1 byte0x0E
Sub-request 1, reference type1 byte0x06
Sub-request 1, file number2 bytes0x0004
Sub-request 1, record number2 bytes0x0001
Sub-request 1, record length2 bytes0x0002
Sub-request 2, reference type1 byte0x06
Sub-request 2, file number2 bytes0x0003
Sub-request 2, record number2 bytes0x0009
Sub-request 2, record length2 bytes0x0002
Success Response
FieldSizeValue
Function code1 byte0x14
Response data length1 byte0x0C
Sub-request 1, file response length1 byte0x05
Sub-request 1, reference type1 byte0x06
Sub-request 1, record data4 bytes0D FE 00 20
Sub-request 2, file response length1 byte0x05
Sub-request 2, reference type1 byte0x06
Sub-request 2, record data4 bytes33 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
FieldSizeValue
Function code1 byte0x15
Request data length1 byte0x09 to 0xFB (9 to 251)
Sub-request x, reference type1 byte0x06
Sub-request x, file number2 bytes0x0001 to 0xFFFF (1 to 65535)
Sub-request x, record number2 bytes0x0000 to 0x270F (0 to 9999)
Sub-request x, record length2 bytesN = Number of records to write, specified in register count
Sub-request x, record data2 X N bytesrecord data
Success Response
FieldSizeValue
All fieldsSame as requestEcho of the request
Error Response
FieldSizeValue
Error code1 byte0x95
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x15
Request data length1 byte0x0D
Reference type1 byte0x06
File number2 bytes0x0004
Record number2 bytes0x0007
Record length2 bytes0x0003
Record data6 bytes06 AF 04 BE 10 0D
Success Response
FieldSizeValue
Function code1 byte0x15
Request data length1 byte0x0D
Reference type1 byte0x06
File number2 bytes0x0004
Record number2 bytes0x0007
Record length2 bytes0x0003
Record data6 bytes06 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
FieldSizeValue
Function code1 byte0x16
Reference address2 bytes0x0000 to 0xFFFF (0 to 65535)
And_Mask2 bytes0x0000 to 0xFFFF (0 to 65535)
Or_Mask2 bytes0x0000 to 0xFFFF (0 to 65535)
Success Response
FieldSizeValue
All fieldsSame as requestEcho of the request
Error Response
FieldSizeValue
Error code1 byte0x96
Exception code1 byte0x01, 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 AddressValue
Holding register 5
Current Contents0b00000000 00010010
0x0012 (18)
Request
FieldSizeValue
Function code1 byte0x16
Reference address2 bytes0x0004
And_Mask2 bytes0b00000000 11110010
0x00F2
Or_Mask2 bytes0b00000000 00100101
0x0025
Success Response
FieldSizeValue
Function code1 byte0x16
Reference address2 bytes0x0004
And_Mask2 bytes0b00000000 11110010
0x00F2
Or_Mask2 bytes0b00000000 00100101
0x0025
Data In Server After Write
Modbus AddressValue
Holding register 5
Current Contents0b00000000 00010010
And_Mask0b00000000 11110010
(1) (Current Contents And And_Mask)0b00000000 00010010
Or_Mask0b00000000 00100101
NOT And_Mask0b11111111 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
FieldSizeValue
Function code1 byte0x17
Read starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity to read2 bytes0x0001 to 0x007D (1 to 125)
Write starting address2 bytes0x0000 to 0xFFFF (0 to 65535)
Quantity to write2 bytes0x0001 to 0x0079 (1 to 121)
Write byte count1 byteN = 2 x quantity to write
Write register valuesN bytesValues to write
Success Response
FieldSizeValue
Function code1 byte0x17
Byte count1 byte2 x N, where N = quantity to read
Register Value 12 bytesdata with high byte followed by low byte
Register Value 22 bytesdata with high byte followed by low byte
...
Register Value N2 bytesdata with high byte followed by low byte
Error Response
FieldSizeValue
Error code1 byte0x97
Exception code1 byte0x01, 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 AddressValue
Holding register 40x00FE (254)
Holding register 50x0ACD (2765)
Holding register 60x0001 (1)
Holding register 70x0003 (3)
Holding register 80x000D (13)
Holding register 90x00FF (255)
Holding register 150x00FF (255)
Holding register 160x00FF (255)
Holding register 170x00FF (255)
Request
FieldSizeValue
Function code1 byte0x17
Read starting address2 bytes0x0003 (3)*
Quantity to read2 bytes0x0006 (6)
Write starting address2 bytes0x000E (14)*
Quantity to write2 bytes0x0003 (3)
Write byte count1 byte0x06
Register 15 value2 bytes0x00FF
Register 16 value2 bytes0x00FF
Register 17 value2 bytes0x00FF

* = Note that the starting address in the request transmitted over the wire is 1 less than the actual Modbus address being requested.

Success Response
FieldSizeValue
Function code1 byte0x17
Byte count1 byte0x0C (12)
Register 4 value2 bytes0x00FE
Register 5 value2 bytes0x0ACD
Register 6 value2 bytes0x0001
Register 7 value2 bytes0x0003
Register 8 value2 bytes0x000D
Register 9 value2 bytes0x00FF

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
FieldSizeValue
Function code1 byte0x18
FIFO pointer address2 bytes0x0000 to 0xFFFF (0 to 65535)
Success Response
FieldSizeValue
Function code1 byte0x18
Byte count2 bytesN = 2 FIFO count bytes + 2 x FIFO count.
FIFO count2 bytes0x0000 to 0x001F (0 to 31)
FIFO valuesN − 2 bytesQueued register data
Error Response
FieldSizeValue
Error code1 byte0x98
Exception code1 byte0x01, 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 AddressValue
Holding register 1247 — FIFO count0x0002 (2)
Holding register 1248 — FIFO value 10x01B8 (440)
Holding register 1249 — FIFO value 20x1284 (4740)
Request
FieldSizeValue
Function code1 byte0x18
FIFO pointer address2 bytes0x04DE
Success Response
FieldSizeValue
Function code1 byte0x18
Byte count2 bytes0x0006 (6)
FIFO count2 bytes0x0002
FIFO value 12 bytes0x01B8
FIFO value 22 bytes0x1284

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
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0D or 0x0E
MEI type specific dataN bytesN = number of interface-specific request data bytes; contents depend on MEI type.
Success Response
FieldSizeValue
Function code1 byte0x2B
MEI type1 byteEcho of request
MEI type specific dataN bytesN = number of interface-specific response data bytes; contents depend on MEI type.
Error Response
FieldSizeValue
Error code1 byte0xAB
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0D
CANopen request dataN bytesN = number of CANopen request data bytes; contents follow the CANopen general reference format.
Success Response
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0D
CANopen response dataN bytesN = number of CANopen response data bytes; contents follow the CANopen general reference format.
Error Response
FieldSizeValue
Error code1 byte0xAB
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0E
Read Device ID code1 byte01, 02, 03, or 04
Object ID1 byte0x00 to 0xFF (0 to 255)
Success Response
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0E
Read Device ID code1 byteEcho of request
Conformity level1 byteSupported access level
More follows1 byte0x00 (no) or 0xFF (yes)
Next object ID1 byteObject to request next
Number of objects1 byteN = number of identification objects returned.
Object ID / length / valueRepeated N timesObject data
Error Response
FieldSizeValue
Error code1 byte0xAB
Exception code1 byte0x01, 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
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0E
Read Device ID code1 byte0x01
Object ID1 byte0x00
Success Response
FieldSizeValue
Function code1 byte0x2B
MEI type1 byte0x0E
Read Device ID code1 byte0x01
Conformity level1 byte0x01
More follows1 byte0x00
Next object ID1 byte0x00
Number of objects1 byte0x03
Vendor name object ID1 byte0x00
Vendor name length1 byte0x16
Vendor name value22 bytesCompany identification (ASCII)
Product code object ID1 byte0x01
Product code length1 byte0x0F
Product code value15 bytesProduct code XX (ASCII)
Revision object ID1 byte0x02
Revision length1 byte0x05
Revision value5 bytesV2.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.