Read Input Status (Function Code 02)
Query
This function allows you to obtain the ON/OFF status of discrete inputs (Modbus 1x
range) in the addressed slave. PC Broadcast mode is not supported with this function
code. In addition to the slave address and function fields, the message requires
that the information field contain the initial input address to be read (Starting
Address) and the number of locations that are interrogated to obtain status
data.
The addressing allows up to 2000 inputs to be obtained at each request; however, the
specific slave device can have restrictions that lower the maximum quantity. The
inputs are numbered form zero; (input 10001 = zero, input 10002 = one, input 10003 =
two, and so on, for a 584).
The following table is a sample read input status request to read inputs 10197 to
10218 (22 coils) from slave number 11.
TIP:
This is the structure of the message being
sent out to the Modbus network. The following byte values are displayed in
hexadecimal format.
Node Address
| Function Code
| Data Start Point High
| Data Start Point Low
| Number of Points High
| Number of Points Low
| Error Check Field (2 bytes)
|
0B | 02 | 00 | C4 | 00 | 16 | CRC |
Response
An example response to Read Input Status is as shown in the following table. The data
is packed one bit for each input. The response includes the slave address, function
code, quantity of data characters, the data characters, and error checking. Data is
packed with one bit for each input (1 = ON, 0 = OFF). The lower-order bit of the
first character contains the addressed input, and the remainder follows. For input
quantities that are not even multiples of eight, the last characters are completed
with zeros at high-order end. The quantity of data characters is always specified as
a quantity of RTU characters, that is, the number is the same whether RTU or ASCII
is used.
Because the slave interface device is serviced at the end of a controller's scan, the
data reflects input status at the end of the scan. Some slaves limit the quantity of
inputs provided each scan; thus, for large coil quantities, multiple PC transactions
must be made using coil status for sequential scans.
Node Address
| Function Code
| Byte Count
| Data Discrete Input 10197…10204
| Data Discrete Input 10205…10212
| Data Discrete Input 10213…10218
| Error Check Field (2 bytes)
|
0B | 02 | 03 | AC | DB | 35 | CRC |
The status of inputs 10197…10204 is shown as AC (HEX) = 10101 1100 (binary). Reading
from left to right, this show that inputs 10204, 10202, and 10199 are all On. The
other input data bytes are decoded similarly.
Due to the quantity of input statuses that are requested, the last data field that is
shown as 35 HEX = 0011 0101 (binary) contains the status of only 6 inputs
(10213…102180) instead of 8 inputs. The two leftmost bits are provided as zeros to
fill the 8-bit format.
Provide Feedback