# Connect a device to an eaxTag

> Connect a device to an eaxTag, such as a measured value a template brings, by handing it over to a driver mapping so the device becomes its source, and give it back with Return to local tag - the Studio steps, the 409 OWNED_BY_LOCAL_TAG answer and its plan, what blocks a handover, how writability is carried and never widened, the handed_over record, the two routes, the audit records, high availability and the known limits.

Product: eaxScada · Type: How-to guide · Editions: Starter, Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/how-to/connect-a-device-to-an-eaxtag/
Verified against commit 7f40b62.

## Goal

A plant template you apply brings its measured values as eaxTags, for example `Line1/Tank1/Level`. They show no value, "waiting for initial data", until something writes them. Your device now measures that value: you want a driver mapping to produce the same path, so that the screens, alarms and trends built on it keep working, without renaming anything.

A path has one producer at every moment. A mapping on a path that an eaxTag produces is refused, and nothing ever takes the path over by itself. **Hand over to driver** is the explicit action that moves the path from the eaxTag to the mapping, in one step. **Return to local tag** moves it back.

## Before you start

- The Studio, on site (not through remote access), signed in with the engineer role or above.
- A driver channel and device that reach the device (see the connection how-tos, for example [Connect to an S7 PLC](/docs/eaxscada/how-to/connect-to-an-s7-plc/)).
- No enabled eaxTags script writes the path. Disable the script, or remove its write, first.
- On a high-availability pair, the Studio of the HA primary.

## 1. Map the device value on the eaxTag's path

1. Open **Drivers**, select the channel, then **Tag Mappings → + Map New Tag**.
2. Fill in the address and type as usual, and give the mapping the eaxTag's UNS path.
3. Click **Save**.

The server refuses the mapping, and the dialog says that an eaxTag produces the path, so a mapping cannot write it. Nothing has changed.

