Modbus Function Code 20 (0x14): Read File Record Specification & Hex Guide
Standard Holding Registers (FC 03) address a flat 65,536-word register space, which quickly runs tight in protection relays, flow computers, and batch recorders storing multi-megabyte oscillography or historical archives. To retrieve structured multi-file records cleanly, the Modbus Application Protocol Specification V1.1b3 defines Function Code 20 (0x14) — Read File Record.
Function Code 20 organizes extended 6xxxx memory into numbered files (1 to 65,535) containing up to 10,000 sequential 16-bit registers per file—and lets a master bundle multiple non-contiguous file reads inside a single request PDU. This guide breaks down the sub-request format, hex PDU framing, exception rules, Python pymodbus code, and simulation in ModbusSimulator.
1. How Function Code 20 Works (V1.1b3 Specification)
Unlike single-range register reads, Function Code 0x14 carries a 1-byte Byte Count (0x07–0xF5, i.e., 7 to 245 bytes) followed by one or more 7-byte Sub-Request blocks:
- Reference Type (1 Byte): Must be
0x06for extended file record space. - File Number (2 Bytes): Unsigned 16-bit integer from
0x0001to0xFFFFidentifying which archive file to query. - Record Number (2 Bytes): Starting 0-based record index inside that file (
0x0000to0x270F/ 0–9999). - Record Length (2 Bytes): Number of consecutive 16-bit registers to read starting at Record Number.
2. Request & Response Hex Frame Analysis
Suppose a SCADA master requests 2 registers from File Number 4 (0x0004) starting at Record Number 1 (0x0001) on Unit ID 1, and the slave returns register values 0x0DFE and 0x0020.
Modbus RTU Request Frame (11 Bytes)
[Slave] [FC] [ByteCnt] [Ref] [FileNo] [RecNo] [RecLen] [CRC-16]
01 14 07 06 00 04 00 01 00 02 [CRC]
Modbus TCP Request ADU (15 Bytes)
[Trans ID] [Proto] [Len] [Unit] [FC] [ByteCnt] [Ref] [FileNo] [RecNo] [RecLen]
00 01 00 00 00 09 01 14 07 06 00 04 00 01 00 02
Modbus TCP Normal Response ADU
[Trans ID] [Proto] [Len] [Unit] [FC] [RespLen] [SubLen] [Ref] [Word 0] [Word 1]
00 01 00 00 00 09 01 14 07 05 06 0D FE 00 20
| Response Field | Hex Value | Size & Meaning |
|---|---|---|
| Function Code | 0x14 | 1 byte — Read File Record (decimal 20) |
| Resp. Data Length | 0x07 | 1 byte — Total bytes following in PDU (1 + 1 + 4 + 1 = 7) |
| File Resp. Length | 0x05 | 1 byte — Sub-response length including Reference Type (1 + 2 × 2 = 5) |
| Reference Type | 0x06 | 1 byte — Confirms extended file record memory |
| Record Data | 0D FE 00 20 | 4 bytes — Two 16-bit Big-Endian register values (3582 and 32) |
3. Standard Exception Codes for FC 20
If any sub-request fails validation, the device responds with function code 0x94 (0x14 | 0x80) and a standard Modbus exception code:
| Exception Code | Name | Root Cause in FC 20 |
|---|---|---|
0x01 | Illegal Function | PLC or meter does not support Function Code 20. |
0x02 | Illegal Data Address | File Number does not exist or Record Number + Length exceeds file bounds. |
0x03 | Illegal Data Value | Byte Count not a multiple of 7 (+0), Reference Type != 0x06, or PDU overflow. |
0x04 | Server Device Failure | Flash/EEPROM archive read error inside the remote device. |
4. Python Implementation Using Pymodbus
from pymodbus.client import ModbusTcpClient
from pymodbus.file_message import FileRecord
def read_plc_file_record(host="127.0.0.1", port=502, file_no=4, record_no=1, length=2, slave_id=1):
client = ModbusTcpClient(host=host, port=port, timeout=2.0)
if not client.connect():
raise ConnectionError(f"Failed to connect to {host}:{port}")
record_req = FileRecord(file_number=file_no, record_number=record_no, record_length=length)
resp = client.read_file_record([record_req], slave=slave_id)
if resp.isError():
print(f"FC 20 Error: {resp}")
else:
for rec in resp.records:
print(f"File {rec.file_number} Record {rec.record_number}: {rec.record_data}")
client.close()
if __name__ == "__main__":
read_plc_file_record()
5. Debugging Modbus Frames With ModbusSimulator
Before deploying telemetry parsers against field relays or RTUs, test register layouts, byte order, and serial/TCP framing using ModbusSimulator (Windows Modbus emulator, Modbus slave simulator, and Modbus TCP simulator). Explore companion protocol guides like FC 24 (Read FIFO Queue) and Modbus Data Types & Byte Order.
Test Modbus TCP & RTU Devices Without Hardware
Download ModbusSimulator for Windows — unified Master + Slave simulator with live register grids, hex frame capture, and 30-day free trial.
Download Free 30-Day TrialFrequently Asked Questions
What is Modbus Function Code 20 (0x14)?
Function Code 20 is Read File Record, allowing a Modbus master to read numbered files and 16-bit record ranges from extended 6xxxx device memory.
What is Reference Type 0x06 in FC 20?
0x06 is the mandatory identifier defined by Modbus V1.1b3 for file-record sub-requests and sub-responses.
Can one FC 20 request read multiple files?
Yes. You can pack multiple 7-byte sub-requests inside one FC 20 request as long as both the request and response fit inside the 253-byte PDU limit.
What is the maximum Record Number in FC 20?
Per the specification, Record Number ranges from 0x0000 (0) through 0x270F (9,999) per file.