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 code1 Byte0x05
Output Address2 Bytes0x0000 to 0xFFFF
Output Value2 Bytes0x0000 or 0xFF00
Table 1 - Command structure

Response

The normal response is an echo of the request, returned after the coil state has been written.

Function code1 Byte0x05
Output Address2 Bytes0x0000 to 0xFFFF
Output Value2 Bytes0x0000 or 0xFF00
Table 2 - Response structure

Error

Error code1 Byte0x85
Exception code1 Byte01 or 02 or 03 or 04
Table 3 - Error structure. Scroll below for details.

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

write single coil
Figure 1 - Write Single Coil

Contents retrieved from

  • http://modbus.org/
  • http://www.simplymodbus.ca/

More information