- For a template's measured value (marked `placeholder`), the dialog says it is waiting for a device and offers **Hand over to driver**.
- For any other eaxTag, it offers the same button with a warning: hand it over only if the device is now its source.
- If something blocks the handover, the dialog lists why and offers no button. Fix each point (see [What blocks a handover](#what-blocks-a-handover)) and save the mapping again.

## 2. Hand over to driver

1. Click **Hand over to driver** (a deliberate click; **Close** leaves everything as it was).
2. The second dialog, **Hand over to the driver?**, lists what moves with the path: the unit, the engineering range, the description, the write range, the e-signature for external writers, and where operator writes go (none, or to the device). It also says that the value is Bad, waiting for initial data, until the driver's first good read.
3. Click **Hand over**.

The toast says "*path* is now read from the driver." The mapping appears in **Tag Mappings** with a **Return** action.

What the server does, in one step:

1. It checks the plan again and refuses, with nothing changed, if anything blocks it.
2. It writes the audit records first: `EAXTAG_HANDED_OVER` in the security trail and `HANDOVER_TAG` in the driver audit trail. If they cannot be written, nothing changes (`503 AUDIT_NOT_WRITTEN`).
3. It removes the eaxTag definition while eaxTags still own the path. The definition stays in the eaxTags store's history, and whole in the mapping's new `handed_over` record.
4. It moves the path to the channel in one step: never released and then claimed, never two writers. Any failure after the definition was removed, including an HA commit the cluster refuses, puts the definition back and gives it the path back.
5. It sets the tag Bad, "waiting for initial data", with the mapping's unit and the former description, until the driver's first good read. An operator's or a script's last value is not shown as the device's.

From then on eaxTags cannot write the path. An operator write to the former eaxTag is refused (it is no eaxTag any more), and a script's write is refused because the script does not own the path. Alarms on the path keep the same path, and hold while the tag waits for its first read.

### What moves with the path

| eaxTag | Mapping after the handover |
|---|---|
| `unit` | `eng_unit`, when the mapping has none. A different unit blocks. |
| `min`, `max` (when `min` < `max`) | `eng_min`, `eng_max`, when the mapping has none. A different range blocks. |
| Write range | The mapping's write range, when it has none. A different one blocks. |
| `esign_external` | Set on the mapping when the eaxTag had it; never cleared. |
| `description` | The tag's description, kept in `handed_over.description`. |
| `writable` | `access`: see below. |

### Writability is carried, never widened

| eaxTag | Access the mapping sends | Result |
|---|---|---|
| Not writable (a measured value, as in every template) | none, or `RO` | An `RO` mapping (Read only). An operator, API or command write to the path is refused. |
| Not writable | `RW` or `WO` | Refused: `writable_differs`. |
| Writable (a setpoint or mode) | none, or `RW` | An `RW` mapping: operator writes go to the device. |
| Writable | `RO` | Refused: `read_only` (operator writes would be lost). |

To let operators write such a tag later, widen the mapping's access with an ordinary mapping edit, which is audited as any other. The **Map New Tag** dialog sends no access for connections that have no access field, so the handover carries the eaxTag's.

## What blocks a handover

Each blocker has a code (the Studio's text) and an English `detail`.

| Code | Why | Fix |
|---|---|---|
| `script_writes` | An enabled eaxTags script writes the path (listed in `scripts`). The cross-reference's script analysis decides: a computed path that matches counts, and a script that does not parse counts as writing everything. | Disable the script or remove its write. |
| `text_mapping` | The mapping is a String mapping; an eaxTag is numeric. | Map a numeric type. |
| `unit_differs` | The mapping has another unit. | Make them the same, or leave the mapping's unit empty. |
| `range_differs` | The mapping has another engineering range. | Make them the same, or leave the mapping's range empty. |
| `read_only` | Operators write this eaxTag and the mapping is read only. | Map it with write access, or make the eaxTag not writable first. |
| `writable_differs` | Operators cannot write this eaxTag; the mapping would let them write to the device. | Map it Read only, or make the eaxTag writable first. |
| `write_range_differs` | The mapping has another write range. | Make them the same, or leave the mapping's write range empty. |

## 3. Give the path back

1. In **Drivers → Tag Mappings**, click **Return** on the handed-over mapping's row (its accessible name and tooltip give the full name of the action). The action is there only for a mapping with a `handed_over` record.
2. A confirmation asks first. Confirm it.

A toast confirms that the path is an eaxTag again. The server writes `EAXTAG_RETURNED` and `RETURN_TAG` first, then the mapping stops producing the path (it keeps it meanwhile), the definition from the handover record is stored again and takes the path in one step, and the mapping is removed. The value restarts as a new eaxTag's: Bad, waiting for initial data, for a tag with `no_initial`, else its initial value.

## The answers of the API

### The refusal and its plan

`POST /api/dev/drivers/tag` on a path an eaxTag produces answers `409` with the code `OWNED_BY_LOCAL_TAG`. Nothing is saved:

```json
{
  "status": "error",
  "code": "OWNED_BY_LOCAL_TAG",
  "error": "...",
  "uns_path": "Line1/Tank1/Level",
  "local_tag": { "path": "Line1/Tank1/Level", "unit": "%", "initial": 0, "no_initial": true, "min": 0, "max": 100, "placeholder": true },
  "handover": {
    "path": "Line1/Tank1/Level", "placeholder": true, "no_initial": true,
    "unit": "%", "description": "", "eng_min": 0, "eng_max": 100,
    "esign_external": false, "writable": false, "access": "RO"
  }
}
```

`local_tag` is the eaxTag definition. `handover` is the plan: what the mapping would carry (`unit`, `eng_min`, `eng_max`, `write_range`, `esign_external`, `access`), the eaxTag's `description`, the template marker, `no_initial` and `writable`, and `blockers` (each with `code`, `detail`, and the conflicting values where they apply). Before this version the refusal was `500` "tag is owned by another producer".

### The routes

Both need the engineer role or above, run only on the HA primary, and are never allowed through remote access (both are "never" in the remote route table). Route list: [HTTP API routes, `/api/dev`](/docs/eaxscada/reference/generated/http-api/#apidev).

| Request | Answer |
|---|---|
| `POST /api/dev/drivers/tag/handover` with a new mapping (the body of `POST /api/dev/drivers/tag`) | `{"status": "ok", "tag_mapping", "handover"}`, with the mapping's revision. `404` when the path is no eaxTag. `409 HANDOVER_REFUSED` with the plan when something blocks it, with nothing changed and no handover record. `503 AUDIT_NOT_WRITTEN` when the records cannot be written. |
| `POST /api/dev/drivers/tag/return?id=<mapping>` | `{"status": "ok", "returned": "<path>", "local_tag"}`. `400` without `id`, `404` for no such mapping, `409` for a mapping that was not handed over or holds no definition. An `If-Match` with the mapping's `_rev` is checked (`409` `stale` when it changed). `503 AUDIT_NOT_WRITTEN` when the records cannot be written. |

### The `handed_over` record

A handed-over mapping carries `handed_over` on `GET /api/dev/drivers`, in `config.json` and in the replicated driver configuration ([Driver channels, devices and tags](/docs/eaxscada/reference/generated/config/drivers/#handover)):

| Member | Meaning |
|---|---|
| `from` | The producer that held the path: `eaxtags`. |
| `at` | When, in Unix milliseconds. |
| `by` | Who handed it over. |
| `description` | The eaxTag's description, the tag's description from then on. |
| `local_tag` | The eaxTag definition as it was, for the return. |

Only the server sets it: a save that sends it is ignored, and a save that keeps the path keeps the stored record. A mapping moved to another path loses it.

## Audit records

| Record | Trail | When |
|---|---|---|
| `EAXTAG_HANDED_OVER` | Security trail | A handover: path, channel, mapping, address, unit, `esign_external`, writable, write range, and the definition's sha256 before (none after). |
| `HANDOVER_TAG` | Driver audit trail | The same handover, the mapping saved. |
| `EAXTAG_RETURNED` | Security trail | A return: path, channel, mapping, and the definition's sha256 after. |
| `RETURN_TAG` | Driver audit trail | The same return, the mapping removed. |

Each record is written before anything changes. On-site changes of drivers and eaxTags carry no e-signature in this version.

## High availability

Both actions run on the HA primary only; a standby refuses them before anything is touched. The primary deletes the eaxTag definition (JetStream KV, acknowledged by the cluster) before it commits the driver configuration. A follower copes with either arrival order: a replicated mapping with a handover record takes its path from eaxTags if they still hold it there, and a path that a replicated configuration releases is claimed again by that node's eaxTag when its definition arrived first. A replicated mapping without the record never takes an eaxTag's path.

## Known limits

- **Deleting a handed-over mapping deletes its record.** The definition then stays only in the eaxTags store's history (`GET /api/dev/eaxtags/history?kind=tag&key=<path>`). Use **Return** instead of **Delete** when you want the eaxTag back.
- **No historian annotation.** There is no historian annotation API yet, so the handover writes no annotation into the trends. The audit trails record when the source changed.
- **Not through remote access.** The change spans two stores that no live review covers as one change, so both routes are refused there.

## Verify

1. In **Drivers → Tag Mappings**, the mapping shows the path, with **Return** on its row.
2. The tag's quality is "Bad (waiting for initial data)" until the driver's first good read, then Good with the device's value.
3. The eaxTags list no longer has the path.
4. The audit trail has `EAXTAG_HANDED_OVER`, and the driver audit trail `HANDOVER_TAG`.

## Related

- [eaxTags reference](/docs/eaxscada/reference/eaxtags-local-tags/) (the template marker and `no_initial`)
- [Tags with no initial value](/docs/eaxscada/explanation/alarms/#local-tags-with-no-initial-value)
- [Limit tag writes](/docs/eaxscada/how-to/limit-tag-writes/)
- [Allow remote access](/docs/eaxscada/how-to/allow-remote-access/)
