> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/modbus.md).

# Modbus

How the XL4 Plus works as a Modbus master or slave, the data offset, and what changed from the XL4.

The XL4 Plus can be a Modbus master (client) and a Modbus slave (server) at the same time. It supports Modbus RTU and ASCII on the RS232 and RS485 ports, and Modbus TCP on Ethernet. You set it up in QTech Workbench.

{% hint style="info" %}
**Applies to:** XL4 Plus firmware v7.x with Modbus licensed. Fully featured units include Modbus; Legacy units don't. See [Licensing and features](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/licensing-and-features.md).
{% endhint %}

## In this section

* [Set up as a Modbus master](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/modbus/modbus-master.md): read and write a PLC, flow meter or analyser
* [Set up as a Modbus slave](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/modbus/modbus-slave.md): let a PLC or SCADA system read and write the RTU
* [Link two XL4 Plus RTUs over Modbus](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/modbus/xl4-plus-to-xl4-plus-modbus.md)
* [Floating-point numbers](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/floating-point-numbers.md): convert floating-point registers for DATRAN

## Real and telemetry points

* As a **master**, the RTU reads and writes the slave's data through its **real** points (RDI, RDO, RAI, RAO).
* As a **slave**, the RTU lets the master read and write its **telemetry** points (TDI, TDO, TAI, TAO).
* DATRAN reads and writes telemetry points too.

With no DLP, or a DLP without `telinp` and `telout`, the RTU copies real inputs to telemetry inputs and telemetry outputs to real outputs. A DLP with `telinp` and `telout` stops this, and must copy the values itself. See [Configure](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/configure.md).

## More than one master: the data offset

A site often has two masters for the RTU. For example, the RTU polls a flow meter and a pH transducer as a Modbus master, DATRAN polls the RTU, and a PLC also reads and writes the RTU as a Modbus master. The RTU then runs three comms tasks: QComms slave (for DATRAN), Modbus master (for the transducers) and Modbus slave (for the PLC).

With two masters, they can fight over the outputs. The PLC may write a coil, and DATRAN, not knowing, overwrites the telemetry output with the value it thinks should be there.

To prevent this, the Modbus slave settings have a **data offset**. It moves the Modbus I/O to a different part of the telemetry data table. Normally the offset is equal to or greater than the site's point count in DATRAN. Set an offset for each data type: digital inputs, digital outputs, analogue inputs and analogue outputs. Notional points aren't mapped to third-party protocols.

### Example

DATRAN is set to 24 digital inputs, so it uses TDI1–TDI24. The data offset is 24, so the PLC's discrete inputs 10001–10008 map to TDI25–TDI32. If the PLC reads 10009 or higher, the RTU returns a Modbus I/O exception.

That slot needs values in it, so the DLP copies them in. To let the PLC read RDI7 and RDI8 from the RTU, RDI10 from the flow meter and RDI17 from the pH meter:

```
CPDIG RDIN7, TDIN25, 2
CPDIG RDIN10, TDIN27, 1
CPDIG RDIN17, TDIN28, 1
```

In fact, a much simpler approach would have been to set the Data Offset, the DATRAN Site Point Count, and the Extra I/O slot to all have the same value. That way, the data layout in DATRAN would exactly correspond to that in the PLC, and the DLP would only need the following line:

```
CPDIG RDIN1, TDIN25, 24
```

Note that these examples only relate to Digital Input values. The DLP would also need to include commands for copying any other data types that were used.

## Changes from the XL4

The XL4 always read inputs, whether it was the master or the slave. On the XL4 Plus, a master reads the slave's inputs, and a slave's inputs are read by the master. When you replace an XL4, you may need to remap the site's I/O. See [Port an XL4 site to the XL4 Plus in DATRAN VI](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/upgrade-xl4-to-xl4-plus/port-xl4-site.md).

## Check it's working

* In Workbench diagnostics, turn on **DBG\_MB\_MASTER** (serial master), **DBG\_MB\_CLIENT** (TCP master) or **DBG\_MB\_SLAVE**.
* The ER light flashes 8 times for a serial master failure, and 10 times for a TCP client failure. See [Status lights and diagnostics](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/status-lights-and-diagnostics.md).
