> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/services/plc-relay.md).

# PLC Relay

Configure PLC Relay to read and write PLC tags over Allen-Bradley, Modbus TCP, or Siemens S7.

PLC Relay is an edge container service that provides an HTTP API for reading and writing PLC tags. You configure it through the Deployment Manager UI by selecting a protocol, entering connection details, and defining tags.

{% hint style="info" %}
PLC Relay is available exclusively for Enterprise customers. [Contact the Roboflow sales team](https://roboflow.com/sales) to learn more.
{% endhint %}

## Supported Protocols

When adding or editing a PLC Relay service, you select one of three protocols. Each protocol has its own connection settings and tag format.

<table data-header-hidden data-search="false"><thead><tr><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td>Protocol</td><td><code>PLC_DRIVER</code></td><td>PLCs</td><td>Default Port</td></tr><tr><td>Allen-Bradley (EtherNet/IP)</td><td><code>allen_bradley</code></td><td>CompactLogix, ControlLogix, Micro800</td><td>44818</td></tr><tr><td>Modbus TCP</td><td><code>modbus</code></td><td>Any Modbus TCP device</td><td>502</td></tr><tr><td>Siemens S7</td><td><code>siemens_s7</code></td><td>S7-300, S7-400, S7-1200, S7-1500</td><td>102</td></tr></tbody></table>

{% hint style="warning" %}
Switching protocols clears all configured tags because tag address formats are not interchangeable between protocols. The UI will prompt for confirmation before applying the change.
{% endhint %}

## Connection Settings

### PLC Address

The address format depends on the selected protocol:

* **Allen-Bradley:** IP or hostname, optionally followed by `/slot` (e.g. `192.168.1.100/0`) or a full CIP routing path.
* **Modbus TCP:** IP or hostname, with optional `:port` (e.g. `192.168.1.100:502`). Also requires a Unit ID (0-255) and Word Order (big or little) for 32-bit values.
* **Siemens S7:** IP or hostname, with optional `:port` (e.g. `192.168.1.100:102`). Also requires Rack (0-7) and Slot (0-31).

### Simulation Mode

When enabled, PLC Relay uses an in-memory simulator instead of connecting to a real PLC. All API operations work normally, but values are stored in memory. This is useful for testing without hardware.

To simulate only some tags, leave Simulation Mode off and turn on "Simulated" for those tags. See [Simulated Tags](#simulated-tags).

## Tag Configuration

Tags define the PLC data points accessible through the API. Each tag has a name, data type, writable flag, and optional description.

### Simulated Tags

Turn on "Simulated" in the Add or Edit Tag window to serve one tag from the in-memory simulator while the other tags stay on the live PLC. Use it for tags that are not on the PLC yet, or that the relay is not allowed to access. The tag still needs a valid address for the protocol, so you can turn it back to live later without other changes. Simulated tags show a "Simulated" chip in the tag list. While the relay is connected, the "Current Status" card also shows a "simulated" chip on images that report simulated tags. In `PLC_TAGS`, a simulated tag has `"simulated": true`.

If every tag is Simulated, the relay does not report connectivity. The status card stays on "Awaiting first report from this device…" and "PLC Disconnected" does not fire.

When you save a configuration that marks at least one tag Simulated, a service pinned to some older PLC Relay images moves to the current image, because those images ignore the setting. Saving without Simulated tags does not trigger this move.

### Data Types

| Type   | Description           | Range                           |
| ------ | --------------------- | ------------------------------- |
| `BOOL` | Boolean               | `true` / `false`                |
| `INT`  | 16-bit signed integer | -32,768 to 32,767               |
| `DINT` | 32-bit signed integer | -2,147,483,648 to 2,147,483,647 |
| `REAL` | 32-bit floating point | IEEE 754                        |

### Tag Name Formats

{% tabs %}
{% tab title="Allen-Bradley" %}
Tag names must match the PLC program. API requests must use the name exactly as configured.

| Style          | Example                       |
| -------------- | ----------------------------- |
| Simple         | `TagName`                     |
| Program-scoped | `Program:MainProgram.TagName` |
| Array element  | `TagName[0]`                  |
| UDT member     | `MyUDT.Member`                |
| {% endtab %}   |                               |

{% tab title="Modbus TCP" %}
Format: `{area}:{address}` where address is a non-negative integer.

| Area         | Type(s)         | Access    | Example       |
| ------------ | --------------- | --------- | ------------- |
| `coil`       | BOOL            | Writable  | `coil:0`      |
| `discrete`   | BOOL            | Read-only | `discrete:5`  |
| `holding`    | INT, DINT, REAL | Writable  | `holding:100` |
| `input`      | INT, DINT, REAL | Read-only | `input:200`   |
| {% endtab %} |                 |           |               |

{% tab title="Siemens S7" %}
Data Block format: `DB{n}.DB[XWD]{byte}[.{bit}]`

Area format: `[MIQEA][WD]?{byte}[.{bit}]`

| Address         | Type               | Description                     |
| --------------- | ------------------ | ------------------------------- |
| `DB1.DBX0.0`    | BOOL               | Bit 0 of byte 0 in Data Block 1 |
| `DB1.DBW0`      | INT                | 16-bit word in DB1              |
| `DB1.DBD0`      | DINT or REAL       | 32-bit double-word in DB1       |
| `M0.0`          | BOOL               | Merker bit                      |
| `I0.0` / `Q0.0` | BOOL               | Process input/output bit        |
| `MW0` / `MD0`   | INT / DINT or REAL | Merker word / double-word       |

For S7-1200/1500: enable PUT/GET in TIA Portal and disable optimized block access on accessed DBs.
{% endtab %}
{% endtabs %}

## Web Dashboard

PLC Relay includes a built-in web dashboard for monitoring tag values in real time. Once the service is running, access it at `http://<device-ip>:8007`.

The dashboard also hosts interactive Swagger documentation at `/docs` and a visual config builder at `/static/config-builder.html`.

## HTTP API

The API reads and writes the configured tags over HTTP, so a pipeline can exchange PLC data without speaking Allen-Bradley EtherNet/IP, Modbus TCP, or Siemens S7 directly. Base URL is `http://<device-ip>:8007`, and the API is unauthenticated. See [Services](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/services.md#using-the-apis) for the rules shared by all on-device service APIs.

Tags come from the `PLC_TAGS` environment variable on the service and cannot be created or changed through the API. Only values can be written, and only for tags configured as writable.

### Read Before You Trust the Status Code

A request that reaches the service but fails at the PLC returns `200`. Check the body:

* `/read` returns `value: null` with `error` populated.
* `/write` returns `success: false` with `error` populated. This also happens when the value does not fit the tag's type or range.
* `/healthz` returns `plc_connected: false`.

Genuine `4xx` responses mean the request itself was wrong: `404` for a tag that is not configured, `403` for a tag configured as read-only, `400` for an empty batch or a duplicate tag name in a write batch, `422` for a body or query parameter that fails schema validation (ex: a missing field).

### Health and Validation

`/healthz` also reports the active driver, whether the relay is in `live` or `simulation` mode, and the latest tag validation summary. Validation compares each configured tag against the PLC and reports it as `ok`, `not_found`, `type_mismatch`, or `not_validated`.

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/healthz" method="get" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

Re-run validation after a PLC program change or a reconnection:

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/validate" method="post" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

### Tag Definitions

Tag names are PLC addresses in the format for the active driver, described in [Tag Name Formats](#tag-name-formats).

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/schema" method="get" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

### Read and Write Values

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/all\_tags" method="get" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/read" method="get" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/write" method="post" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

### Batch Operations

Both batch endpoints check tag names before anything runs, so an unknown tag rejects the whole request rather than returning partial results. A read-only tag in `/write_batch` also rejects the whole request.

`/write_batch` additionally rejects a batch that names the same tag twice, since keeping only the last value for a repeated name would silently drop the earlier writes. `/read_batch` accepts duplicates and returns one result per entry, in the order you sent them.

Value type or range errors and PLC failures are reported per entry in `write_batch`'s `results`, with `success_count` and `error_count` summarizing the batch. The other writes in the batch still run.

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/read\_batch" method="post" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

{% openapi src="/files/sLbfwc4nzTThFtccS6aC" path="/write\_batch" method="post" %}
[edge-plc-relay.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dad4d4f242abc03a2f2e2afe34cb8fa80227f4f1%2Fedge-plc-relay.yaml?alt=media)
{% endopenapi %}

## CLI

The `plc-cli` tool gives an interactive terminal interface for reading and writing tags. Use it for debugging and quick operations when the web dashboard is not reachable. It is a local client running inside the container against the same HTTP API the dashboard uses.

```bash
docker exec -it plc-relay plc-cli
```

<table data-search="false"><thead><tr><th>Key</th><th>Action</th></tr></thead><tbody><tr><td><code>R</code></td><td>Read all tag values</td></tr><tr><td><code>T</code></td><td>Read a single tag, selected from a list</td></tr><tr><td><code>W</code></td><td>Write a tag, selected from the writable tags</td></tr><tr><td><code>S</code></td><td>Show the tag schema</td></tr><tr><td><code>H</code></td><td>Show detailed health status</td></tr><tr><td><code>V</code></td><td>Run tag validation against the PLC</td></tr><tr><td><code>Enter</code></td><td>Refresh the display</td></tr><tr><td><code>Q</code></td><td>Quit</td></tr></tbody></table>

## Environment Variables

The Configure modal writes these for you. Edit them directly only when a deployment is managed by hand. See [Update Device Configuration](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/making-changes/update-device-configuration.md).

<table data-search="false"><thead><tr><th>Variable</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><code>PLC_DRIVER</code></td><td>none</td><td><code>allen_bradley</code>, <code>modbus</code>, or <code>siemens_s7</code></td></tr><tr><td><code>PLC_IP</code></td><td>none</td><td>PLC address in the format for the selected driver</td></tr><tr><td><code>PLC_TAGS</code></td><td>none</td><td>Tag definitions as JSON. The config builder at <code>/static/config-builder.html</code> generates this</td></tr><tr><td><code>SIMULATION_MODE</code></td><td>off</td><td>Use the in-memory simulator instead of a real PLC</td></tr><tr><td><code>LOG_LEVEL</code></td><td><code>INFO</code></td><td>Logging verbosity: <code>DEBUG</code>, <code>INFO</code>, <code>WARNING</code>, or <code>ERROR</code></td></tr></tbody></table>

Driver-specific settings:

<table data-search="false"><thead><tr><th>Driver</th><th>Variable</th><th>Range</th><th>Default</th></tr></thead><tbody><tr><td>Modbus</td><td><code>MODBUS_UNIT_ID</code></td><td>0 to 255</td><td><code>1</code></td></tr><tr><td>Modbus</td><td><code>MODBUS_WORD_ORDER</code></td><td><code>big</code> or <code>little</code></td><td><code>big</code></td></tr><tr><td>Siemens S7</td><td><code>S7_RACK</code></td><td>0 to 7</td><td><code>0</code></td></tr><tr><td>Siemens S7</td><td><code>S7_SLOT</code></td><td>0 to 31</td><td><code>1</code></td></tr></tbody></table>

## Connection Monitoring

The "PLC Relay" card on the device's Configuration tab has a "Current Status" section with the connection state, the active protocol, and the latest tag values. When the relay cannot reach the PLC, the card shows "PLC unreachable". The status and the "PLC Disconnected" alert need at least one configured tag, with `LOG_LEVEL` set to `INFO` or `DEBUG`.

To be notified when a relay loses connectivity, add a "PLC Disconnected" alert from the device's "Device Alerts" tab. See [Set up Device Alerts](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/setting-up/set-up-device-alerts.md).

## Troubleshooting

| Symptom                                | Fix                                                                                                                                                                                 |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| "Not connected to PLC" (Allen-Bradley) | Verify PLC address format (IP/Slot), check port 44818 is reachable                                                                                                                  |
| "Not connected to PLC" (Modbus)        | Check IP/port (default 502) and verify Unit ID matches the device                                                                                                                   |
| "Not connected to PLC" (Siemens S7)    | Check IP/port (default 102), rack, and slot values; for S7-1200/1500 enable PUT/GET and disable optimized block access                                                              |
| "Function refused" (Siemens S7)        | PUT/GET disabled in TIA Portal, or optimized block access enabled on the target DB                                                                                                  |
| REAL value reads as garbage (Modbus)   | Try the opposite Word Order (big vs. little)                                                                                                                                        |
| Validation shows "NOT FOUND ON PLC"    | Allen-Bradley: check that the tag exists in the PLC program. Modbus and Siemens S7: the test read failed, so check the address, and for S7 check PUT/GET and optimized block access |
