Operation
WebRelay-10 Users Manual
3.4.7 Write Single Coil
–
Modbus Function Code 05 (0x05)
This function allows you to control relays one at a time.
Relay Address (2 bytes):
0x0000 (Relay 1) – 0x00009 (Relay 10)
Relay Value (1 byte):
0x00 (ON)), 0xFF(OFF)
Padding (1 byte):
0x00
Request
Modbus TCP Request Frame Example – Write Coil 3 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
Write Coil
0x05
Data
4 bytes
Relay address (0x0000 – 0x0009)
Relay value (0x00, 0xFF)
Padding (0x00)
0x0002
0xFF
0x00
Tx String: 00 01 00 00 00 06 FF 05 00 02 FF 00
Response
WebRelay-10 Response Frame Example – Write Coil 3 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
Write coil
0x05
Data
4 bytes
Relay address (0x0000 - 0x0009)
Relay value (0xFF, 0x00)
Padding (0x00)
0x0003
0xFF
0x00
Rx String: 00 01 00 00 00 06 FF 05 00 02 FF 00
Errors
Single Coil Write Error Function Code (1 Byte): 0x85
Exception codes (1 Byte):
0x01 – Function not supported.
0x02 – Address out of range.
0x03 – Incorrect relay value or padding value.
page 72
Xytronix Research & Design, Inc.