Modbus Frame Decoder
Paste the hex bytes of a Modbus RTU, TCP or ASCII frame. The decoder splits them into fields, checks the CRC, pairs requests with responses and explains exception codes.
Frames
ExampleRTU with CRC, TCP with MBAP header, or ASCII starting with a colon. Put several frames on separate lines. Wireshark hex streams, Wireshark hex dumps and Modbus Poll logs work as they are.
Decoded frames
Runs entirely in your browser. Nothing you enter is sent to a server.
How Modbus frames are built
Modbus RTU
| Part | Bytes |
|---|---|
| Device address (unit ID) | 1 |
| Function code | 1 |
| Data | 0–252 |
| CRC, low byte first | 2 |
Modbus TCP
| Part | Bytes |
|---|---|
| Transaction ID | 2 |
| Protocol ID, always 0 | 2 |
| Length: unit ID + PDU | 2 |
| Device address (unit ID) | 1 |
| Function code | 1 |
| Data | 0–252 |
Modbus ASCII
| Part | Bytes |
|---|---|
| : | 1 |
| Device address (unit ID) | 2 |
| Function code | 2 |
| Data | 0–504 |
| LRC | 2 |
| CR LF | 2 |
The part from the function code to the end of the data is called the PDU and is the same in all three variants. Register values are sent high byte first; only the RTU CRC goes low byte first.
How the decoder reads a frame
First it looks for the envelope. An RTU frame ends with a CRC that matches the bytes before it. A TCP frame starts with a 7-byte MBAP header whose length field matches the rest. An ASCII frame starts with a colon. Inside the envelope, the function code says how the rest is built. A request and a response of the same function have a different structure, so the decoder can tell them apart, and it pairs each response with the request before it.
A response to a read carries only the values, not the start address. Paste the request together with the response and the decoder shows the real register numbers. One click opens the values in the register decoder, which finds floats, 32-bit values and the byte order.
Common mistakes
- Exception 02 although the register exists. Usually the address is off by one: register 40001 is address 0 in the frame. The address converter shows both.
- No response at all. A device stays silent when the CRC is wrong, the device address does not match, or baud rate and parity differ. If the decoder finds the request correct, look at the wiring and serial settings. The CRC calculator builds a correct frame for a test.
- Whole Ethernet packet pasted. That is fine. The decoder skips the Ethernet, IP and TCP headers when the IPv4 checksum is valid. With several packets, put each on its own line.
- Responses assigned to the wrong request. In Modbus TCP, the transaction ID pairs a response with its request. A client that reuses IDs too soon gets confusing results, and so does a log in which requests and responses are not in order.
Questions from practice
What is in the Modbus TCP MBAP header?
Seven bytes: transaction ID (2), protocol ID (2, always 0), length (2) and unit ID (1). The length counts the bytes after it, so the unit ID plus the PDU. 00 01 00 00 00 06 11 means transaction 1, Modbus protocol, 6 bytes follow, unit 17.
How do I copy a Modbus frame from Wireshark?
Right-click the Modbus/TCP line in the packet details and copy it as a hex stream, or copy the bytes of the whole packet. Both work: the decoder recognises the Ethernet, IPv4 and TCP headers and skips them. A hex dump with offsets and an ASCII column works too.
Why does a decoded response show no register numbers?
A read response contains a byte count and the values, nothing else. Which registers they came from is only in the request. Paste the request on the line above the response and the decoder pairs them, numbers the registers and passes the start address on to the register decoder.
What is the difference between Modbus TCP and RTU over TCP?
Modbus TCP puts the 7-byte MBAP header in front of the PDU and has no CRC. RTU over TCP sends the unchanged serial frame, device address and CRC included, through a TCP connection. A client set to the wrong variant gets no answer. The decoder handles both: a frame with a valid CRC is shown as RTU, however it was transported.
What does exception code 0B mean?
Gateway Target Device Failed to Respond: the Modbus TCP gateway received the request and sent it to the serial line, but the device behind it did not answer in time. Check that the unit ID matches the serial device address, then the gateway's baud rate and parity and the RS-485 wiring. Code 0A means the gateway did not even know where to send the request.
Related tools
- Register DecoderFloat32, Int32, UInt16 and bits in every byte order, plus Find my value.
- Address Converter40001 ↔ offset 0, 4x/3x/0x/1x notation, 5- and 6-digit addresses.
- Value EncoderTurn a value like 230.5 into registers for every byte order.
- CRC-16 CalculatorModbus RTU checksum in wire order, plus a full frame check.
- Function & Exception CodesWhat each code means and the usual cause in practice.