
Revision 3.1
WebRelay
TM
Users Manual
Length (2 Bytes): 0x0006
Unit identifier (1 Byte): 0xff
Modbus:
Function code (1 Byte): 0x01 (read coils)
Starting address (2 Bytes): 0x0000 (0x0000 or 0x0001)
Quantity of coils (2 Bytes): 0x0002 (0x0001 or 0x0002)
Character String Example:
char read_coils_mb_request[] ={0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0xff, 0x01, 0x00, 0x00, 0x00, 0x02 };
Response
Modbus/TCP:
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x0004
Unit identifier (1 Byte): 0xff
Modbus:
Function code (1 Byte): 0x01 (Read coils)
Byte count (1 Byte): 0x01
Coil status (1 Byte): 0x00, 0x01, 0x02, or 0x03 (bit 0 = relay state, bit 1 = input state)
Data Byte (hex)
LS Data Bits (binary)
Input State
Relay State
0x00
00
off
off
0x01
01
off
on
0x02
10
on
off
0x03
11
on
on
Modbus Error:
Function code (1 Byte): 0x81
Exception code (1 Byte): 0x01 or 0x02
Exception codes:
0x01 - Function code not supported
0x02 - Incorrect starting address / quantity of outputs combination
Character String Example:
char read_coils_mb_response[] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0xff, 0x01, 0x01, 0x01};
3.4.2 Read Discrete Inputs (Modbus Function Code 02 (0x02))
This function returns the state of the optically-isolated input.
Request
Modbus/TCP:
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x0006
Unit identifier (1 Byte): 0xff
Modbus:
Function code (1 Byte): 0x02 (read inputs)
Starting address (2 Bytes): 0x0000 (always 0x0000)
Quantity of inputs (2 Bytes): 0x0001 (always 0x0001)
Xytronix Research & Design, Inc.
page 46