Specifications

Revision 2.4 WebRelay-Quad™
Users Manual
3.3.2 Write Single Coil (Modbus Function Code 05 (0x05))
This function is used to change the state of the coil
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): 0x05 (write coil)
Output address (2 Bytes): 0x0000 – 0x0003 (specifies relay)
Output value (1 Byte): 0xff - turn relay on, 0x00 - turn relay off
Padding (1 Byte): 0x00
Character String Example:
char write_coil_mb_request[] =
{0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0xff, 0x05, 0x00, 0x00, 0xff, 0x00 };
Response
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): 0x05 (write coil)
Reference number (2 Bytes): 0x0000
Data (1 Byte): 0xff - relay on, 0x00 - relay off
Padding (1 Byte): 0x00
Modbus Error:
Function code (1 Byte): 0x85
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 write_coil_mb_response[] =
{0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0xff, 0x05, 0x00, 0x00, 0xff, 0x00 };
Xytronix Research & Design, Inc. page 34