40
7 OPTION
40
OPTION
Chapter
7
■Function codes for Modbus
Function codes are explained in detail.
In this chapter, function fields and data fields varying by function codes are explained.
Each actual message frame consists of an address field, function field, data field, and error check
field, which are transmitted in this order.
List of function codes
01 (0x01) Read coils
ON/OFF states of slave coils are read.
Since this is a read command, no broadcast can be specified.
Specify the coil start address and number of coils.
* N = Number of coils/8 or N = N + 1 if indivisible
Example) Read the digital zero (address 00003) state.
Code Function name Command
01 (0x01) Read coils Read out coils
02 (0x02) Read discrete inputs Read out input statuses
03 (0x03) Read holding registers Read out holding registers
04 (0x04) Read input register Read out the input register
05 (0x05) Write single coil Write in a coil (single)
06 (0x06) Write single register Write in a holding register (single)
15 (0x0F) Write multiple coils Write in coils (multiple)
16 (0x10) Write multiple registers Write in holding registers (multiple)
08 (0x08) Diagnostics Diagnosis mode
11 (0x0B) Get comm event counter Read out the event counter
12 (0x0C) Get comm event log Read out communication events
17 (0x11) Report slave ID Read out slave ID information
[Request]
Function 1 byte 0x01
Start address 2
bytes 0x0000 - 0xFFFF
Number of coils 2
bytes 1 - 2000 (0x07D0)
[Response]
Function 1 byte 0x01
Number of data bytes 1
byte N *
Coil status N
bytes N or N+1
[Error response]
Error code 1 byte 0x81 (function + 0x80)
Exception code 1
byte 01 or 02 or 03
[Request]
Function 01
[Response]
Function 01
Start address; higher 00 Number of data bytes 01
Start address; lower 02 Digital zero 00
Number of coils; higher 00
Number of coils; lower 01