Mobdbus function code 5
Write Single Coil on Modbus
This function code is used to write a single output to either On or Off in a remote device. The requested On/Off state is specified by a constant in the request data field. A value of FF 00 hex requests the output to be On. A value of 00 00 requests it to be Off. All other values are illegal and will not affect the output.
The Request PDU specifies the address of the coil to be forced. Coils are addressed starting at zero. Therefore coil numbered 1 is addressed as 0. The requested On/Off state is specified by a constant in the Coil Value field. A value of 0XFF00 requests the coil to be On. A value of 0X0000 requests the coil to be off. All other values are illegal and will not affect the coil.
Request
Function code | 1 Byte | 0x05 |
Output Address | 2 Bytes | 0x0000 to 0xFFFF |
Output Value | 2 Bytes | 0x0000 or 0xFF00 |
Response
The normal response is an echo of the request, returned after the coil state has been written.
Function code | 1 Byte | 0x05 |
Output Address | 2 Bytes | 0x0000 to 0xFFFF |
Output Value | 2 Bytes | 0x0000 or 0xFF00 |
Error
Error code | 1 Byte | 0x85 |
Exception code | 1 Byte | 01 or 02 or 03 or 04 |
Example
Request
This command is writing the contents of discrete coil # 192 to OFF in the slave device with address 11.
0B 05 00BF 0000 FC84 |
- 0B: The Slave Address (0B hex = address 11)
- 05: The Function Code 5 (Write Single Coil)
- 00BF: The Data Address of the coil (coil# 192 - 1 offset = 191 = BF hex).
- 0000: The status to write (FF00 = ON, 0000 = OFF).
- FC84: The CRC (Cyclic Redundancy Check) for error checking.
Response
The normal response is an echo of the query, returned after the coil has been written.
0B 05 00BF 0000 FC84 |
- 0B: The Slave Address (0B hex = address 11)
- 05: The Function Code 5 (Write Single Coil)
- 00BF: The Data Address of the coil (coil# 192 - 1 offset = 191 = BF hex).
- 0000: The status written (FF00 = ON, 0000 = OFF)
- FC84: The CRC (Cyclic Redundancy Check) for error checking
Workflow Diagram for Modbus FC 5
Contents retrieved from
- http://modbus.org/
- http://www.simplymodbus.ca/
More information
- Modbus Function Codes
- Mobdbus function code 1 - read coils
- Mobdbus function code 2 - read discrete inputs
- Mobdbus function code 3 - read multiple holding registers
- Mobdbus function code 4 - read input registers
- Mobdbus function code 5 - write single coil
- Mobdbus function code 6 - write single holding register
- Mobdbus function code 15 - write multiple coils
- Mobdbus function code 16 - write multiple holding registers
- Modbus References
- Modbus protocol basics