Automation Glossary • Modbus Function Code 02 Read Discrete Inputs

Modbus FC02 (Read Discrete Inputs)

Merobix Engineering • • 4 min read

Function code 02 reads discrete inputs, the single-bit read-only status values a device reports but never lets you write. When you are mapping limit switches, run-status flags, or fault bits from a device, FC02 is usually the right verb. This reference explains what FC02 targets, how it packs its reply, and why it differs from the coil read that looks almost identical on the wire.

Back to Blog

Modbus Function Code 02 Read Discrete Inputs in one line: Modbus function code 02 reads discrete inputs: the read-only single-bit status values such as limit switches and fault flags. The request names a starting input address and a quantity, and the device replies with those inputs packed eight to a byte, least-significant bit first. It reads only the discrete-input table, and there is no write code because the table is read-only by design.

What FC02 Reads and How It Replies

Discrete inputs are the Modbus table of single read-only bits, typically wired to physical status contacts like a limit switch, a level float, or a fault relay, or exposed by firmware as a status flag. Function code 02 reads a contiguous block of them. The request carries a starting address and a quantity, and the reply is a byte count followed by the input states packed eight to a byte, first input in the least significant bit of the first byte, just like a coil read.

The response format is identical to function code 01, so on the wire the two look the same apart from the code byte. The difference is entirely which table they read. Because discrete inputs are read-only, there is no matching write code, which is enforced simply by the absence of one. The place of this table among the four is described in the Modbus register types reference.

FC02 Versus FC01 and the Read-Only Rule

The recurring confusion is between function code 02 and function code 01, because both read bits and both pack the reply the same way. The rule is that a value you can both read and command lives in the coil table and uses FC01, while a value the device only reports lives in the discrete-input table and uses FC02. Mapping a run-status input as a coil, or a command as a discrete input, is a common map error that surfaces as an exception. The general grouping of read and write codes is in the Modbus function code overview.

Because discrete inputs cannot be written, any attempt to write one is by definition unsupported, and a device will reject it. When FC02 returns an illegal data address exception rather than data, the input is either out of range or expressed in a different addressing base than your map assumes, which is a matter for the Modbus register addressing reference to resolve.

Frequently Asked Questions

Can you write a discrete input with Modbus?

No. Discrete inputs are read-only by definition and Modbus provides no write function code for them. If a value needs to be commanded on or off it belongs in the coil table and is written with function code 05 or 15. A discrete input only reports device status; it never accepts a command from the master.

Why do FC01 and FC02 replies look identical?

Both read single bits and both pack the reply eight bits to a byte, least-significant bit first, with a leading byte count. The only wire difference is the function code byte itself. What separates them is the table: FC01 reads the read-write coil table and FC02 reads the read-only discrete-input table.

What kinds of signals map to discrete inputs?

Anything the device reports as a single on/off status that the master should not command: limit and proximity switches, level floats, run-confirmation feedback, and fault or alarm flags are typical. If the same signal also needs to be set by the master, it belongs in the coil table instead and is read with FC01.

Sources and verification

This page references the protocol specifications published by the organizations below. Editions, product capabilities, and documentation change over time - confirm current requirements and specifications directly with the source.

Merobix is not affiliated with, endorsed by, or sponsored by these organizations; their names are used only to identify the standards and products discussed.

More in Industrial Protocols
Modbus Function Code 01 Read Coils  •  Modbus Function Code 03 Read Holding Registers  •  Modbus Function Code 04 Read Input Registers  •  Modbus Function Code 07 Read Exception Status  •  Modbus Illegal Function (Exception 01)  •  All Industrial Protocols →
Free SCADA operator training
Merobix University - 70 video lessons & 261 quiz questions, from first login to compliance reporting. No demo call required.
Start free →