Modbus Function Code Workbench
Choose the right Modbus operation, inspect its PDU bytes, and decode normal versus exception responses.
Modbus Function Code Workbench
Select an operation, then watch the request PDU, normal response, and exception response change together. The same function code byte tells the server whether the client wants bits, registers, a write echo, or an error report.
Stage 1: choose the data table
Function codes are tied to the kind of object being addressed: coils, discrete inputs, input registers, or holding registers.
Coils
0x bit table Read/write boolean outputs. Read with FC01, write with FC05 or FC15.Discrete inputs
1x bit table Read-only boolean inputs. Read with FC02.Input registers
3x 16-bit table Read-only measured values. Read with FC04.Holding registers
4x 16-bit table Read/write settings or state. Read with FC03, write with FC06 or FC16.Request PDU
Client asks for holding registers starting at protocol address 0x006B.
Normal response
Read responses return byte count followed by data bytes.
Exception response
The server sets bit 7 of the original function code and returns one exception byte.
What to notice
FC01
Read coilsRead one or more 0x boolean outputs.
FC02
Read discrete inputsRead one or more 1x boolean inputs.
FC03
Read holding registersRead one or more 4x 16-bit registers.
FC04
Read input registersRead one or more 3x 16-bit registers.
FC05
Write single coilWrite ON as 0xFF00 or OFF as 0x0000.
FC06
Write single registerWrite one 4x 16-bit register and echo the request.
FC15
Write multiple coilsWrite packed boolean outputs; hexadecimal code is 0x0F.
FC16
Write multiple registersWrite a block of 4x registers; hexadecimal code is 0x10.
Core idea
The function code is the first byte of the Modbus PDU. It selects the operation; the following bytes only make sense after that byte is known.
Common trap
FC15 and FC16 are decimal names. In packet bytes they appear as 0x0F and 0x10, so do not read the labels as hexadecimal values.
Exception rule
An exception response is not a different command. It is the original function code with bit 7 set, followed by a one-byte reason code.
Quick reference and technical notes
This workbench focuses on the Modbus PDU. RTU, ASCII, and TCP add different transport envelopes around the same function-code request.