Skip to content

Data model: global variables, data types and external access

eaxPLCExplanationFreeProView as Markdown

An eaxPLC project declares its data once and uses it everywhere. Global variables live in global variable lists, user types in data types, and the tag database in the Studio shows every declared variable in one grid, with its external access, write range, unit and description.

This page explains the pieces and the rules the PLC enforces. For the exact syntax see ST language: phase 3 additions. Everything here is in every edition (eaxPLC Free, Standard and Performance); only the new cross-reference checks are in Standard and Performance.

A project holds five kinds of POU. The two new kinds for data and the new FUNCTION kind are Structured Text only.

Kind Holds Tree group
PRG a PROGRAM, in ST or ladder Programs (PRG)
FB a FUNCTION_BLOCK, in ST or ladder Function Blocks (FB)
FUN one FUNCTION, named like the POU Functions (FUN)
GVL one or more VAR_GLOBAL blocks, nothing else Global variables (GVL)
DUT one TYPE, named like the POU Data types (DUT)

A project that uses none of this behaves byte for byte as before: same linked text, same program hash, same storage. The project file format changes (to format 2) only when you add the first FUN, GVL or DUT, or change a project compile setting.

A global is declared once, in a global variable list, and every POU can use it by name. A POU looks a name up in its own declarations first, then among the globals. VAR_EXTERNAL is optional; when you write it, its type must equal the global’s, and VAR_EXTERNAL CONSTANT makes the global read-only inside that POU.

  • Names are unique. Two globals with the same name (in any list) are an error. A PROGRAM variable named like a global is an error too (Speed is a global variable (GVL_Line): rename the local or use the global), because both would share one place in the process image. Inside a FUNCTION_BLOCK or a FUNCTION, a local may hide a global, with a warning: a reusable block must not stop compiling because a project adds a global.
  • Same place as the main program’s variables. A global has the same storage key as a variable of the main program with that name. Moving a main-program variable into a list (Promote to global) keeps its storage, its live value and its UNS path, so eaxScada tags bound to it keep working.
  • Initialised before any task. The PLC initialises the globals in a set-level step that runs first in the program’s first cycle, before inputs reach any task. A task program that reads a global in cycle 1 sees its initial value.
  • Located globals. A global may have a direct address (AT %QX0.1), like a program variable.

A data type POU holds one TYPE:

Form Example Stored as
Structure TYPE ST_Recipe : STRUCT Temp_SP : REAL; Time_s : DINT := 600; END_STRUCT END_TYPE its members, each naturally aligned (at most 8 bytes)
Union TYPE U_Word : UNION AsWord : WORD; AsBytes : ARRAY[0..1] OF BYTE; END_UNION END_TYPE every member at offset 0; size of the largest
Enumeration TYPE E_State : (Idle, Run := 10, Fault) DINT; END_TYPE its base type (default INT); values count up from the previous one
Subrange TYPE T_Speed : INT(0..3000); END_TYPE its base type
Alias type TYPE T_Level : REAL; END_TYPE the type it names

A type may use one declared later: the compiler collects every type name first. A type that holds itself by value (A holds B holds A) is an error naming the cycle.

  • Enumerations compare, take part in CASE, and convert to and from an integer with E_STATE_TO_INT and INT_TO_E_STATE. Comparing two different enumerations, or assigning an integer without a conversion, is an error. A value is written E_State.Run, or Run when only one enumeration declares it.
  • Subranges. A constant out of range is a compile error. Any other store into a subrange variable is checked at run time. By default the value is clamped to the bound and counted (the live values system/RangeClamps and system/RangeClamps/<Var>, and a diagnostic event at most every 10 seconds); the PLC never stops for it. The project setting subrange_violation := 'fault' faults the task instead. See Set the project compile settings.

An alias gives a second, symbolic name to a variable, one member of a structure or block, one array element, or one bit of an integer:

PumpRun AT Motors[3].Run : BOOL;
Ready AT Status.3 : BOOL; (* bit 3 of Status *)

An alias has no storage and no initial value of its own: it reads and writes its target’s storage. It is declared in a VAR_GLOBAL block or in a PROGRAM’s VAR, has exactly its target’s type (a bit is BOOL), and its indexes are constants. An alias of an alias is allowed up to four deep. The cross-reference lists each use of the alias under its own name with the target’s storage, so the AI guard’s storage rule also covers writes made through an alias.

A FUNCTION returns one value and is called in expressions, with formal (Scale(IN := x, LO := 0.0, HI := 100.0)) or positional arguments. You set the result by assigning to the function’s name. Its locals do not persist: every call starts from their initial values. A FUNCTION cannot call itself, directly or through others, and declares no function block instances.

