# Tooling Tags

Each machine that uses tooling has a `Tooling` folder in its asset tags, an instance of the `Kanoa/assetTooling` UDT. It's
created when **Uses tooling** is turned on and removed when it's turned off. Its **Inputs** let a PLC drive tooling; the rest
shows what's mounted, for screens and dashboards.

## Inputs

| Tag | Type | What writing it does |
| --- | --- | --- |
| Inputs/Tooling | String | Mounts the tool with this name on the machine. The name is looked up among the tools in the machine's site, then among tools outside any site. A tool with output positions first unmounts the current one; a blank name unmounts it. A tag can't confirm warnings, so they are accepted and saved in the mount's note. |
| Inputs/Blocked Positions | String | The mounted tool ends up with exactly these position numbers blocked, for example `1, 3`, and its other positions unblocked. |
| Inputs/Cycle Count | Int8 | The machine's cycle count. The increase is added to every tool mounted on the machine, and becomes the machine's outfeed: each item the mounted tool makes gets its parts per cycle (see [Counting outfeed from cycles](./tooling-tags.md#counting-outfeed-from-cycles)). |
| Inputs/Tool Shot Counter | Int8 | A reading of the tool's own shot counter. While readings keep coming, the machine's cycle count is left out for that tool. A reading below the last one (the counter was reset) only becomes the new baseline. |

## Counting Outfeed from Cycles

When `Inputs/Cycle Count` is bound, it is the machine's outfeed. **Leave the asset's own `Inputs/Outfeed Count` (in its
assetOEE tags) unbound**, or the outfeed is counted twice. The asset's `Infeed Count` and `Waste Count` stay as they are.

Each increase in the cycle count is written as outfeed:

- The running item gets the cycles × its parts per cycle: its own positions and the ones set to no item.
- On a family tool, each other item gets the cycles × its own positions' parts, as a **co-product**. Co-products are
  production of that item, but they aren't counted in the run, its OEE or its work order. Run Review lists them under
  **Co-products**.
- With no tool mounted, the running item gets one part a cycle.

A tool's cycles count every part it makes, good or bad, so each reject on the asset's `Waste Count` (for example, from a
vision system) is also taken off the running item's outfeed. A system that knows which item it rejected can call
`system.kanoa.tooling.recordReject` with the item instead, which records a co-product's reject as that item's waste.

## Display Tags

| Tag | Meaning |
| --- | --- |
| Primary/toolingName, toolingAssetId, mountedDate | The machine's output tool and when it was mounted. |
| Primary/partsPerCycle, activePositions, totalPositions | Parts made per cycle, and its unblocked and total positions. |
| Primary/cycleRate | The tool's cycle rate on this machine. |
| Primary/lifetimeCycles, cyclesSincePm, cyclesSinceRefurb | Its life counts. |
| Primary/worstPct, toolStatus | How close it is to its nearest limit, and its status. |
| Alerts/worstLevel, message | 0 OK, 1 due, 2 over a limit, with the alert text. |
| Mounted | A dataset of every tool on the machine, inserts included. |
| Positions | A dataset of the output tool's positions. |

The display tags are refreshed whenever the tooling on the machine changes, and every hour.

## Scripting

The same actions are available as system functions in `system.kanoa.tooling`, for example `mountByName`,
`setBlockedPositions`, `recordProduction`, `recordReject`, `recordCycles` and `recordShotCounter`, along with `mount`, `unmount`, `setPositionBlocked`,
`setPositionRetired`, `getTools`, `getPositions`, `getPartsPerCycle`, `getCycleRates`, `setCycleRate` and `getCounters`.
