PLCBytes
Modbus tools

Modbus Frame Converter: RTU ↔ TCP ↔ ASCII

Paste a Modbus frame in any form and get the same request or response as Modbus RTU, Modbus TCP and Modbus ASCII, with the CRC, MBAP header and LRC recalculated.

Frames

Example

RTU with CRC, TCP with MBAP header, ASCII starting with a colon, or just the PDU (function code and data). One frame per line. Wireshark hex streams and Modbus Poll logs work as they are.

Examples

Leave both fields empty to keep the values from the frames. A frame without a transaction ID gets one counted from 1, and a response always gets the ID of its request.

Converted frames

Open in frame decoder

Runs entirely in your browser. Nothing you enter is sent to a server.

What each variant adds to the PDU

PartRTUTCPASCII
Start——colon (3A)
Header—transaction ID 2 B, protocol ID 0 2 B, length 2 B—
Device address1 byteunit ID, 1 byte2 hex characters
PDU (function code + data)binarybinaryhex text, 2 characters per byte
CheckCRC-16, low byte firstnone, TCP protects the dataLRC, 2 hex characters
End of framesilence of 3.5 charactersgiven by the length fieldCR LF (0D 0A)

The PDU is the same in all three variants, so a conversion never changes register values. A PDU has at most 253 bytes.

How the conversion works

All three Modbus variants carry the same PDU: the function code and its data. Only the envelope differs. RTU puts the device address in front and a CRC-16 at the end. TCP puts a 7-byte MBAP header in front (transaction ID, protocol ID 0, length, unit ID) and has no checksum. ASCII writes the address, the PDU and an LRC as hex text between a colon and CR LF. The converter takes the PDU out of whatever you paste and wraps it again, so the CRC, the length and the LRC are always recalculated. To see what each byte means, open the frames in the frame decoder.

A Modbus TCP to RTU gateway does exactly this with every request. When a gateway setup does not work, compare what your software sends over TCP with what should appear on the RS-485 side.

Common mistakes

Questions from practice

How do I convert a Modbus RTU frame to Modbus TCP?

Remove the two CRC bytes from the end, keep the device address as the unit ID and put six bytes in front: the transaction ID, two zero bytes and the length (PDU length + 1). For 11 03 00 6B 00 03 76 87 that gives 00 01 00 00 00 06 11 03 00 6B 00 03.

What is the difference between Modbus TCP and Modbus RTU over TCP?

Modbus TCP uses the MBAP header and no CRC. RTU over TCP, called RTU encapsulated or serial tunnelling in some software, sends the serial RTU frame including its CRC unchanged through a TCP connection. Both often use port 502, so the device or gateway manual or a Wireshark capture is the only way to tell which one is expected.

Which unit ID should I use through a Modbus TCP gateway?

The address of the serial device behind the gateway, 1–247. The gateway copies the unit ID into the RTU frame. Some gateways map unit IDs to other addresses or answer unit 0 or 255 themselves, so check the gateway settings if the address alone does not help.

Does the converter change register values?

No. The function code and the data bytes are copied unchanged. Only the device address (if you set one), the transaction ID and the header or checksum around the PDU change.

Why does a Modbus ASCII frame end with CR LF?

Modbus ASCII marks the end of every frame with carriage return and line feed (0D 0A). The converter shows the frame without them so it can be pasted into a terminal; when sending, add CR LF or turn it on in the terminal program.

Related tools