# Modbus TCP and Modbus RTU

> Connect PLCs, drives, energy meters and I/O modules that speak Modbus, and make their values available to OPC UA clients, SCADA screens, history and AI assistants.

Modbus is the most widespread fieldbus protocol in industry: PLCs, frequency drives, power meters, temperature controllers and remote I/O almost always offer it. PLCGateway includes a Modbus master for Modbus TCP, Modbus RTU tunnelled over TCP (serial gateways) and Modbus RTU on a serial port.

Neighbouring registers are combined into one request so that a whole device is read with a few telegrams, 32 and 64-bit values are assembled in the word order of the device, and every value carries a quality code. The values can then be published through the built-in OPC UA server, sent over MQTT, logged, alarmed and shown on screens.

- **Driver id:** `modbus_tcp`, `modbus_rtu_tcp`, `modbus_rtu`
- **Connection:** TCP 502 · RTU over TCP · RS-485 / RS-232
- **Address browsing:** addresses are typed or imported
- **Writing:** yes
- **Included in:** PLCGateway Connect, PLCGateway SCADA, PLCGateway Embedded

## What PLCGateway reads and writes

- Holding registers (FC3) and input registers (FC4)
- Coils (FC1) and discrete inputs (FC2)
- Single bits of a register as BOOL
- INT16 to INT64, FLOAT32 / FLOAT64 and strings with selectable word order (ABCD, CDAB, BADC, DCBA)
- Writing with FC5, FC6 and FC16, register bits with read-modify-write
- Several slaves behind one gateway through the unit id

## Address examples

| Address | Meaning |
|---|---|
| `HR100 · %MW100` | Holding register 100 (0-based) |
| `40101` | Classic 1-based notation for holding register 100 |
| `IR5 · 30006` | Input register |
| `C12 · 00013` | Coil |
| `DI7 · 10008` | Discrete input |
| `HR20.7` | Bit 7 of holding register 20 |

## Controllers and devices

- [Schneider Electric Modicon](https://plcgateway.com/controllers/schneider-electric.md)
- [CODESYS-based controllers](https://plcgateway.com/controllers/codesys-plcs.md)
- [Building automation and energy meters](https://plcgateway.com/controllers/building-automation.md)

## Connect in a few steps

1. Add a device, choose Modbus TCP, RTU over TCP or RTU serial and enter the IP address or the serial port with baud rate and parity.
2. Set the unit id and, for 32-bit values, the word order of the device.
3. Create the tags with their addresses and data types, or import a register list from CSV; test the connection to see the first values.
4. Use the values on screens, in history and alarms, or share them through OPC UA and MQTT.

## Questions and answers

### Does PLCGateway support Modbus RTU over RS-485?

Yes. The modbus_rtu driver uses a serial port (RS-485 or RS-232) directly, and modbus_rtu_tcp sends RTU frames through a serial-to-Ethernet gateway.

### My float values look wrong. What should I change?

Most devices store a 32-bit value in two registers but differ in their order. Choose the word order ABCD, CDAB, BADC or DCBA on the device or on a single tag until the value matches the device display.

### Can PLCGateway also act as a Modbus server?

Yes. Besides the Modbus driver, PLCGateway has a Modbus TCP server that offers all tags as coils and registers, so another PLC or a SCADA system can read the collected data over Modbus.

## Related protocols

- [BACnet/IP](https://plcgateway.com/protocols/bacnet.md)
- [Siemens S7](https://plcgateway.com/protocols/siemens-s7.md)
- [OPC UA client](https://plcgateway.com/protocols/opc-ua.md)
- [DNP3 (IEEE 1815)](https://plcgateway.com/protocols/dnp3.md)
- [All protocols](https://plcgateway.com/protocols.md)

_Product and model names are trademarks of their owners. They are named only to show which equipment the drivers communicate with; PLCGateway is not affiliated with these companies._

---
Source: https://plcgateway.com/protocols/modbus
