ceo@instrumentationblog.in
Communication Protocols · Free Tool

Modbus TCP Frame Decoder

Paste a Modbus TCP frame in hex, as captured by Wireshark or a test tool. The decoder splits the MBAP header, checks the length field, and decodes the function code, addresses, quantities, data values and exception codes byte by byte.

MBAP header checkFunction codes 01 to 06, 15, 16Requests and responsesException codes
Examples:
Function
Frame type
Length field check
Summary
How this result was found
    Advertisement

    How a Modbus TCP Frame Is Built

    A Modbus TCP message, called the ADU, is the normal Modbus PDU (function code plus data) with a 7 byte MBAP header in front. There is no CRC: TCP already checks the data. All Modbus TCP traffic goes to the registered TCP port 502. The header is defined in the Modbus Messaging on TCP/IP Implementation Guide.

    FieldBytesMeaningSet by
    Transaction identifier2Pairs a response with its requestClient; server copies it back
    Protocol identifier20 = Modbus protocolClient; server copies it back
    Length2Number of following bytes (unit identifier plus PDU)Client in the request, server in the response
    Unit identifier1Slave address behind a gateway; often 1, 0 or 255 for a direct TCP deviceClient; server copies it back
    Function code1What to do (03 = read holding registers)Client; server adds 0x80 on an error
    Data0 to 252Addresses, quantities, byte count, valuesBoth
    Length field = 1 (unit identifier) + PDU bytes = total frame bytes − 6
    Exception function code = request function code + 0x80

    Worked example

    The request 00 01 00 00 00 06 11 03 00 6B 00 03 decodes as transaction 1, protocol 0, length 6, unit 17 (0x11), function 03 Read Holding Registers, start address 0x006B = 107 and quantity 3. Counting the bytes after the length field gives 1 + 5 = 6, so the length is OK. In 1 based Modicon numbering the client is reading registers 40108 to 40110.

    The response 00 01 00 00 00 09 11 03 06 02 2B 00 00 00 64 carries the same transaction and unit, a byte count of 6 and three values: 0x022B = 555, 0 and 0x0064 = 100. The tool opens with the request; click the FC03 response example to see the values.

    Function codes and limits

    CodeNameRequest dataLimit per request
    01 / 02Read Coils / Discrete Inputsstart, quantity2000 bits
    03 / 04Read Holding / Input Registersstart, quantity125 registers
    05Write Single Coiladdress, FF00 (on) or 0000 (off)1 coil
    06Write Single Registeraddress, value1 register
    15 (0x0F)Write Multiple Coilsstart, quantity, byte count, bits1968 coils
    16 (0x10)Write Multiple Registersstart, quantity, byte count, values123 registers

    Common exception codes are 01 illegal function, 02 illegal data address, 03 illegal data value, 04 server device failure, 06 server device busy, 0A gateway path unavailable and 0B gateway target device failed to respond.

    Key insight: the address in the frame is a 0 based offset. Register 40001 is sent as 0x0000, so an "off by one" reading is almost always a numbering mismatch, not a broken device. Check it with the Modbus address calculator.

    For serial frames with a CRC use the Modbus RTU frame decoder and the Modbus CRC calculator. To turn two registers into a real number, use the IEEE 754 float converter.

    Advertisement

    Frequently Asked Questions

    What is the MBAP header in Modbus TCP?

    The 7 byte Modbus Application Protocol header: transaction identifier (2), protocol identifier (2), length (2) and unit identifier (1). It replaces the slave address and CRC of Modbus RTU.

    What does the length field count?

    The number of bytes that follow it: the unit identifier plus the function code and data. It equals the total frame length minus 6.

    What unit identifier should I use for Modbus TCP?

    For a device addressed directly by IP the value is often ignored; 1, 0 or 255 are common. Behind a TCP to RTU gateway it must be the slave address of the serial device.

    Does Modbus TCP have a CRC?

    No. TCP and Ethernet already check the data, so Modbus TCP frames carry no CRC.

    What does function code 0x83 mean?

    It is an exception response to function 03. The next byte is the exception code, for example 02 means illegal data address.

    You May Also Like

    Learn more on the blog

    Modbus protocol explained: RTU vs TCP

    A practical guide on instrumentationblog.in that explains the theory behind this tool with solved examples.

    Read Full Article

    More Communication Protocols

    More Instrumentation Tools

    2 toolsInstrument Tag DecoderDecode ISA 5.1 instrument tags and look up every identification letter.4 toolsIP, NEMA and Ex Rating DecoderDecode IP codes, NEMA enclosure types, ATEX and IECEx Ex markings and hazardous area zones.4 toolsWire and Cable Color CodesWire colour codes for power, control panels, thermocouples and RTDs by standard.9 toolsPID Tuning ToolsPID tuning calculators, PID form converter and an online PID loop simulator.4 toolsP&ID SymbolsSearchable P&ID symbols for instruments, lines, valves and flow elements.3 toolsPipe and Flange ChartsPipe schedules, ASME B16.5 flange dimensions and pressure ratings.4 toolsThread Size ChartsNPT, BSP and metric thread sizes and a thread identifier for instrument fittings.17 toolsTroubleshooting GuidesInteractive fault finders for transmitters, flowmeters, valves and loops.18 toolsPractice TestsInstrumentation quizzes with instant scores and explained answers.5 toolsDigital Logic ToolsK map solver, Boolean algebra simplifier and truth table generator for digital electronics and PLC logic.4 toolsElectrical Selection ToolsConduit fill and wire gauge calculators to the NEC, plus an ANSI device numbers decoder for protection relays.2 toolsMechanical ChartsGalvanic corrosion chart with a metal pair checker and a bolt torque calculator for SAE and metric bolts.3 toolsProcess Engineering ToolsPsychrometric calculator with a live chart and a flow rate calculator for pipes.CalculatorsCalculatorsFree engineering calculators for flow, level, pressure, temperature, valves and more.ConvertersUnit Converters76 converters, 700+ units.