VAR_IN_OUT parameters (in FUNCTIONs and FUNCTION_BLOCKs) are copied in and copied out: the actual is copied into the parameter before the body runs and back after it. The actual must be a variable of exactly the parameter’s type: no expression, no CONSTANT, no bit. A parameter is at most 4096 bytes; for more, pass a global. One consequence of copying: if the body also uses the actual’s global directly by name during the call, it sees the value from before the call, and the copy back overwrites its own write. The compiler warns about that case.

Every global and program variable has an external access that the PLC enforces against everything outside the program:

Access From outside
None Invisible and unwritable: not in the registry, so not published on UNS, not browsable in OPC UA, not in /api/registry. Every write refused, never forced.
Read Published and readable. Every external write refused. Forcing allowed.
Read-write Readable and writable, within the write range. UNS and OPC UA still need the server’s writable patterns to allow the name (the patterns stay an outer limit).

You set it with an attribute in the declaration, {attribute 'access' := 'read'}, or in the tag database’s External access column. Engineers in the Studio still see every variable, whatever its access: access controls clients outside the program, not the people who program it.

Defaults. A declaration without an access attribute is read-write, so a project written before this release behaves as it did. Variables you create in the Studio (Add POU, the tag database’s Add, a CSV import) get an explicit read: read-only from outside until you allow more.

Write range. {attribute 'write_range' := '0.0..120.0'} bounds every external write of a numeric variable. A subrange type narrows it further. A value outside is refused (WRITE_OUT_OF_RANGE). An enumeration accepts only its own values from outside, by number or by name.

Members. A member of a structure, union or function block can carry its own access and write_range attributes; they apply to that member in every instance. A member’s access can only narrow the access of the variable that holds it. A member without its own write range takes the nearest enclosing one (for example a write_range on an array of values bounds every element).

Writes by path. Outside clients can write and force one elementary member or array element by its path: Recipes[2].Temp_SP, GVL_Line.Recipes[3].Temp_SP, Line2.Valves[3].Cmd over /api/write and /api/force (HTTP and NATS); Recipes/2/Temp_SP over UNS; OPC UA lists the member paths as nodes. Every check applies to the leaf: the access narrowed through each member on the way, CONSTANT, the subrange, the enumeration’s values, and the member’s own write range (else the enclosing one). Only an elementary leaf (BOOL, an integer, an enumeration, REAL, LREAL) is written; a path to a structure or an array is refused (400), and so is an index that is not a constant or is outside the bounds.

Function block instances. Of a function block instance, only its VAR_INPUTs can be written or forced from outside, by path or by symbol, on every path. Its outputs and internal variables are published read-only: a write by path answers 400 (… is not a VAR_INPUT of …: only a function block’s inputs are written or forced from outside by path), UNS WRITE_ACCESS_DENIED, OPC UA BadNotWritable, each audited. Writes by direct address keep the storage rules below.

Bits. A bit alias (Ready AT Status.3 : BOOL) of an integer that has a write range is read-only from outside: setting one bit could take the integer out of its range.

Aliases. An alias’s effective access is the narrower of its own and its target’s: an alias narrows access, never widens it. An alias’s own narrower access applies to the alias’s name only. If Oven2_SP AT Recipes[2].Temp_SP : REAL is declared with access read, writes by the name Oven2_SP are refused, while Recipes keeps its own access for writes by its name or by address.

One check in the runtime covers every path into the process image, always against the program that is running now (during an online test, the test program’s access applies from its first cycle; an untest puts the accepted program’s back at once):

Data flowOne check for every outside write
One check for every outside writeA write from outside the program, by name, member path or direct address, on any path, passes the same four checks against the program that runs: the storage it hits is not a constant, not an input a fieldbus or MQTT source drives, belongs to read-write variables, and the value is within the write range. A failed check refuses the write, nothing is written and the refusal is audited. A write that passes is queued with the program version and written into the process image at the next cycle boundary.Outside write/api/write, /api/force(HTTP, NATS), OPC UA,UNS, Modbus TCPNot a constantNot a driven inputfieldbus or MQTTAccess read-writenarrowed by membersWithin its rangeor the subrangeRefusednothing written;auditedWrite queuetagged with theprogram versionProcess imagenext cycle boundaryyesyesyesyesCONSTANT_READ_ONLYIO_INPUT_DRIVENWRITE_ACCESS_DENIEDWRITE_OUT_OF_RANGECMDapplied
The checks look at the storage the write hits, so a direct address cannot reach a protected variable.
  • Data store
  • External system
  • Check or decision
  • Command to equipment
  • Refusal
Read as text

