ModBus协议-功能码-0x02



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.

ModBus协议-功能码-0x02_第1张图片

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协议-功能码-0x02_第2张图片






你可能感兴趣的:(ModBus协议)