PortDock

Modbus RTU ↔ TCP Frame Converter

Convert Modbus RTU (address + CRC) to Modbus TCP with an MBAP header and back, plus ASCII mode (colon, LRC). Every byte color-coded and explained.

Examples

Everything is converted in your browser; the bytes you paste are not sent anywhere.

FAQ

What is the difference between an RTU and a TCP frame?

The PDU in the middle (function code and data) is identical. RTU adds a 1-byte slave address in front and a 2-byte CRC16 (low byte first) at the end. TCP has no CRC and puts a 7-byte MBAP header in front: transaction ID (2), protocol ID (2, always 0), length (2) and unit ID (1). The length counts the bytes from the unit ID to the end.

Which Unit ID do I use through a gateway?

A TCP-to-RTU gateway (serial device server) uses the Unit ID it receives as the slave address on the serial side, so enter the address of the device behind it (1 to 247). Address 0 is a broadcast on a serial line, so depending on the gateway it is forwarded to every device (no reply) or taken as the gateway itself. 255 (FF) is the value recommended for a TCP device addressed directly; a gateway usually does not forward it to the serial line, or answers it itself. Check the gateway manual for the exact behaviour.

How is the Transaction ID chosen?

The sender of the request picks it and the device returns the same number in its response; it is usually increased by one per request. RTU has no such field, so it is dropped when converting TCP to RTU, and the value in the box above is used when converting RTU to TCP.

What is ASCII mode?

The other transmission mode of Modbus over Serial Line. The address, PDU and LRC are sent as two upper-case HEX characters per byte, with «:» (3A) in front and CR LF (0D 0A) at the end. The LRC is the 8-bit two's complement of the sum of the bytes from the address to the end of the PDU. It carries the same PDU as RTU, so the two convert directly.

It says the CRC or LRC is wrong

The last bytes are taken as the CRC (or LRC) and dropped, the rest is converted, and the correct value is shown. If you pasted only the address and PDU without a CRC, keep the format on RTU and append the correct CRC, or get it from the CRC & Checksum Calculator.

References

  • Modbus Messaging on TCP/IP Implementation Guide V1.0b — MBAP header (transaction, protocol, length, unit ID), unit ID at gateways
  • Modbus over Serial Line Specification and Implementation Guide V1.02 — RTU and ASCII framing, addresses (0 broadcast, 1–247), CRC and LRC
  • Modbus Application Protocol Specification V1.1b3 — PDU (function code and data), exception responses

For the MBAP header and connection problems see Modbus TCP connections and the MBAP header; for the RTU bytes see Reading Modbus RTU frames.

To decode values and 40001 addresses in detail use the Modbus Frame Decoder; to practise with questions try the Modbus Practice Quiz.