Function codes
| Code | Function | Notes |
|---|---|---|
| 01 | Read Coils | Up to 2000 coils per request. |
| 02 | Read Discrete Inputs | Same data as function 01. |
| 03 | Read Holding Registers | Up to 125 registers per request. |
| 04 | Read Input Registers | Same data as function 03. |
| 05 | Write Single Coil | Value 0x0000 (off) or 0xFF00 (on). |
| 06 | Write Single Register | Items that occupy one register, and the first register of a STRING item. |
15 (0x0F) | Write Multiple Coils | Up to 1968 coils per request. |
16 (0x10) | Write Multiple Registers | Up to 123 registers per request. |
43/14 (0x2B/0x0E) | Read Device Identification | See Device identification. |
Any other function code returns exception 01 (Illegal Function).
The coils and discrete inputs are the same table, and so are the holding registers and input registers. Use whichever function your PLC or library prefers. See Addressing.
Example
Read coils 0–4 (function 01). The request frame, in hexadecimal:
00 01 00 00 00 06 01 01 00 00 00 05
│ │ │ │ │ │ └ quantity: 5 coils
│ │ │ │ │ └ start address: 0
│ │ │ │ └ function code 01
│ │ │ └ unit identifier (ignored)
│ │ └ length of what follows: 6 bytes
│ └ protocol identifier: always 0
└ transaction identifier, echoed in the response
The response carries one byte of coil states, coil 0 in the least significant bit:
00 01 00 00 00 04 01 01 01 05
│ └ coils 0 and 2 on (binary 00000101)
└ byte count