02 (0x02) Read Discrete Inputs
This function code is used to read from 1 to 2000 contiguous status of discrete inputs in a remote device. The Request PDU specifies the starting address, i.e. the address of the firstinput
specified, and the number of inputs. In the PDU Discrete Inputs are addressed starting at zero. Therefore Discrete inputs numbered 1-16 are addressed as 0-15.The discrete inputs in the response message are 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 d ata byte will be padded with zeros (toward the high order end of the byte). The Byte Count field specifies the quantity of complete bytes of data.
The status of discrete inputs 204–197 is shown as the byte value AC hex, or binary 1010 1100. Input 204 is the MSB of this byte, and input 197 is the LSB.
The status of discrete inputs 218–213 is shown as the byte value 35 hex, or binary 0011 0101.Input 218 is in the third bit position from the left, and input 213 is the LSB.
Tx:01 02 00 C4 00 16
Rx:01 02 03 AC DB 35
0xC4 = 196
0x16 = 22
[197,218]
[197,204]
[205,212]
[213,218]
[204,197] 204:MSB 197:LSB
[212,205] 212:MSB 205:LSB
[218,213] 218:MSB 213:LSB
本文介绍Modbus协议中使用功能码02读取远程设备中连续的离散输入状态的方法。详细解释了请求与响应PDU的具体内容,包括起始地址、输入数量及如何将状态打包为数据字段。
1045





