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 code1 Byte0x01
Starting Address2 Bytes0x0000 to 0xFFFF
Quantity of coils2 Bytes1 to 2000 (0x7D0)
Table 1 - Command structure

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 code1 Byte0x01
Byte count1 ByteN*
Coil Statusn Byten = N or N+1
*N = Quantity of Inputs / 8 if the remainder is different of 0 ⇨ N = N+1
Table 2 - Response structure

Error

Error code1 ByteFunction code + 0x80
Exception code1 Byte01 or 02 or 03 or 04
Table 3 - Error structure. Scroll below for details.

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

read coil states
Figure 1 - Read Coil states

Contents retrieved from

  • http://modbus.org/
  • http://www.simplymodbus.ca/

More information