> 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/plc-interfacing-df1.md).

# PLC interfacing (DF1)

Connect an Allen-Bradley PLC over DF1, map PLC files to RTU points, and replace a Q03 RTU.

The XL4 Plus talks to Allen-Bradley PLCs (programmable logic controllers) using the DF1 protocol, full duplex only, on either RS232 port. You set it up in QTech Workbench as a DF1 master or a DF1 slave, but not both.

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

## Master or slave?

Workbench's master and slave terms don't match DF1's own terms exactly:

| In Workbench       | What the RTU does                                                                                                    |
| ------------------ | -------------------------------------------------------------------------------------------------------------------- |
| DF1 Master enabled | Full duplex, command initiator only. It polls the PLC with read and write requests at the **Poll Interval** you set. |
| DF1 Slave enabled  | Full duplex, command executor only. It answers requests from the PLC.                                                |
| Both enabled       | Not allowed                                                                                                          |

{% hint style="warning" %}

* The RTU doesn't support Allen-Bradley half-duplex DF1. Set the PLC to full duplex (peer to peer).
* While the RTU is sending, it doesn't listen. The PLC must only reply after the RTU's message has finished.
  {% endhint %}

## Set up DF1 in Workbench

Open the **DF1 Master** or **DF1 Slave** category and set:

| Setting               | What it is                                                                                                          |
| --------------------- | ------------------------------------------------------------------------------------------------------------------- |
| Enabled               | Turns on the DF1 service                                                                                            |
| Com Port              | RS232-A or RS232-B. Check the port isn't already used by another service: see the **Comms Options** category.       |
| RTU address           | The device (SRC) address of this RTU for DF1 comms (irrespective of RTU acting as a master or slave)                |
| PLC address           | The PLC's DF1 address (DST)                                                                                         |
| PLC type              | Sets which DF1 commands are used (below)                                                                            |
| PLC-5 addressing mode | PLC-5 only: logical binary or logical ASCII                                                                         |
| Com port settings     | Baud rate, parity, data bits and stop bits are defined per the RS232 protocol to match the settings made in the PLC |

### PLC types and commands

| PLC type              | Commands the RTU uses                                                             |
| --------------------- | --------------------------------------------------------------------------------- |
| SLC (also MicroLogix) | Protected logical read/write with three address fields (CMD 0F, FNC A2 and AA)    |
| PLC5                  | Word range read/write (CMD 0F, FNC 01 and 00)                                     |
| CIF                   | Unprotected read/write (CMD 01 and 08). These use the Common Interface File (N9). |

If the RTU is the slave, then it will respond appropriately based on the type of command that was sent to it by the DF1 Master. Refer to "Allen Bradley DF1 Protocol and Command Set Reference Manual, Publication 1770-6.5.16 - October 1996".

* The SLC 500 Common Interface File is data file 9. The MicroLogix 1000 Common Interface File is integer file 7.
* Unprotected operations for PLC-5 processors read from the PLC-2 compatibility file.
* Logical binary addressing encodes up to 4 address levels as bytes, for example `0x03,0x00,0x07,0x1E` (data table 0, file 7, element 30). Logical ASCII addressing uses the PLC's own form, for example `$N7:30`.

## Map PLC files to RTU points

A data mapping links a block of RTU points to a file and element in the PLC. Click **Add Mapping**, then set:

| Field          | What it is                                                                                                                                                                                                                   |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| RTU Mapping    | RDI, RDO, RAI, RAO, TDI, TDO, TAI or TAO                                                                                                                                                                                     |
| RTU Index      | The first point number                                                                                                                                                                                                       |
| PLC Mapping    | Specifies the memory mapping reference in the PLC. In PLC-5 nomenclature this is represented in the form for example `$N1:1` meaning Integer file type file number 1, element 1, or `$B3:4` (bit file type file 3 element 4) |
| File Type ID   | Integer (89 hex) or bit (85 hex)                                                                                                                                                                                             |
| File Number    | The PLC file number                                                                                                                                                                                                          |
| Element Number | The PLC element (row) number                                                                                                                                                                                                 |
| Byte count     | How much to transfer: an even number of bytes                                                                                                                                                                                |

The mapping is summarised as `{<RTU type><index>:<PLC file type><file number>:<element>} (bytes)`.

### Rules

* The RTU supports access to **INTEGER** and **BIT** type files in the PLC, but not other file types (such as timers, counters, strings, etc).
* Data moves in 16-bit words. Every read or write must be a multiple of 16 bits.
* The starting index of the digital input must lie on a word boundary (1, 17, 33 etc). Since the RTU itself has only 8 native digital inputs and in situations where there is no other I/O defined it may be useful to create an unused or unallocated space so that the first mapped digital input has an index of 17.
* The RTU's Analogue points are inherently aligned to WORD addresses so this constraint does not apply to them.
* A mapping doesn't reserve space in the RTU's data table. To hold PLC values beyond the RTU's own I/O, add a **General Purpose I/O** block. The commands and the data block are set separately: neither sets the other.

However, the mapping can include the RTU I/O if desired, for example if the PLC wants to read the state of RTU inputs.

## Replace a Q03 RTU

When replacing a Q03 (eXcel) RTU with the XL4 Plus the following considerations should be made:

1. The PLC needs to be configured to use the "Full Duplex" (peer to peer) variant of DF1, and not the "Half Duplex" variant.
2. Set the XL4 Plus as the **DF1 master**.
3. The Q03 always used source address 0. In Workbench, set the PLC (DST) address to the address the PLC uses as its own SRC address.
4. The Q03 only used unprotected read/write (commands 1 and 8) on file N9. To copy that behaviour, use the **CIF** PLC type. The SLC type would use protected reads and writes instead.
5. The RTU will ignore commands initiated from the PLC and may indicate that they are out of sequence (a Warning in the diagnostics about TNS) if the PLC does not respond with the Sequence number of the command initiated by the RTU.

## Check it's working

A trace of communications can be enabled in QTech Workbench by turning on and displaying the Diagnostics window. If the **DF1** category is selected the RTU will display diagnostics relating to the DF1 protocol. To see a trace of raw data transfer also turn on the serial comms category in the diagnostics. See [Status lights and diagnostics](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/status-lights-and-diagnostics.md).
