Reading Function Codes

Master the read function codes FC01/02/03/04 — read coils, read discrete inputs, read holding registers, read input registers — and the request-to-response structure

Chapter Objectives

Scenario: Ms. Wang Wants to "Take a Look"

The greenhouse network is up and the register map is drawn. Ms. Wang's most basic need right now is: "What's the temperature in there? What's the humidity? Is the exhaust fan on?"—in other words, "read only, don't write". In Modbus, "reading" is handled by a dedicated group of function codes; they only ask the slave for data and never change anything.

Analogy: read function codes are like "calling on a student in class"—the teacher asks "student number 3, what's the temperature?" and the student reports a number; no matter how many times you ask, the state of the classroom is unchanged.

Why It Matters

"Reading" is 90% of the work of a monitoring system: SCADA video walls, phone apps, and data dashboards are all essentially polling for data on a cycle. Master the 4 read function codes and you have half the ability to "map the physical world onto a screen". The other half—"writing" (controlling devices)—is saved for Chapter 5.

Core Concepts: The 4 Read Function Codes

CodeHexActionWhat it readsCorresponding data type
010x01Read CoilsSwitch states (read/write area)Coils
020x02Read Discrete InputsRead-only switch statesDiscrete inputs
030x03Read Holding RegistersRead/write 16-bit valuesHolding registers
040x04Read Input RegistersRead-only 16-bit measured valuesInput registers

Memory aid: 01/02 read "switches" (1 bit), 03/04 read "values" (16 bits); the ones ending in 1 read the writable area (coils / holding registers), the ones ending in 2 read the read-only area (discrete inputs / input registers). The four codes cover exactly the four data types from Chapter 3.

Structure of a Read Request and a Read Response

Read request: function code + starting address (2B) + quantity (2B).

Read response: function code echoed + byte count (1B) + data (N bytes). Here byte count = number of data bytes: when reading N registers (16-bit) the byte count = 2×N; when reading N coils the byte count = ⌈N/8⌉.

Protocol Details and Byte-Level Examples

FC 03: Read Holding Registers (Request → Response Pair)

Request—read 2 holding registers from slave 1 (starting at 0x0000):

■ RTU Address ■ Function Code ■ Data ■ CRC
Slave 1 01
FC 03: Read Holding Registers 03
Starting address + quantity 00 00 00 02
CRC-16 C4 0B
ByteValueMeaning
001Slave 1
103Function code: Read Holding Registers
2–300 00Starting address
4–500 02Quantity
6–7C4 0BCRC-16

Response—the slave returns 4 data bytes 00 64 00 C8 (100 and 200); note that the byte count = 04 (2 registers × 2 bytes):

■ RTU Address ■ Function Code ■ Data ■ CRC
Slave 1 01
FC 03 echoed 03
Byte count = 4 04
Data (100 and 200) 00 64 00 C8
CRC-16 BA 7A
ByteValueMeaning
001Slave 1
103Function code echoed
204Byte count = 4
3–600 64 00 C8Data (100, 200)
7–8BA 7ACRC-16

FC 04: Read Input Registers (Read-Only Measured Values)

Request—read 1 input register from slave 1 (starting at 0x0000): 01 04 00 00 00 01 31 CA. The response structure is identical to FC03, except the byte count = 02 and the data is the 16-bit measured value being read (for example the raw reading of the humidity sensor).

FC 01: Read Coils (Switch States)

Request—read 10 coils from slave 1 (starting at 0x0000): 01 01 00 00 00 0A BC 0D. The response has a byte count = 02 (⌈10/8⌉=2), and the data is packed by bit: bit 0 = coil 0, bit 1 = coil 1, and so on—one byte holds at most 8 switches.

Real-World Applications

Case 1: The Greenhouse "Look, Don't Control" Operation Table (Running Case)

What Ms. Wang wants to knowFunction codeRequest (complete RTU frame)
Temperature of sensor 1FC 0301 03 00 00 00 01 84 0A
HumidityFC 0401 04 00 00 00 01 31 CA
Whether the fan / pump / shade curtain is onFC 0101 01 00 00 00 0A BC 0D

Note: FC01 reads coils (switch states in the writable area), while FC02 reads discrete inputs (read-only switches, such as a door sensor). In a greenhouse, "is the device on" usually maps to coils, so FC01 is used.

Case 2: The VFD Side Case—Reading the Frequency

A factory host application uses FC 03 to read holding register 0x0000 of a VFD and obtain the present output frequency; comparing it with the target speed that was written in tells you whether the motor is "obeying". Read the setpoint, read the actual value—this is the pair of operations industrial monitoring performs most often.

Hands-On Lab Guide

The Lab wizard currently supports FC 01 / 03 (read operations); practise them one at a time:

  1. FC 03: read 2 holding registers → expected request 01 03 00 00 00 02 C4 0B, and the response byte count should be 04;
  2. FC 01: read 10 coils → expected request 01 01 00 00 00 0A BC 0D, and the response byte count should be 02;
  3. Compare the response data against the tables in this section and confirm that "byte count = 2 × number of registers" or "⌈number of coils/8⌉".

Common Misconceptions

Quiz Anchors

  1. FC 04 and FC 03 both read 16-bit values—what is the fundamental difference between them? (Hint: writable / read-only)
  2. For an FC03 response reading 5 holding registers, what should the byte count be?
  3. Reading 12 coils with FC01, what should the response byte count be?

Chapter Summary and What's Next

In this chapter you mastered the 4 read function codes: 01/02 read switches, 03/04 read values; you learned that a read request contains only "address + quantity", while a read response adds a "byte count" followed by the data. You can also read every command in the greenhouse "look, don't control" operation table.

In the next chapter we turn the page—looking is not enough; Ms. Wang also wants to turn on the exhaust fan and set the humidity target. That means the write function codes.