Skip to content

Expression language

eaxScadaReferenceStarterProEnterpriseView as Markdown

Migrated page, not yet verified against the current code. Treat values, paths and examples as indicative until this notice is removed.

Synoptics must react to plant telemetry at high refresh rates, inform operators with threshold colour bands and alarm blinking, and support calculations. This page documents eaxScada’s dynamic conditioning and expression engine: the tag reference preprocessor, the browser’s evaluation once per display frame (with the studio’s dependency index), transforms, and the server-side scripting engine.


System architectureTwo places where an expression is evaluated
Two places where an expression is evaluatedBindings, conditions and their transforms are evaluated in the browser, in the operator runtime and in the studio while Live Preview is on, from the tag values the eaxScada server sends over the WebSocket. A script typed in the Scripting workspace is sent to the server and evaluated there, once per request, by an engine that reads tags but never writes one.BROWSER: STUDIO AND OPERATOR RUNTIMEEAXSCADA SERVERClient enginebindings, conditions andtransforms, at most onceper display frameScreen shapesfill, text, rotation,visibilityScripting workspacein the studioTag enginevalues and qualityServer script enginefresh for each request,at most 16 KiB and 200 ms,reads tags, never writesa tagtag values, WebSocketproperty valuesPOST /api/dev/evala tag, when read
Screens are drawn in the browser; the server only evaluates what an engineer sends it, and never writes a tag while doing so.
  • Service or process
  • Data or telemetry
Read as text

Bindings, conditions and their transforms are evaluated in the browser, in the operator runtime and in the studio while Live Preview is on, from the tag values the eaxScada server sends over the WebSocket. A script typed in the Scripting workspace is sent to the server and evaluated there, once per request, by an engine that reads tags but never writes one.

Parts

  • Client engine (service or process, inside Browser: studio and operator runtime): bindings, conditions and transforms, at most once per display frame
  • Screen shapes (service or process, inside Browser: studio and operator runtime): fill, text, rotation, visibility
  • Scripting workspace (service or process, inside Browser: studio and operator runtime): in the studio
  • Tag engine (service or process, inside eaxScada server): values and quality
  • Server script engine (service or process, inside eaxScada server): fresh for each request, at most 16 KiB and 200 ms, reads tags, never writes a tag

Connections

  • Tag engine → Client engine (data or telemetry): tag values, WebSocket. The studio uses the values only while Live Preview is on; the operator runtime always.
  • Client engine → Screen shapes (data or telemetry): property values
  • Scripting workspace → Server script engine (data or telemetry): POST /api/dev/eval. Engineer role; the script runs with the caller's own role, and the answer is its result or its error.
  • Tag engine → Server script engine (data or telemetry): a tag, when read

Engineers migrating projects from other HMI platforms should not have to rewrite every tag reference. The client-side preprocessor (web/static/js/designer/designer_expressions.js) accepts several notations and turns each into a tag('...') call:

Syntax Input Preprocessed expression
Braced path {Plant/Line1/Tank101/Level} tag('Plant/Line1/Tank101/Level')
Direct ISA-95 UNS path Plant/Line1/Tank101/Level > 80.0 tag('Plant/Line1/Tank101/Level') > 80.0
Bracketed path [Plant/Line1/Pump1/Speed] tag('Plant/Line1/Pump1/Speed')

A tag path with a provider prefix in front of it, such as {[default]Plant/Line1/Tank101/Level}, is not converted: remove the prefix and write {Plant/Line1/Tank101/Level}.

