Modbus Function Code 1
Read Coils on Modbus
It can read the status of 1 to 2000 coils in a remote device. The Request PDU specifies the starting address, i.e. the address of the first coil specified, and the number of coils. In the PDU Coils are addressed starting at zero. Therefore coils numbered 1-16 are addressed as 0-15.
Request
Function code | 1 Byte | 0x01 |
Starting Address | 2 Bytes | 0x0000 to 0xFFFF |
Quantity of coils | 2 Bytes | 1 to 2000 (0x7D0) |
Response
The coils in the response message are packed as one coil per bit of the data field. Status is indicated as 1=On and 0=Off. The LSB of the first data byte contains the output addressed in the query. The other coils follow toward the high order end of this byte, and from low order to high order in subsequent bytes.
If the output quantity is not eight's multiplication, the remaining bits in the final data byte will be padded with zeros (toward the high order end of the byte). The Byte Count field specifies the quantity of used Bytes (Table 2).
Function code | 1 Byte | 0x01 |
Byte count | 1 Byte | N* |
Coil Status | n Byte | n = N or N+1 |
Table 2 - Response structure
Error
Error code | 1 Byte | Function code + 0x80 |
Exception code | 1 Byte | 01 or 02 or 03 or 04 |
Example
Request
This command is requesting the On/Off (0/1) status of discrete coils # 30 to 60 from the slave device with address 11.
0B 01 001D 001F ED6E |
- 0B: The Slave Address (0B hex = address 11)
- 01: The Function Code 1 (Read Coils)
- 001D: The Data Address of the first coil to read (001D hex = 29, +1 offset = coil #30).
- 001F: The total number of coils requested (25 hex = 31, inputs 30 to 60).
- ED6E: The CRC (Cyclic Redundancy Check) for error checking.
Response
0B 01 04 CD6BB27F 2BE1 |
- 0B: The Slave Address (0B hex = address 11)
- 01: The Function Code 1 (Read Coils)
- 04: The number of data bytes to follow (31 Coils = 3 bytes + 7 bits + 1 space holder = 4 bytes)
- CD: Coils 37 - 30 (1100 1101)
- 6B: Coils 45 - 38 (0110 1011)
- B2: Coils 53 - 46 (1011 0010)
- 7F: 1 space holder & Coils 60 - 54 (0111 1111)
- 2BE1: The CRC (Cyclic Redundancy Check).
The more significant bits contain the higher coil variables. This shows that coil 38 is On (1) and 45 is Off (0). Due to the number of coils requested, the last data field 7F contains the status of only 7 coils. The space holders are always filled with zeroes. In this example there was only 1 spaceholder represented by the most significant bit.
Workflow Diagram for Modbus FC 1
Contents retrieved from
- http://modbus.org/
- http://www.simplymodbus.ca/
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