eaxTags script reference
An eaxTags script computes the values of local tags: a simulation, a derived value, a state machine. It is ECMAScript (plain JavaScript, no modules, no page or network access), edited in the Scripts (n) tab of Drivers → Local tags (eaxTags) with the Studio’s code editor. The same engine runs the script on eaxScada and on an eaxPLC runtime, so a script behaves the same wherever it runs.
// state kept between ticksvar level = 40;
function tick() { var running = tags.get("Line1/Pump1/Running") == 1; level = sim.clamp(level + (running ? 4 : -3) * dt, 0, 100); tags.set("Line1/Tank1/Level", level);}Script definition
Section titled “Script definition”| Member | Studio field | Meaning |
|---|---|---|
id |
id | Lowercase letters, digits, _ and -, at most 64 characters, starting with a letter or digit. Cannot be changed after the first save. |
name, description |
Name, What it does | Free text. |
enabled |
on | Runs when ticked. A disabled script is stored and not run. |
period_ms |
every … ms | How often tick() is called. At least 100; 0 or missing means 1000. |
node |
runs on | Empty: eaxScada (the HA primary). A PLC id: that eaxPLC runtime, next to its PLC. |
source |
the editor | The script. Must not be empty and must define tick(). |
updated_at, updated_by, ai_authored |
Set by the server. ai_authored marks a script written or last changed by an AI client; a person’s save that changes the source clears it. |
Lifecycle
Section titled “Lifecycle”- Save (
POST /api/dev/eaxtags/scripts, or Save andCtrl+Sin the Studio). The server checks the definition, compiles the script, runs its top level, findstick()and calls it once as a dry run: its writes are recorded, not applied, and atags.getof a tag it wrote in that run reads the written value. Any error refuses the save and nothing is stored. The audit recordEAXTAG_SCRIPT_SAVEDis written first; when it cannot be written the save is refused with503 AUDIT_NOT_WRITTEN. - Store. The definition is kept plant-wide (
EAX_SCRIPTSin the NATS Key-Value store, with history, or the eaxTags file), so every node has it. History lists its versions; Load puts an older version in the editor, saved only with Save. - Start. An enabled script that runs on eaxScada is (re)started on the HA primary. A standby node shows it as “standby (runs on the primary)” and starts it when it becomes primary. While the runtime is stopped no script runs; they start again when it runs.
- Load. On each start the script is compiled and its top level runs once. Then its saved state is restored (see State). A script that fails to load (its top level throws, for example) does not run, and its status shows the error.
- Tick.
tick()is called everyperiod_ms. Its writes are applied when it ends, with the quality of what it read (Quality of a script’s values). A tick that throws counts as an error and the script keeps running: the next tick runs as usual. A successful tick clears the current error; the last failure and its time are kept in the status. A script that keeps failing has its tags marked Bad (When the script fails or stops). - Stop. On a save, a delete, a disable, a standby or a server stop, the script stops and its state is saved. A deleted script’s state is deleted with it. A disabled or deleted script, or one pinned to an eaxPLC, leaves the tags it wrote on eaxScada Bad, their last value kept.
Limits
Section titled “Limits”- 200 ms per tick, and 200 ms for loading the script. A tick that takes longer is stopped: “stopped after 200ms (time limit): a tick must be short”. It counts as an error; the next tick runs again.
- 64 KiB of state. Larger state is not kept (the log says “state not kept: N bytes (at most 65536)”).
- The status keeps the last 20 lines of
console.log, each cut at 300 characters.
Top-level variables (not functions) keep their values between ticks. They are saved as JSON every 10 s and when the script stops, and restored when it loads again: after a save, a restart or a failover to the other node. A variable is restored only if the script still declares it; the log says “state restored (N variables)”. Values that JSON cannot hold (functions, undefined) are not kept. The global node is never part of the state.
What a script reads and writes
Section titled “What a script reads and writes”| On eaxScada | Pinned to an eaxPLC runtime | |
|---|---|---|
tags.get(path) |
Any tag of the server: driver tags, eaxTags, System/.... A String tag reads as text. |
The PLC’s variables by name or direct address ("Motor", "%MW10"), and the eaxTags its scripts set on this PLC. |
tags.quality(path) |
The tag’s quality name. | Not available: it throws “this host has no tag qualities”. |
tags.set(path, value) |
eaxTags only. | eaxTags only, sent to eaxScada after the tick. |
tags.set(path, value, {quality, reason, from}) |
The value with a quality you set, or judged by the inputs you name (Quality of a script’s values). | quality and reason throw “this host has no tag qualities”. from is not used: the value is written. |
tags.setBad(path, reason) |
The eaxTag Bad, its last value kept. | Not available: it throws “this host has no tag qualities”. |
node |
This server’s node id. | Not defined. |
genealogy |
Read only, on servers with genealogy (Pro, Enterprise). | Not defined. |
The eaxPLC runtime runs pinned scripts only when it is started with -eaxtags-scripts (eaxPLC command line); the script’s status in the Studio then reads “running on PLC id”.
A script never commands equipment. It writes only eaxTags, never a driver tag or an eaxPLC variable. Its writes:
- are held to the tag’s write range, like an operator’s;
- are applied when the tick ends, timestamped then, with the quality of the inputs the tick read: Good from Good inputs, Uncertain or Bad otherwise, see Quality of a script’s values (on eaxScada; a pinned script’s values are Good, and eaxScada marks them Bad when the PLC stops reporting);
- give a tag with
no_initialits first value, when written from Good inputs; - are not kept as a writable tag’s operator value: after a restart a writable tag gets back the value an operator wrote last;
- do not pass the screen write policy or the server interlocks, which cover operator and API writes (Which writers are covered).
A script saved by an AI client (the AI assistant, the AI co-pilot account) never writes the plant emergency-stop signal or a tag watched by a safety alarm: such a write is refused at run time, logged in the script’s status and recorded in the audit trail as AI_SCRIPT_WRITE_REFUSED. A person’s save in the Studio that changes the source makes it a person’s script again. See MCP AI gateway, 6.3.
Globals and functions
Section titled “Globals and functions”| Name | What it is |
|---|---|
tick() |
Define it. Called every period. A script without it is refused: “define function tick() - it is called every period”. |
dt |
Seconds since the previous tick (the period in the dry run). Use it for rates: x + rate * dt. |
t |
Seconds since the script loaded (0 in the dry run). |
now |
The current time, Unix milliseconds. |
node |
This server’s node id, read only (eaxScada only). See The node global. |
tags.get(path) |
A tag’s value: a number, or a string for a String tag. A path the server does not know throws no tag "path". A path this tick already wrote returns the value written, which is applied when the tick ends. |
tags.quality(path) |
The tag’s quality name: "Good", "Bad (...)" such as "Bad (waiting for initial data)", or "Uncertain (...)". |
tags.set(path, value) |
Sets an eaxTag. true and false are 1 and 0. A text is refused, even "12": convert it with Number(). A value that is not a finite number is refused. The value takes the quality of what the tick read. |
tags.set(path, value, {quality, reason, from}) |
The same with options, all optional. quality: "Bad" or "Uncertain" (never "Good"). reason: a text, only with a quality. from: the list of tag paths the value is computed from. Any other key throws. See Mark a value yourself and Name the inputs of a write. |
tags.setBad(path, reason) |
Makes an eaxTag Bad, its last value kept, with your reason. eaxScada only. |
sim.noise(a) |
A random number between -a and a. |
sim.lag(cur, target, tau_s) |
cur moved towards target with a first-order lag of tau_s seconds (uses dt). tau_s of 0 or less returns target. |
sim.wave(period_s, amp, offset) |
offset + amp · sin(2π · t / period_s). |
sim.clamp(v, lo, hi) |
v limited to lo … hi. |
console.log(...) |
Writes a line, with its time, to the script’s status in the Studio. |
genealogy.find(type, id), genealogy.trace(key, dir, depth) |
Part and lot genealogy, read only. Arguments and results: Part and lot genealogy, Scripts. |
tags.get of a tag waiting for its first value (no_initial) returns 0, and of a Bad tag its last value. You do not need to check tags.quality(path) and return early: eaxScada judges each write by the quality of what the tick read.
function tick() { // High is waiting, Bad or Uncertain when the level is tags.set("Line1/Tank1/High", tags.get("Line1/Tank1/Level") > 90);}While the level waits for its first value, High is not written as false: it stays as it is. When the level goes Bad, High keeps its last value and goes Bad, with a reason that names the level. A script that returns early when an input is not Good gets the same result: the tags it did not write are marked too. See Quality of a script’s values.
Quality of a script’s values
Section titled “Quality of a script’s values”On eaxScada a script’s values take the quality of the tags they are computed from. A value computed from a Bad, waiting or frozen input is never shown, alarmed on or used by an interlock as a Good reading. This is on for every script, in every edition that has eaxTags, with no switch per script. Scripts pinned to an eaxPLC are not affected (see Tags fed by an eaxPLC that stops reporting).
The inputs of a tick
Section titled “The inputs of a tick”- An input is a tag the tick reads with
tags.getortags.quality. - The tags the script writes are not inputs: the tags it wrote before and the tags this tick wrote. An accumulator that reads its own output back never locks itself Bad.
- The tick’s quality is the worst of its inputs. Good and Overridden count as Good. Then, from better to worse: Uncertain, waiting for initial data, out of service, Bad. A tag that does not exist counts as Bad (“missing”).
- The worst is taken over the whole tick, not per write. A script that computes two values from the same inputs gets both marked. To judge a write by its own inputs, use
from.
What a write stores
Section titled “What a write stores”The writes of a tick are applied when tick() returns or throws, timestamped at that moment. A path written twice in a tick gets the last value written. Each write takes the tick’s quality:
| Worst input | What the output gets |
|---|---|
| Good | The value, Good. |
| Uncertain | The value, Uncertain, with a reason such as “script id: input path Uncertain (EU exceeded)”. |
| Bad, or a missing tag | The value is not stored. The output keeps its last value and goes Bad, reason “script id: input path Bad (…)”. |
| Out of service (a disabled channel) | The output keeps its last value and goes out of service, with the same kind of reason. Like its input, it raises no quality alarm. |
| Waiting for initial data | An output no script has written since eaxScada started stays as it is: still waiting, or at its initial value. Starting a plant raises no flood of alarms. An output written since then goes Bad. |
| Simulated (any quality) | The value is also marked simulated (SIM). The mark only adds: a simulated tag stays marked. |
- The reason is carried on the tag as
quality_reasonin the tag’s JSON, on Uncertain and Bad, for clients of the API. The next write that makes the tag Good clears it. - Only a value write makes an output Good again. An input that becomes Good again changes nothing until the script writes the output from Good inputs. Write your outputs every tick: the deadband keeps the noise out.
Outputs the tick did not write
Section titled “Outputs the tick did not write”A script’s known outputs are the paths its source writes as literal texts (tags.set("Line1/Tank1/High", ...), tags.setBad("...")) and every tag it has written, at most 2000. They are kept with the state, so a restart or a failover keeps them.
- A tick that read an input that is not Good and did not write a known output marks it with the tick’s quality, as a write would. An output whose last write named its inputs (
from) is judged by those inputs only. - Only a tag that still holds the script’s last write, or the value it had when the script started, is marked. A tag that an operator or another writer changed since is left alone.
- Once per spell. A tag that already has that quality and reason is not set again, so alarms and the historian get one change, not one per tick.
- The mark is timestamped at the tick’s time, after the value the tag holds.
When the script fails or stops
Section titled “When the script fails or stops”- A tick that throws: the writes made before the throw are applied with the tick’s quality, as above.
- A script that keeps failing: after 3 failing ticks in a row, and at least 10 s after the first of them, every known output goes Bad, reason “script id failing: error”. From then on the writes of failing ticks are dropped, until a tick succeeds.
- Disabled, deleted, or pinned to an eaxPLC: every known output goes Bad at once, reason “script id no longer runs”. A save whose new source no longer writes a literal path makes that tag Bad, reason “script id no longer writes it”.
- Not a stop: a standby node (the primary runs the script), a stopped runtime and a server stop. The script does not mark its tags then.
- The same rules apply: only a tag still holding the script’s last write, once per spell. The log has one warning per spell: “eaxTags script failing: the tags it writes are Bad, last value kept” or “eaxTags script no longer feeds tags it wrote: they are Bad, last value kept”.
Operator tags (writable) are never marked
Section titled “Operator tags (writable) are never marked”A writable tag holds an operator’s setpoint or mode: an intent, not a reading.
- eaxScada never marks it Bad or Uncertain from a script’s inputs.
- A script’s write to it from inputs that are not Good is not applied. The script’s status logs it once: “path not written: reason (an operator’s tag takes only a value computed from Good inputs)”. A write from Good inputs is applied as before.
tags.setBadon it, ortags.setwith aquality, throws: “path is an operator’s tag (writable): a script does not mark it Bad” (or Uncertain).
Name the inputs of a write: from
Section titled “Name the inputs of a write: from”tags.set(path, value, {from: [...]}) judges the write by the listed tags only, not by everything the tick read. Use it in a script that computes several unrelated values.
function copy(dst, src) { tags.set(dst, tags.get(src), {from: [src]}); // judged by src alone}- A listed tag that the tick did not read is judged as it is now.
{from: []}: the value depends on nothing the tick read, for example a pure simulation. It is stored Good, and no input marks it SIM. This is the way to take one write out of the rule.- The output keeps its
fromfor the rule on outputs the tick did not write. - A script saved by an AI client may add inputs with
from, never narrow below the tick’s worst.{from: []}in such a script still takes the tick’s quality.
Mark a value yourself
Section titled “Mark a value yourself”| Call | Result |
|---|---|
tags.setBad(path, reason) |
The tag keeps its last value and goes Bad, reason “script id: reason” (“script id: set Bad” without one). |
tags.set(path, value, {quality: "Uncertain", reason}) |
The value, stored Uncertain, reason “script id: reason”. |
tags.set(path, value, {quality: "Bad", reason}) |
As tags.setBad: the value is not stored. |
function tick() { if (tags.get("Line1/Analyser/Calibrating") == 1) { tags.setBad("Line1/Analyser/Purity", "analyser calibrating"); return; } tags.set("Line1/Analyser/Purity", tags.get("Line1/Analyser/Raw") * 0.98);}- A worse input wins.
{quality: "Uncertain"}on a value computed from a Bad input is Bad, naming the input. quality: "Good"is refused:quality "Good" is not set by a script: a value written from Good inputs is Good.- A misspelt key throws (
unknown option "qualty" (quality, reason, from)), as does areasonwithout aquality. - These errors also happen in the dry run, so a save that always hits one is refused.
What follows from a Bad or Uncertain output
Section titled “What follows from a Bad or Uncertain output”- Screens show the red ✕ or the amber ? (Show bad and stale values).
- Alarms on a Bad output are held: they neither trip nor clear, and an alarmed tag raises its “Signal unreadable” alarm (Values that cannot be read). An Uncertain output is evaluated, its quality shown.
- Interlocks that read a Bad output block their command, unless If the interlock reads a Bad value is Allow (Decide what a Bad value does). An Uncertain value is used. A simulated output keeps an interlock active unless it is ticked Allowed in commissioning (On (commissioning only): accepted and marked).
- The historian gets one point per change of quality, under every logging rule (Quality of periodic and triggered samples).
Scripts that compute several things
Section titled “Scripts that compute several things”The tick-wide rule errs towards Bad. A script that computes values from unrelated inputs marks every value when one input fails. Give each write its from.
The demo plant’s plant-derived script is an example. It copies the status of ten controllers for the screens (online, scan rate, fault), counts pump running hours and averages the mixer heater’s duty. Without from, one silent controller makes the tick’s worst input Bad: the figures of the nine other controllers, the running hours and the heater duty all go Bad with it. The demo’s copy() passes {from: [src]}, the running hours {from: [runningPath]} and the heater duty {from: [heaterPath]}. One silent controller then marks only its own three tags.
Scripts that read each other in a loop
Section titled “Scripts that read each other in a loop”When script A writes a tag that script B reads, and B writes a tag that A reads, the two latch: once one of these values goes Bad, each keeps the other Bad after the cause is gone. A longer ring latches the same way: A’s value computed from C’s, C’s from B’s, B’s from A’s. Loops of any number of scripts are reported (29 November; before, only two scripts that read each other’s values directly). The save is not refused. Each script of the loop shows an amber warning in its status that names the scripts and the paths, and the save’s answer carries it in warnings.
Two scripts:
Scripts loop_a and loop_b read each other's values: loop_a writes Plant/Loop/X, read by loop_b; loop_b writes Plant/Loop/Y, read by loop_a. A script's value takes the worst quality of what it reads, so once one of these goes Bad the two keep each other Bad after the cause is gone. Break the loop: name the tags each value is really computed from, tags.set(path, value, {from: [...]}).Three scripts or more:
3 scripts read each other's values in a loop: a writes Plant/A/X, read by b; b writes Plant/B/Y, read by c; c writes Plant/C/Z, read by a. A script's value takes the worst quality of what it reads, so once one of these goes Bad the scripts of the loop keep each other Bad after the cause is gone. Break the loop: name the tags each value is really computed from, tags.set(path, value, {from: [...]}).- One warning per loop. Every script of a loop shows the same text once, however long the loop. The scripts are named along the loop, starting from the lowest id, each with the values it writes on the loop and the scripts that read them.
- A two-script loop through two values of each is reported too. Each write names its input with
from: B’sYis computed from A’sX, A’sPfrom B’sY, B’sQfrom A’sP, and A’sXfrom B’sQ. No two values read each other, yet the four close a loop: one warning, naming both scripts and their two values each. - Loops that share a value are one loop. When a value is on two loops (B’s value is read by A and by C, and B reads both of theirs), one warning names the three scripts. Two loops that share a script but no value stay two warnings: that script shows both, one per line.
- A long loop names at most 10 scripts, then “and N more scripts”. A script past the first ten finds its own part at the end (“among them id writes …”). Each value list names at most 3 paths, then “and N more”. The text stays short in every status.
- Break the loop with
from. A write whosefromleaves the previous script’s value out links nothing. The warning goes at the next save or read of the status. - What counts: enabled scripts that run on eaxScada. A script pinned to an eaxPLC and a disabled script are left out. A write without
fromis computed from every tag the script reads, except its own outputs: a script that reads its own output is no loop.tags.setBadlinks nothing: it is a mark, not a value computed from inputs. - A computed path is compared by its pattern when it has a literal part (
Plant/L*/XmatchesPlant/L2/X). A path computed in full is not compared. - A script saved by an AI client: its
fromcannot leave out what its tick reads, so it cannot break the loop. The warning says so: a person must save that change.
In the Studio (29 November):
- A save with warnings says so. The toast is an amber “Saved with N warnings: script id. Details under its status.” instead of the green “saved and started” one, and the script’s status scrolls into view. The script is saved and runs.
- The script list marks each script with a warning: an amber accent on its row and a marker with its number of warnings. The marker selects the script and moves the focus to its warnings in the status.
- A chip “N warnings” above the list shows only the scripts with a warning; a second click shows every script again. No banner is shown. The marker, the chip and the warnings keep the focus across the list’s refresh every 2 s.
- The marker and the chip count every warning in the status, a stored script that declares its own
nodeincluded.
Where used and Hand over to driver
Section titled “Where used and Hand over to driver”The cross-reference reads a script as the runner does:
tags.setBad(path, ...)is a write of the path, liketags.set.tags.quality(path)is a read, and so is each path in a write’s{from: [...]}.- The same holds for a script that does not parse: its literal paths are found by a scan.
So Where used lists a script that only marks a tag Bad, or only checks its quality, and such a tag is not reported unused. Hand over to driver is refused (script_writes) while an enabled script writes the path, tags.setBad included: disable the script or remove the call first (What blocks a handover).
Errors and where they show
Section titled “Errors and where they show”While you type, the code editor parses the script with the server’s own parser half a second after you stop typing and underlines the error at its line (7.1 Highlighting, completion and errors). Nothing runs. A script without tick() gets a warning.
When you save, a refused save shows its message under the status and marks its line in the editor. Line numbers are the script’s own.
| Message (shortened) | Cause |
|---|---|
script id "...": lowercase letters, digits, _ and - |
The id. |
period_ms must be >= 100 |
The period. |
the script has no source |
An empty source. |
node "...": a PLC id (or empty: eaxScada) |
The runs on value. |
script <id>: ... with a line |
A syntax error, or an error in the top level. |
script <id>: define function tick() - it is called every period |
No tick(). |
script <id>: tick(): ... |
The dry-run tick threw, for example a tags.set of a path that is not an eaxTag or a tags.get of a tag that does not exist. |
script <id>: line N: node is the server's node id, read only: declare another name |
A top-level declaration of node (7.5). |
While it runs, the status panel beside the editor shows:
- the state: running (green dot in the list), standby (runs on the primary) (amber), stopped, or running on PLC id / not running on PLC id;
- runs and errors counts, and the last and longest tick in µs against the 200 ms limit;
- the current error in rose, and the editor marks its line when you select the script; after a successful tick, “last error at time: message” in grey;
- a warning in amber, such as a stored script that declares its own
node, or a loop with other scripts (Scripts that read each other in a loop); several warnings are on separate lines, one per loop; - the last
console.loglines.
Run-time errors you will meet: <path> is not an eaxTag: a script writes only eaxTags, no tag "<path>", the write range refusal of the tag, tags.set("<path>"): the text "..." is not a number; convert it explicitly with Number(), <path>: NaN is not a finite number, the errors of tags.set’s options and tags.setBad (Mark a value yourself), and the time limit. On eaxPLC: <path>: not set by a script on this PLC (an eaxTag path; PLC variables are read by name), and tags.setBad("<path>"): this host has no tag qualities (the same for tags.set with a quality).
The same data is in GET /api/dev/eaxtags (status: running, runs, errors, last_error, last_failure, last_failure_at, last_run_us, max_run_us, log, standby, node, warning).
Engineer role or above for changes; reads for any signed-in user. Every change is recorded first (EAXTAG_SCRIPT_SAVED, EAXTAG_SCRIPT_DELETED).
| Request | Answer |
|---|---|
GET /api/dev/eaxtags/scripts |
{"scripts", "status"}; ?list=1 returns the scripts alone. |
POST /api/dev/eaxtags/scripts (or PUT) |
The saved script, after the checks and the dry run, with warnings (a list of texts, one per loop) when the script is in a loop with other scripts. Body at most 256 KiB. |
DELETE /api/dev/eaxtags/scripts?id= |
{"deleted": "<id>"}; 404 when there is no such script. The tags it wrote on eaxScada keep their last values and go Bad, “script id no longer runs”. |
GET /api/dev/eaxtags/history?kind=script&key=<id> |
The stored versions, newest first. |
Scripts are also part of the eaxTags export and import; an imported script is dry-run like a save, keeps its AI mark, and a stored script that declares node is loaded with a warning instead of refused.
See also
Section titled “See also”- eaxTags local tags
- Expression language, 7. The code editor
- Script a screen (screen scripts and server expressions, which are not eaxTags scripts)
- Build your first 2D screen