Skip to main content

Function codes

CodeFunctionNotes
01Read CoilsUp to 2000 coils per request.
02Read Discrete InputsSame data as function 01.
03Read Holding RegistersUp to 125 registers per request.
04Read Input RegistersSame data as function 03.
05Write Single CoilValue 0x0000 (off) or 0xFF00 (on).
06Write Single RegisterItems that occupy one register, and the first register of a STRING item.
15 (0x0F)Write Multiple CoilsUp to 1968 coils per request.
16 (0x10)Write Multiple RegistersUp to 123 registers per request.
43/14 (0x2B/0x0E)Read Device IdentificationSee 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