Modbus Function Codes
Each command starts with an address followed by a function code. These are used to read data from discrete inputs and input registers. They can also read/write data on coils and holding registers of each Modbus device you address.
The following is a table of object types provided by a Modbus slave device to a Modbus master device:
Object type | Access | Size |
Coil | Read-write | 1 bit |
Discrete input | Read-only | 1 bit |
Input register | Read-only | 16 bits |
Holding register | Read-write | 16 bits |
Modbus Frame
The frame format is composed of an Application Data Unit (ADU), which encloses a Protocol Data Unit (PDU):
- ADU = Address + PDU + Error check
- PDU = Function code + Data
Most used Function Codes
-
Read:
- 01: Coils (FC=01)
- 02: Discrete Inputs (FC=02)
- 03: Multiple Holding Registers (FC=03)
- 04: Input Registers (FC=04)
- 05: Single Coil (FC=05)
- 06: Single Holding Register (FC=06)
- 0F: Multiple Coils (FC=15)
- 10: Multiple Holding Registers (FC=16)
Write:
All Modbus Function Codes
The various reading, writing and other operations are categorised as follows. The most primitive reads and writes are shown in bold. A number of sources use alternative terminology, for example Force Single Coil where the standard uses Write Single Coil. Prominent entities within a Modbus slave are:
- Coils (1 bit): readable and writable, states: on/off
- Discrete Inputs (1 bit): readable, states: on/off
- Input Registers (16 bit): readable, essentially measurements and statuses
- Holding Registers (16 bit): readable and writable, essentially configuration values
Function type | Function name | Function code | ||
Data Access | Bit access | Physical Discrete Inputs | Read Discrete Inputs | 2 |
Internal Bits or Physical Coils |
Read Coils | 1 | ||
Write Single Coil | 5 | |||
Write Multiple Coils | 15 | |||
16-bit access | Physical Input Registers | Read Input Registers | 4 | |
Internal Registers or Physical Output Registers |
Read Multiple Holding Registers | 3 | ||
Write Single Holding Register | 6 | |||
Write Multiple Holding Registers | 16 | |||
Read/Write Multiple Registers | 23 | |||
Mask Write Register | 22 | |||
Read FIFO Queue | 24 | |||
File Record Access | Read File Record | 20 | ||
Write File Record | 21 | |||
Diagnostics | Read Exception Status | 7 | ||
Diagnostic | 8 | |||
Get Com Event Counter | 11 | |||
Get Com Event Log | 12 | |||
Report Slave ID | 17 | |||
Read Device Identification | 43 | |||
Other | Encapsulated Interface Transport | 43 |
Contents retrieved from
- https://en.wikipedia.org/wiki/Modbus
More information
- Modbus Function Codes
- Mobdbus function code 1 - read coils
- Mobdbus function code 2 - read discrete inputs
- Mobdbus function code 3 - read multiple holding registers
- Mobdbus function code 4 - read input registers
- Mobdbus function code 5 - write single coil
- Mobdbus function code 6 - write single holding register
- Mobdbus function code 15 - write multiple coils
- Mobdbus function code 16 - write multiple holding registers
- Modbus References
- Modbus protocol basics