A write from outside the program, by name, member path or direct address, on any path, passes the same four checks against the program that runs: the storage it hits is not a constant, not an input a fieldbus or MQTT source drives, belongs to read-write variables, and the value is within the write range. A failed check refuses the write, nothing is written and the refusal is audited. A write that passes is queued with the program version and written into the process image at the next cycle boundary.

Parts

  • Outside write (external system): /api/write, /api/force (HTTP, NATS), OPC UA, UNS, Modbus TCP
  • Not a constant (check or decision)
  • Not a driven input (check or decision): fieldbus or MQTT
  • Access read-write (check or decision): narrowed by members
  • Within its range (check or decision): or the subrange
  • Refused (outcome): nothing written; audited
  • Write queue (data store): tagged with the program version
  • Process image (data store): next cycle boundary

Connections

  • Outside write → Not a constant (next step)
  • Not a constant → Not a driven input (next step): yes
  • Not a driven input → Access read-write (next step): yes
  • Access read-write → Within its range (next step): yes
  • Within its range → Write queue (next step): yes
  • Not a constant → Refused (refusal): CONSTANT_READ_ONLY. Also a force onto a constant's storage.
  • Not a driven input → Refused (refusal): IO_INPUT_DRIVEN
  • Access read-write → Refused (refusal): WRITE_ACCESS_DENIED. Access none or read. A force is refused only for access none (FORCE_ACCESS_DENIED): access read may be forced.
  • Within its range → Refused (refusal): WRITE_OUT_OF_RANGE
  • Write queue → Process image (command to equipment): applied. Only while the program version the write was checked against still runs; after a deploy or an online-edit switch it is dropped (WRITE_STALE_PROGRAM).
Path Refusal
POST /api/write by name or member path (HTTP and the NATS API) 403 WRITE_ACCESS_DENIED for access none or read; 400 WRITE_OUT_OF_RANGE outside the write range; 409 CONSTANT_READ_ONLY for a constant
POST /api/write by direct address (%MW40) the same codes when the written bytes overlap the storage of any protected variable or member; the answer names it
POST /api/force 403 FORCE_ACCESS_DENIED for access none (by name or by overlap); 409 CONSTANT_READ_ONLY for a constant; access read may be forced
OPC UA a variable with access none is not in the address space; a write needs the plc.write right (BadUserAccessDenied otherwise), and is refused with BadNotWritable (access read, constant) or BadOutOfRange
UNS commands access none is not published; access read and constants answer an error
Modbus TCP server a write over protected storage, or out of the range of a subrange or enumeration member or of an element of a range-limited array, is refused with a Modbus exception and audited under the client’s address

The direct-address check matters: variables without an AT address live in the %M area, so before this release %MW<n> could reach any of them. Now a write by address is checked against the storage it hits, not only the name it gives.

Refused writes are audited (IO_WRITE / WRITE_DENIED, or TAG_WRITE / WRITE_REFUSED for UNS, OPC UA and Modbus), refused forces as FORCE_DENIED.

Forcing is an engineer’s commissioning right (plc.force), not an external client’s. So a variable with access read can be forced; access none and CONSTANTs cannot. When a deploy makes a forced location access none, the deploy releases the force (FORCE_RELEASED, deploy vN made X inaccessible from outside (access none): it is never forced). An online test that would do the same is refused with forced_symbol_changes: unforce first.

A CONSTANT (global, program or block member) is always read from outside, whatever its access attribute says, and is never forced: no outside path can change a value the logic relies on. A constant with access none stays none. See Constants, outside writes and forces.

RETAIN (and VAR RETAIN) is accepted and shown in the tag database, but nothing is written to persistent storage. A retain variable keeps its value across deploys and online edits, like every variable both versions share. A cold reset or a power cycle resets it to its initial value, like any other variable. The tag database says so: its Retain column reads not persistent. Do not rely on RETAIN to survive a restart of the PLC.

Why access is signed and descriptions are not

Section titled “Why access is signed and descriptions are not”

What the PLC enforces is part of the declaration text: access, write range, initial value, CONSTANT and the address. That text is linked into the program, hashed and signed, so changing it needs a test or a deploy like any other logic change, with its e-signature and audit. No one can widen access on a running PLC without a signed change.

What people read lives beside the program, in a documentation file per POU: description, engineering unit, display format and notes. That file is never linked and never part of the program hash. A description change is a project revision under the POU’s lock (audited PROJECT_TAGDOC_SAVE) and needs no deploy, no test and no signature. Otherwise every typo fix in a description would need an e-signed online edit.

The tag database marks the two kinds of column: initial value, external access and write range go to the POU’s draft; unit, display and description save at once. See Document variables without a deploy.