Attention
IronPLC supports IEC 61131-3 Structured Text excluding I/O mapping.
Variable Scope¶
IEC 61131-3 provides keywords to control the scope and direction of variables within program organization units.
IEC 61131-3 |
Section 2.4.3 |
Support |
Partial |
Scope Keywords¶
Keyword |
Description |
Status |
|---|---|---|
|
Local variable |
Supported |
|
Input parameter (read-only in callee) |
Partial |
|
Output parameter (written by callee) |
Partial |
|
In/out parameter (passed by reference) |
Partial |
|
Global variable (accessible across POUs) |
Supported |
|
Reference to a global variable |
Supported |
Example¶
FUNCTION_BLOCK MotorControl
VAR_INPUT
start : BOOL;
stop : BOOL;
END_VAR
VAR_OUTPUT
running : BOOL;
END_VAR
VAR
internal_state : INT;
END_VAR
IF start AND NOT stop THEN
running := TRUE;
ELSIF stop THEN
running := FALSE;
END_IF;
END_FUNCTION_BLOCK
Global Variables¶
Global variables are declared in a CONFIGURATION block using
VAR_GLOBAL and accessed from programs using VAR_EXTERNAL.
The VAR_EXTERNAL declaration must match the name and type of the
global variable it references.
Top-Level Global Variables (Vendor Extension)¶
Note
This is a vendor extension not part of the IEC 61131-3 standard. See Enabling Dialects and Features for how to enable it.
Many PLC vendors allow VAR_GLOBAL blocks at the top level of a file,
outside of a CONFIGURATION block. IronPLC supports this common
extension to improve compatibility with code written for other PLC
environments.
Enable with --allow-top-level-var-global or --allow-all on the
command line.
Programs access top-level globals the same way as configuration globals —
through VAR_EXTERNAL declarations that match the name and type.
See Also¶
Variable Declarations — basic variable syntax
FUNCTION_BLOCK — function blocks
FUNCTION — functions