Operation
WebRelay-10 Users Manual
3.4.5 Read Discrete Inputs – Modbus Function Code 02 (0x02) (WebRelay-10 Plus™
only)
This function returns the state of the discrete inputs.
Start Address: 0x0000 (input1) to 0x0001 (input 2)
Input Quantity: 0x0001 to 0x0002
The sum of the starting address and the quantity of coils must not be greater than 0x0002. For example,
if you want to read 0x0002, both inputs, then the start address must be 0x0000. To read the second
input only the start address is 0x0001 with a quantity of 0x0001.
Request
Modbus TCP Request Frame Example – Read Inputs 1 - 2
Field Name
Length
Function
Example Data
Transaction Identifier
2 bytes
Synchronization number.
0x0001
Protocol Identifier
2 bytes
Zero for Modbus/TCP
0x0000
Message Length
2 bytes
Number of bytes in frame (below)
0x0006
Unit Identifier
1 byte
Slave Address (0xff if not used)
0xFF
Function Code
1 byte
Read Inputs
0x02
Data
4 bytes
Start Address (
0x0000-0x0001
)
Quantity (
0x0001-0x0002
)
0x0000
0x0002
TX String: 00 01 00 00 00 06 FF 02 00 00 00 02
Response
The inputs states are indicated by bits one and two of the status byte. A
1
indicates that the input is
switched to ground (
ON
). A
0
indicates that the input is open (
OFF
).
Data Byte (hex)
LS Data Bits (binary)
Input 2 State
Input 1 State
0x00
0000
OFF
OFF
0x01
0001
OFF
ON
0x02
0010
ON
OFF
0x03
0011
ON
ON
WebRelay-10 Response Frame Example – Inputs 1 and 2 ON
Field Name
Length
Function
Example Data
Transaction Identifier
2 bytes
Synchronization number.
0x0001
Protocol Identifier
2 bytes
Zero for Modbus/TCP
0x0000
Message Length
2 bytes
Number of bytes in frame (below)
0x0006
Unit Identifier
1 byte
Slave Address (0xff if not used)
0xFF
Function Code
1 byte
Read Inputs
0x02
Data
2 bytes
Byte count (
0x01
)
Input State (
0x00-0x03
)
0x01
0x03
RX String: 00 01 00 00 00 04 FF 02 01 03
page 68
Xytronix Research & Design, Inc.