Attention
IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include structures and user defined function blocks.
System Uptime¶
Implicit global variables that expose the VM’s monotonic uptime counter.
IEC 61131-3 |
Not part of the standard (vendor extension) |
Support |
Supported (requires |
Variables¶
Variable |
Type |
Description |
|---|---|---|
|
|
Milliseconds since VM start (wraps at ~24.8 days) |
|
|
Milliseconds since VM start (effectively never wraps) |
Description¶
__SYSTEM_UP_TIME and __SYSTEM_UP_LTIME are implicit global variables
that the VM updates before each scan round. They contain the number of
milliseconds elapsed since the VM started, providing a monotonic uptime
counter.
Both variables are updated simultaneously and hold identical values within the same scan round. All tasks in a scan round observe the same uptime.
__SYSTEM_UP_TIME uses TIME (32-bit signed integer of milliseconds)
and wraps at approximately 24.8 days. Elapsed-duration subtraction
(current - previous) produces correct results as long as the interval
is under ~24.8 days, which covers all practical timer use cases.
__SYSTEM_UP_LTIME uses LTIME (64-bit signed integer of milliseconds)
and effectively never wraps (~292 million years).
Epoch and restart behavior:
Both variables start at 0 when the VM starts
If the VM is stopped and restarted, the timer resets to 0
Enabling¶
System uptime variables are a vendor extension and must be explicitly enabled:
ironplcc check --allow-system-uptime-global main.st
Or use the RuSTy dialect which enables all vendor extensions:
ironplcc check --dialect rusty main.st
See Enabling Dialects and Features for more information about dialects and feature flags.
Usage¶
Access the system uptime variables using VAR_EXTERNAL:
PROGRAM main
VAR_EXTERNAL
__SYSTEM_UP_TIME : TIME;
END_VAR
VAR
elapsed : TIME;
END_VAR
elapsed := __SYSTEM_UP_TIME;
END_PROGRAM
A common pattern is to wrap the variable in a function for compatibility with CODESYS-style code:
FUNCTION TIME : TIME
VAR_EXTERNAL
__SYSTEM_UP_TIME : TIME;
END_VAR
TIME := __SYSTEM_UP_TIME;
END_FUNCTION
See Also¶
Enabling Dialects and Features – enabling vendor extensions