
Modbus RTU Function Codes
02/13 Modbus® RTU Serial Communications User Manual 15
3.2 Function Code 02 – Read Digital Input Status
Description
Function code 02 (1X references) is used to read a Digital Input’s (DI) ON/OFF status of the slave device in
a binary data format. All binary data transferred using function code 02 is mapped into bytes.
The specific number of inputs available in an instrument or available via one Function Code 02 message is
instrument-model specific.
Broadcast is not supported.
Query
The query message specifies the starting input and the quantity of inputs to read. Inputs are addressed
starting at zero: Input 1 through 16 are addressed as 0 through 15 respectively
Query message format for function code 02
Slave
Address
Function
Code
Starting
Address
High
Starting
Address
Low
Number
Inputs
High
Number
Inputs
Low
CRC CRC
Example:
Read inputs number 1 to 7 from slave at address 02.
02 02 00 00 00 07 CRC CRC
Response
The input status in the response message is packed as one input per bit of the data field. Status is indicated
as: 1 = ON; 0 = OFF. The LSB of the first data byte contains the input addressed in the query. The other
inputs follow toward the high order end of this byte, and from low order to high order in subsequent bytes.
If the returned input quantity is not a multiple of eight, 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 data
bytes returned.
Response message format for function code 02
Slave
Address
Function
Code
Byte
Count
Data Data … CRC CRC
Example:
Inputs number 2 and 7 are on, all others are off.
02 02 01 42 CRC CRC
In the response the status of inputs 1 – 7 is shown as the byte value 42 hex, or 0100 0010 binary. Input 8 is
the MSB of this byte, and input 1 is the LSB. Left to right, the status of input 7 through 1 is: ON-OFF-OFF-
OFF-OFF-ON-OFF. Input #8 was not requested and so bit #7 or the MSB was padded with a 0.
Kommentare zu diesen Handbüchern