> 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/modbus-slave.md).

# Set up as a Modbus slave

Let a PLC or SCADA system read and write the XL4 Plus over Modbus TCP or serial.

As a Modbus slave (server), the XL4 Plus answers a Modbus master (client), such as a PLC. The master reads and writes the RTU's **telemetry** points. Use the data offset to keep the master's data separate from DATRAN's.

{% hint style="info" %}
**Applies to:** XL4 Plus firmware v7.x with Modbus licensed (fully featured units). This example uses Modbus TCP over Ethernet. The Modbus Master simulator that is used is QModMaster 0.4.5.
{% endhint %}

## 1. Set up the Ethernet port

Set up the Ethernet port. Usually, it is preferable to use static IP addressing. See [Configure](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/configure.md).

## 2. Turn on the Modbus slave

1. Open **Modbus Slave**. Check the **Enabled** box.
2. Set the **Modbus Slave ID** (“1” in this example).
3. The default TCP port is usually **502**, do not alter unless you have a good reason to.
4. The **data offset** settings map the slave IO into the RTU IO space. Generally you would at least offset from the native RTU physical IO (8 DI, 8 DO, 6AI, 2AO).

## 3. Allocate space for the master's data

Right-click **General Purpose I/O** and select **Add IO Block**. Enter how many points of each type the master can use.

## What the master can read and write

| Master command                                         | Direction     | XL4 Plus point            |
| ------------------------------------------------------ | ------------- | ------------------------- |
| Write Multiple Registers (0x10), Write Register (0x06) | Master to RTU | Telemetry analogue output |
| Read Holding Register (0x03)                           | RTU to master | Telemetry analogue output |
| Write Multiple Coils (0x0F)                            | Master to RTU | Telemetry digital output  |
| Read Coils (0x01)                                      | RTU to master | Telemetry digital output  |
| Read Input Register (0x04)                             | RTU to master | Telemetry analogue input  |
| Read Discrete Input (0x02)                             | RTU to master | Telemetry digital input   |

If the DLP uses `telinp` and `telout`, only the telemetry values change when the master writes. The real outputs don't change unless the DLP copies them.

If the master reads past the data you allocated, the RTU returns a Modbus I/O exception.

## Keep DATRAN and the master apart

DATRAN overwrites any telemetry point within the site's point count in DATRAN. For example, if the site has 4 analogue outputs in DATRAN, DATRAN writes TAOUT3 and TAOUT4, and the master's writes to those points are overwritten. Equally, a master write to 40001 and 40002 overwrites DATRAN's values.

To let DATRAN read values the master writes to holding registers, copy them in the DLP from the telemetry analogue outputs to telemetry analogue inputs that DATRAN reads, in a General Purpose I/O block or notional inputs. For example:

* Here we are leaving TAOUT3 and 4 as data from Datran to the Modbus Master holding registers (40001 – 40002).
* TAOUT5–TAOUT10 (40003–40008) carry data from the master. The DLP copies them to TAIN15–TAIN20, which DATRAN reads.

For how the data offset works with more than one master, see [Modbus](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/modbus.md).

## Check it's working

In Workbench diagnostics, turn on **DBG\_MB\_SLAVE** to see the master's commands and any exceptions.