The preprocessor works in this order:

  1. An expression that starts with return, function or ( is left as it is.
  2. Braced and bracketed paths ({A/B}, [A/B]) become tag('A/B'), outside string literals only: 'Mode [A/B]' stays text.
  3. An expression that is nothing but a path becomes tag('...').
  4. Every other bare path becomes tag('...'), outside string literals only. A path already written as tag('...') is left as it is.

A string literal is '...', "..." or `...`, with its backslash escapes; one without its closing quote runs to the end of the expression. Earlier versions converted a braced or bracketed path inside a string too, which broke the quote and the expression.

An expression is any ECMAScript expression and may combine several live tags:

// Density-compensated mass
(tag('Plant/Line1/Tank101/Level') * 0.01) * tag('Plant/Line1/Tank101/Density') * 1000
// Multi-condition interlock
tag('Plant/Line1/Safety/EStopActive') == 0 && tag('Utilities/Air/Pressure') >= 6.2
// Status string
tag('Plant/Line1/Pump1/Running') ? 'ACTIVE (' + tag('Plant/Line1/Pump1/RPM') + ' RPM)' : 'STANDBY'

3. Reactive dependency index and frame batching

Section titled “3. Reactive dependency index and frame batching”

3.1 Inverted dependency index (rebuildDependencyIndex)

Section titled “3.1 Inverted dependency index (rebuildDependencyIndex)”

In the studio, while Live Preview is on, eaxScada keeps an inverted dependency index:

  1. When Live Preview is turned on, or at the first tag update after that, rebuildDependencyIndex() reads every shape on the screen: its bindings, its enabled conditions and a button’s own interlock.
  2. It builds a map: Map<string, Set<{ node, shapeData, key, conf, isCondition }>>.
  3. When a tag update arrives over the WebSocket, finding the objects that read the tag is a constant-time lookup.
  4. With Live Preview off, a tag update is only cached; nothing is evaluated.

The operator runtime keeps its own index (runtime_player.js, buildShapeIndex): once per display frame in which a tag changed, it evaluates only the objects that read one of the tags changed since the last frame, plus every object whose reads are not plain tag paths (another object’s property, a tag path built at run time, a screen parameter, the time, the user, a page global), in screen order. The initial snapshot, the quality clock, the link state and a change of screens evaluate every object and rebuild the index. What the objects show is the same as when every object was evaluated.

A property binding reads another object’s property instead of a tag (in the screen document: targetComponentId and targetProp). The operator runtime resolves it from the screens it draws, and evaluates it on every update; earlier versions dropped the two fields on save and showed such a binding Bad in the runtime.

Redrawing on every WebSocket packet still degrades performance during bursts. Updates are therefore coalesced per display frame:

Data flowWhat a tag update does to a screen
What a tag update does to a screenA tag update arrives over the WebSocket. In the operator runtime it asks for one canvas update per display frame, which evaluates the objects that read the tags changed since the last frame, plus the objects whose reads are not plain tag paths, and redraws once. In the studio it is cached, and only with Live Preview on does the dependency index pick the objects that read the tag, which are evaluated once per display frame.OPERATOR RUNTIMESTUDIOTag updateover the WebSocketOne canvas updaterequested at most onceper display frameReaders of the tagsand objects with otherreads; conditions, thenbindings; one redrawLive Preview on?the value is cachedNothing evaluatedthe cache shows it laterDependency indextag path: the objectsthat read itDirty setone flush requestedper display frameDirty objects onlyeach once; one redrawruntimestudiooffonreaders
Both paths redraw at most once per display frame and evaluate only the objects that may read the changed tag.
  • Service or process
  • Check or decision
Read as text

A tag update arrives over the WebSocket. In the operator runtime it asks for one canvas update per display frame, which evaluates the objects that read the tags changed since the last frame, plus the objects whose reads are not plain tag paths, and redraws once. In the studio it is cached, and only with Live Preview on does the dependency index pick the objects that read the tag, which are evaluated once per display frame.

Parts

  • Tag update (service or process): over the WebSocket
  • One canvas update (service or process, inside Operator runtime): requested at most once per display frame
  • Readers of the tags (outcome, inside Operator runtime): and objects with other reads; conditions, then bindings; one redraw
  • Live Preview on? (check or decision, inside Studio): the value is cached
  • Nothing evaluated (outcome, inside Studio): the cache shows it later
  • Dependency index (service or process, inside Studio): tag path: the objects that read it
  • Dirty set (service or process, inside Studio): one flush requested per display frame
  • Dirty objects only (outcome, inside Studio): each once; one redraw

Connections

  • Start → Tag update (next step)
  • Tag update → One canvas update (next step): runtime. In the operator runtime the update only asks for a canvas update; several updates in one frame make one update.
  • One canvas update → Readers of the tags (next step). Only the objects that read one of the tags changed since the last frame are evaluated, plus every object that reads another object's property, a path built at run time, a screen parameter, the time, the user or a page global. The initial snapshot, the quality clock, the link state and a change of screens evaluate every object.
  • Tag update → Live Preview on? (next step): studio
  • Live Preview on? → Nothing evaluated (next step): off. With Live Preview off, the value is only cached; turning Live Preview on rebuilds the index and evaluates every binding.
  • Live Preview on? → Dependency index (next step): on
  • Dependency index → Dirty set (next step): readers. The objects whose bindings, enabled conditions or own interlock read the tag are added to the dirty set.
  • Dirty set → Dirty objects only (next step)
  • Bursts are queued without intermediate redraws.
  • Once per display refresh (16.67 ms at 60 Hz, 8.33 ms at 120 Hz), the studio’s Live Preview evaluates only the objects in dirtyBindingsQueue, and the operator runtime only the objects its index names for the changed tags; each then redraws once.

A binding can have one transform or a chain of transforms:

Data flowFrom a binding's source to the shape
From a binding's source to the shapeA binding reads its source: a tag, an expression, the property of another shape or a fixed value. A bad source stops there and is shown as bad. Otherwise the transforms of its list run in their order, then the binding's own map, format and script, and the value is set on the shape, unless a script transform read a bad tag.Binding sourcea tag, an expression,another shape's property,or a fixed valueSource bad?bad tag or an errorShown as badtext shows '—', coloursgo neutral, the rest keepsits state; quality markerTransforms listmap, format or script,in the list's orderThe binding's ownmap, then format,then scriptA script read a bad tag?Set on the shapethe bound propertybadgoodbadgood
A bad value is never transformed into a good-looking one: it is shown as bad.
  • Service or process
  • Check or decision
Read as text

A binding reads its source: a tag, an expression, the property of another shape or a fixed value. A bad source stops there and is shown as bad. Otherwise the transforms of its list run in their order, then the binding's own map, format and script, and the value is set on the shape, unless a script transform read a bad tag.

Parts

  • Binding source (service or process): a tag, an expression, another shape's property, or a fixed value
  • Source bad? (check or decision): bad tag or an error
  • Shown as bad (outcome): text shows '—', colours go neutral, the rest keeps its state; quality marker
  • Transforms list (service or process): map, format or script, in the list's order
  • The binding's own (service or process): map, then format, then script
  • A script read a bad tag? (check or decision)
  • Set on the shape (outcome): the bound property

Connections

  • Start → Binding source (next step)
  • Binding source → Source bad? (next step)
  • Source bad? → Shown as bad (next step): bad. A bad source is not transformed: no transform runs.
  • Source bad? → Transforms list (next step): good. A good or uncertain value goes on to the transforms.
  • Transforms list → The binding's own (next step)
  • The binding's own → A script read a bad tag? (next step)
  • A script read a bad tag? → Shown as bad (next step): bad
  • A script read a bad tag? → Set on the shape (next step): good

Translates numeric or boolean states into colours, text labels or icons. Supports discrete keys, numeric ranges and comparison operators:

{
"type": "map",
"mapping": {
"0": "#64748b",
"1": "#10b981",
"2": "#ef4444",
"default": "#334155"
}
}
  • Range keys: "0..50": "#10b981", "51..85": "#f59e0b", "86..100": "#ef4444"
  • Operator keys: "< 50": "#10b981", ">= 80": "#ef4444"

Formats a number as a string:

{
"type": "format",
"precision": 2,
"scale": 1.0,
"prefix": "P-101: ",
"units": " bar"
}

Input 14.2857 gives "P-101: 14.29 bar".

Runs client-side JavaScript, for conversions the other transforms cannot express:

{
"type": "script",
"code": "return (value * 9/5 + 32).toFixed(1) + ' °F';"
}

5. Visual conditioning modes (designer_conditioning.js)

Section titled “5. Visual conditioning modes (designer_conditioning.js)”

Conditioning rules bind tag expressions to graphical attributes:

Mode Behaviour Typical use
Colour and fill bands Compares a value against bands; steps or interpolates the colour. Reactor fluid colour from cyan to amber to red with temperature.
Alarm blinking Toggles stroke/fill between the alarm priority colour and dark slate (#334155) every 500 ms. Unacknowledged ISA-18.2 alarms.
Visibility and security Evaluates a boolean expression and the operator’s roles ($user.hasRole(...)). Hiding maintenance overrides from line operators.
Position and motion Maps a tag range [inMin, inMax] to coordinates [X1, Y1] → [X2, Y2]. Gantry crane, hoist travel, transfer carts.
Size and geometry Maps a tag to height, width or fill level. Vessel level indicators.
Rotation and spin Maps a tag to an angle (0–360°) or drives a continuous angular speed. Agitator blades, pump rotors proportional to motor Hz.
Interaction gating Disables clicks and shows an interlock warning while a condition is false. Blocking a discharge valve while the vessel is under pressure.

ANSI/ISA-18.2 recommends that unacknowledged alarms flash at 1 to 2 Hz.

eaxScada uses one shared blink timer (setupBlinkTimer):

  • A single global interval toggles blinkState = !blinkState every 500 ms.
  • Shapes with blink: true switch to #334155 when blinkState === false and back to the alert colour when it is true.
  • All blinking shapes share the same phase, so every blinking alarm across a multi-monitor control room flashes in step.

Visual bindings run in the browser. The server has an embedded ECMAScript 5.1+ engine written in pure Go (internal/scripting/scripting.go) that evaluates one expression and returns its value. It is reached through one endpoint, POST /api/dev/eval, which needs the engineer role or above. It only reads: a server expression never writes a tag, raises an alarm or changes any other state.

The request body is {"expression": "<source>"}. The expression runs with the caller’s own role: a role field in the body is ignored. The value of the last statement is returned as {"result": <value>}. A syntax error, a thrown error or a refusal is returned as {"error": "script error: ..."} with HTTP status 200.

Limit Value What happens
Expression size 16 KiB (16 384 bytes) A larger expression is refused before it is parsed.
Run time 200 ms The run is interrupted, for example a while (true) {}, and the error says it was stopped after 200 ms.
State none Every evaluation runs in a fresh engine: variables do not survive from one evaluation to the next.

These are the only globals the server adds to the standard ECMAScript ones. There is no $system object, and $tags has no methods.

Global Type Behaviour
$tags object, indexed by tag path $tags["Utilities/Air/Pressure"] reads the tag’s current value from the tag engine when the expression reads it. Only the value is read: quality and timestamp are not available. An unknown path reads as undefined, and "path" in $tags is false for it. Enumerating the object, for example with for (var p in $tags), lists every tag path. Assigning ($tags[p] = 1) or deleting (delete $tags[p]) changes only this evaluation’s view of the object: the tag itself is never written.
$user.role string The caller’s role with the highest hierarchy level, for example Lead_Engineer. It is Operator when the request has no identified user or the user has no role.
$user.hasRole(name) function, returns a boolean true when the caller’s role level is at or above the level of the role name. See the role levels below.
$plantEStopTag string The path of the plant emergency-stop signal tag: the active project’s setting safety.plant_estop_tag (Site1/Safety/PlantEmergencyStop for a project that sets none; a new project is given Plant/Safety/EmergencyStop). Read the signal as $tags[$plantEStopTag] instead of writing the path into a script, so the script follows the project setting.

hasRole and $user.role use these levels. Names are not case-sensitive, and the short names are accepted as well.

Level Role Short name
100 Administrator Admin
80 Lead_Engineer Engineer
60 Process_Supervisor Supervisor
40 Shift_Operator Operator
20 Compliance_Auditor Auditor
10 AI_CoPilot none

Any other name has level 0. A caller whose role has level 0, such as a custom role, gets false from hasRole for every name. A name that is not in the table is never held: hasRole returns false for it, whatever the caller’s role.

6.3 Example: check a setpoint against its limit

Section titled “6.3 Example: check a setpoint against its limit”
// Evaluates to true when the dosing setpoint is inside its safety limit
var maxAllowed = $tags["Plant/Line1/Dosing/MaxAcidLimit"];
var proposed = $tags["Plant/Line1/DosingSetpoint"];
if (maxAllowed === undefined || proposed === undefined) {
throw new Error("limit or setpoint tag not found");
}
proposed <= maxAllowed || $user.hasRole("Process_Supervisor");

The expression only computes the answer. Writing the setpoint is a separate, permission-checked tag write.


Every place in the Studio where you type code or an expression uses the same editor:

Where What you type Checked as
Scripting workspace a server expression (section 6) a server expression
eaxTags, script editor an eaxTags script (tick(), dt, t, now, tags.get, tags.set, sim.*, console.log, node: section 7.5; every function in eaxTags script reference) an eaxTags script
Inspector, Bind tab a binding expression (section 2.2) a binding: preprocessed as at runtime
Inspector, Cond tab visibility, colour, position, size, rotation and text expressions, and the interaction “disable when” condition a binding
Button properties the “disable when” condition a binding
Inspector, Action tab and button properties the script of a Run command action a function body
Chart widgets the option expression a function body
Display settings the startup command or script a function body
  • Highlighting: keywords, strings, numbers, comments and names in distinct colours, matching brackets marked. The editor follows the Studio’s light or dark theme.
  • Completion (as you type, or Ctrl+Space):
    • tag paths from the project’s tag list inside $tags['...'] (server expressions), tags.get('...') and tags.set('...') (eaxTags scripts), tag('...'), tags['...'] and bare paths such as Area/Tank/Level (bindings), writeTagValue('...') and system.tag.write('...') (function bodies);
    • $user, $user.role, $user.hasRole('...') with the project’s role names, and $plantEStopTag, in server expressions;
    • the eaxTags script names (node included), sim. and tags. members in scripts; value, clamp, lerp, now, ifTrue and colorScale in bindings.
  • Errors: half a second after you stop typing, the server parses the text with the same parser it runs (or, for display code, the parser it checks displays with) and the editor underlines the error at its line and column, with the message on hover. The check never runs the code: a script that writes tags or never ends is only parsed. A text over 16 KiB is not checked. An eaxTags script without tick() gets a warning.
  • Run results (Scripting workspace): an object or an array is shown as a tree you can fold, a single value with its type, and an error with a Go to line button; the error’s line is marked in the editor. The last 20 runs of the session are listed under the result: Show displays a run again, Edit again puts its expression back in the editor.

The ? in the editor’s corner lists them.

Key Action
Ctrl+Enter Run (Scripting workspace)
Ctrl+S Save (eaxTags script)
Ctrl+F Find and replace
Ctrl+Space Complete
Ctrl+Z, Ctrl+Y (or Ctrl+Shift+Z) Undo, redo
Ctrl+/ Comment or uncomment the line
Alt+Up, Alt+Down Move the line
Tab, Shift+Tab Indent, outdent (script editors); in an expression field Tab moves to the next field
Esc, then Tab Leave a script editor

The editor saves exactly the text you typed: an expression you open and close without a change is saved unchanged, character for character, line breaks included.

POST /api/dev/parse (engineer role or above, like /api/dev/eval) takes {"source": "<text>", "kind": "<kind>"}, where kind is expression (a server expression), script (an eaxTags script), body (a function body run by a display) or binding (a binding or condition expression). It answers {"diagnostics": [{"line", "column", "message", "severity"}]}: an empty list when the text parses; line and column (counted in UTF-16 code units, from 1) point into the text as sent, and severity is error or warning. It parses and never runs anything. A text over 16 KiB is refused with HTTP 413, an unknown kind with HTTP 400.

The other globals, the script lifecycle and its errors are in eaxTags script reference.

Every eaxTags script that runs on eaxScada can read the global node, a read-only string: this server’s node id, the <node> of its own System/Health/<node>/... tags. It is ha.node_id (or --node-id) when one is set, else the default node-scada-<NATS port>, with the same character replacement as the System Health tags. Every script on the server reads the same value.

A script reads its own server’s health with node instead of a fixed node name, which would read nothing on any other server:

function tick() {
var online = tags.get("System/Health/" + node + "/PLC/line1/Online");
// ...
}
  • Read only. An assignment (node = ..., globalThis.node = ...) is ignored and leaves the value unchanged; in a "use strict" script it throws. delete node has no effect.
  • Not a name you can declare. A script that declares node at top level (var, let, const, function, class, or destructuring) or redefines it with Object.defineProperty is refused when you save it, with its line: “line N: node is the server’s node id, read only: declare another name”. The same applies to a script the AI assistant proposes. A local node inside a function is allowed.
  • Scripts stored before. A stored script that already declares its own top-level node keeps loading and running unchanged, with its own node and without the server’s global: at start, on a failover, and for replicated and imported definitions. The server logs one WARN for it, and the script’s status carries the same text in its warning field (GET /api/dev/eaxtags), shown in amber under the script’s status in the Studio. Rename the variable to get the global; until then, saving the script is refused.
  • Scripts pinned to an eaxPLC runtime have no node. The PLC’s script engine has no such global, and the save check follows it.
  • node is not kept in the script’s saved state, and error line numbers are unchanged.

When an instrument fails or a fieldbus cable is disconnected:

  1. The driver sets the tag quality to QualityBad (0x0000) or QualityUncertain (0x0040).
  2. The expression engine detects non-good quality (quality !== 192).
  3. The shape shows a bad quality indicator (a dashed amber/magenta border with a question mark), so operators know the value is stale.
  4. If an expression throws (a syntax error or a runtime error such as division by zero), the error is caught and logged, and the shape displays NaN instead of breaking the canvas.