# Set the project compile settings

> Choose whether an out-of-range store into a subrange variable is clamped or stops the task, and set how many bytes an online change may copy per switch, in the Studio's Program settings card or through the API; how the settings are signed with the program, when they take effect, and how to check what runs.

Product: eaxPLC · Type: How-to guide · Editions: Free, Pro
Source: https://eaxware.com/docs/eaxplc/how-to/set-the-project-compile-settings/
Verified against commit 9828d73.

## Goal

You decide, per project, what the PLC does with an out-of-range value in a subrange variable, and how many bytes an online change may copy in one cycle.

| Setting (Studio) | Setting (API) | Values | Default |
|---|---|---|---|
| **Out-of-range values** | `subrange_violation` | **Clamp and count** (`clamp`): store the nearest bound, count it, never stop. **Stop the task (fault)** (`fault`) | Clamp and count |
| **Values copied per switch, at most** | `migrate_cap_bytes` | 1 B to 16 MB | 1 MB |

These settings are part of the program: they are saved in the project, then signed and applied by the next **Test edits** or **Build & Deploy**, like a changed POU.

## Before you start

- You are a Lead Engineer or an Administrator. Other users see the card read-only (*Changing these settings needs a Lead Engineer or Administrator*).
- The PLC has a project store (the Studio shows the **Changes** view).

## Set them in the Studio

1. Open **File → Project Settings**. The **Program settings** card sits with the deploy settings.
2. Choose **Out-of-range values**: **Clamp and count** or **Stop the task (fault)**.
3. In **Values copied per switch, at most**, enter a whole number and pick **B**, **KB** or **MB**. The card refuses a value outside 1 B to 16 MB, or one that is not a whole number of bytes.
4. Click **Save in the project**. **Revert** puts back the saved values.
5. The card's state reads **changed: not running yet**, with the running program's values and the project's: *Not running yet: the running program uses clamp and count, 1 MB per switch; Test edits or Build & Deploy applies ...*. The **Changes** view shows a chip for the difference.
6. Click **Test edits** or **Build & Deploy**. The test's impact summary has the line **program settings: old → new** with the POUs changed. Sign as usual.

After the switch the card reads **running**.

Saving changes nothing that runs: until the test or deploy, the running program keeps the settings it was compiled with.

## Set them through the API

1. Read the project's revision and settings: `GET /api/project` answers `revision` and `settings` (the effective values).
2. Send the change, with that revision:

   ```http
   PUT /api/project/settings
   Content-Type: application/json

   {"base_revision": 57, "subrange_violation": "fault", "migrate_cap_bytes": 4194304}
   ```

   A key you leave out keeps its value. The answer is `{revision, format, settings, changed}`. `GET /api/project/compare` reports (entry `settings`) when the project's settings differ from the running program's.

3. Test or deploy, as above.

## How the settings are carried

The PLC writes the settings that differ from their defaults as the **first line** of the linked program text:

```text
{project subrange_violation := 'fault'; migrate_cap_bytes := 4194304}
```

That line is part of the program hash, so a settings change is signed and audited like any other change to what runs, and a rolled-back program runs with the settings it was signed with.

Never write `{project ...}` in a POU yourself. A POU that holds one is refused at save, import and link (*{project ...} is written by the PLC only (the project's compile settings, first line of the linked text): remove it, and set the settings with PUT /api/project/settings*), and a PLCopen document that holds one is refused.

The first non-default setting changes the project file format to 2.

## What each setting does

**Clamp and count** (default). A store outside a subrange (`INT(0..3000)`) stores the nearest bound and counts it per variable. Watch the live values `system/RangeClamps` (the total) and `system/RangeClamps/`. A growing counter raises a diagnostic event (audited `DIAGNOSTIC` / `RANGE_CLAMPED`) at most every 10 seconds, shown in the Studio's **Diagnostics & Events** panel and published on NATS `plc.<id>.events` ([Diagnostic events](/docs/eaxplc/reference/diagnostic-events/)). The PLC never stops for it.

**Stop the task (fault)**. A store outside the range faults the task before anything is stored, naming the variable: *range violation of X: a value outside lo..hi was stored (project setting subrange_violation = fault)*. Fault mode supports subrange bounds within DINT; wider bounds are a compile error.

In both modes, an **external** write outside the range is refused (`WRITE_OUT_OF_RANGE`), and a constant outside the range is a compile error.

**Values copied per switch.** The most bytes of migrated structure members one switch may copy in its first cycle. Above it, **Test edits** is blocked and a deploy is refused while the PLC runs (`409 migration_too_large`); with the PLC paused the deploy goes through. See [Online changes to data structures](/docs/eaxplc/explanation/online-changes-to-data-structures/#the-cap-and-why-the-plc-refuses-while-running). Raise it only if your fastest task can absorb the copy: roughly 0.1 ms per megabyte.

## Result

- The project has a new revision; the change is audited `PROJECT_SETTINGS` with the old and the new settings line (*compile settings changed (not running): the next test or deploy signs and applies them*).
- After the test or deploy, the running program carries the settings, and the card reads **running**.

## Troubleshooting

| Answer | Fix |
|---|---|
| `409`, *the project changed since you loaded it: reload* | Someone saved the project meanwhile. Reload (in the Studio the card reads the project again) and set the values again. |
| `400`, *subrange_violation is clamp or fault* | Use one of the two values. |
| `400`, *migrate_cap_bytes is 1..16777216 bytes (16 MB)* | Use a value in range. |
| *X: the fault mode supports subrange bounds within DINT* (compile) | Narrow the subrange, or stay with clamp and count. |
| *This PLC has no project store: the program settings live in the project.* | Deploy a project to the PLC first. |

## Related

- [Set the deploy settings](/docs/eaxplc/how-to/set-the-deploy-settings/)
- [Online changes to data structures](/docs/eaxplc/explanation/online-changes-to-data-structures/)
- [Runtime HTTP API routes](/docs/eaxplc/reference/generated/http-api-runtime/)
