Simply Modbus logo
← Previous: Modbus RTU
Next: Read Coil FC01

Modbus Read Discrete Inputs (FC02)

Function Code 02

Request

Request

This command is requesting the ON/OFF status of discrete inputs # 10197 to 10218
from the slave device with address 17.

11 02 00C4 0016 BAA9

11: The SlaveID (11 hex = address 17 )
02: The Function Code 2 (read Input Status)
00C4: The Data Address of the first input to read.
             ( 00C4 hex = 196 , + 10001 offset = input #10197 )
0016: The total number of coils requested. (16 hex = 22,  inputs 10197 to 10218 )
BAA9: The CRC (cyclic redundancy check) for error checking.

Response

11 02 03 ACDB35 2018

11: The SlaveID (11 hex = address 17 )
02 : The Function Code 2 (read Input Status)
03 : The number of data bytes to follow (22 Inputs / 8 bits per byte = 3 bytes)
AC : Discrete Inputs 10204 -10197 (1010 1100)
DB : Discrete Inputs 10212 - 10205 (1101 1011)
35 : 2 space holders & Discrete Inputs 10218 - 10213 ( 0011 0101)
2018: The CRC (cyclic redundancy check).

The more significant bits contain the higher discrete inputs.
For example, The first data byte in the response is AC
It shows the first (most significant) bit for input 10204 is on ( 1)
and the last (least significant) bit for input 10197 is off ( 0).

Due to the number of inputs requested, the last data byte 35 contains the status of only 6 inputs.
The first two (most significant) bits in this byte are filled in with zeroes.


← Previous: Modbus RTU
Next: Read Coil FC01