# Modbus to OPC UA

> PLCGateway reads Modbus TCP and RTU devices and serves their registers and coils from an OPC UA server as named, typed variables that MES, SCADA and historians can browse.

Modbus has no names, no data types and no security: a register number means something different in every device. OPC UA has all three. PLCGateway holds the register map once – address, data type, word order, scaling, unit and description – and presents the result as an OPC UA address space.

The IT side then works with variables such as meter1.ActivePower instead of register 40101, over an encrypted and authenticated connection if required, while the devices keep speaking plain Modbus in the machine network.

- **Source:** [Modbus TCP / RTU](https://plcgateway.com/protocols/modbus.md) (`modbus_tcp`, `modbus_rtu_tcp`, `modbus_rtu`)
- **Connection:** TCP 502 · RTU over TCP · RS-485 / RS-232
- **Target:** [OPC UA](https://plcgateway.com/connect.md)
- **Writing:** yes
- **Included in:** PLCGateway Connect, PLCGateway SCADA, PLCGateway Embedded

## Set it up in five 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. Open Gateway → OPC UA and choose the security modes and whether clients sign in anonymously or with user name and password.
5. Connect your OPC UA client (UaExpert, an MES, a SCADA) to opc.tcp://<gateway>:4840 and browse Objects → PLCGateway.

## Example: node ids in the OPC UA server

A device with the id meter1 and these tags appears in the address space as shown below. Names and values are examples.

| Tag | Address | Example value |
|---|---|---|
| `ActivePower` | `HR100` | 42.75 kW |
| `Energy` | `HR200` | 128450.5 kWh |
| `PumpRunning` | `C12` | true |

**OPC UA node ids**

```
opc.tcp://<gateway>:4840
Objects / PLCGateway / meter1
ns=1;s=meter1.ActivePower  = 42.75
ns=1;s=meter1.Energy       = 128450.5
ns=1;s=meter1.PumpRunning  = true
```

Every tag is a variable under Objects / PLCGateway / device in namespace 1; clients read it, write it and subscribe to its changes.

## The OPC UA server in PLCGateway

Every tag becomes a variable in PLCGateway's built-in OPC UA server, so MES, ERP, SCADA and historians use one standard endpoint instead of each controller's own protocol. Clients browse the devices and tags, read, write and subscribe to value changes.

The server offers the security modes None, Sign and SignAndEncrypt with automatically generated certificates; clients sign in anonymously or with user name and password.

- One endpoint (opc.tcp, port 4840) for all devices and protocols
- A folder per device and a variable per tag, with description and unit
- Subscriptions with data-change notifications; writing only where the tag allows it
- Client certificates are approved in the web interface

![OPC UA server settings: endpoint, security policies and users](https://plcgateway.com/assets/img/shots/opcua-1600.webp)

## Controllers and devices

- [Modbus TCP / RTU](https://plcgateway.com/protocols/modbus.md)
- [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)

## Questions and answers

### Can I import a register list?

Yes. Tags are entered by hand or imported from CSV with address, data type and description, and exported the same way.

### Which Modbus variants are supported?

Modbus TCP, Modbus RTU over TCP and Modbus RTU on a serial line, each with unit id, word order and block-read settings per device.

### Does the gateway also work the other way round?

Yes. PLCGateway also has a Modbus TCP server that offers the tags of every driver as registers and coils, for systems that only speak Modbus.

## Related solutions

- [Modbus to MQTT](https://plcgateway.com/solutions/modbus-to-mqtt.md)
- [Siemens S7 to OPC UA](https://plcgateway.com/solutions/siemens-s7-to-opc-ua.md)
- [FANUC FOCAS to OPC UA](https://plcgateway.com/solutions/fanuc-focas-to-opc-ua.md)
- [Haas CNC to OPC UA](https://plcgateway.com/solutions/haas-to-opc-ua.md)
- [MTConnect to OPC UA](https://plcgateway.com/solutions/mtconnect-to-opc-ua.md)
- [Allen-Bradley EtherNet/IP to OPC UA](https://plcgateway.com/solutions/ethernet-ip-to-opc-ua.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/solutions/modbus-to-opc-ua
