Edit Variables as Text using IEC 61131-3 Syntax
Using IEC 61131-3 syntax, variables are declared within structured blocks.
Each block begins with VAR, VAR_INPUT, VAR_OUTPUT, or VAR_EXTERNAL keyword and ending with END_VAR keyword (with no semicolon after).
This table provides the meaning of each keyword:
Keyword |
Meaning |
---|---|
VAR |
Memory variables. Can be global, local, or retain depending on the edited group. |
VAR_EXTERNAL |
External variables. Can be global or local depending on the edited group. |
VAR_INPUT |
Input parameters of a block. Available only when the edited group is a UDFB. |
VAR_OUTPUT |
Output parameters of a block. Available only when the edited group is a UDFB. |
Basic Syntax for Declaring a Variable
To declare a variable, enter its symbol followed by a colon (:) and its data type.
Data Type: STRING
If the data type is STRING, it must be followed with the maximum length in parentheses (e.g., STRING (255)).
MyVar : BOOL;
MyString : STRING(255);
Read-only Attribute
To indicate that a variable has the read-only attribute, insert the CONSTANT keyword at the beginning of the variable declaration:
CONSTANT VarName : DataType;
Declare an Array
To declare an array, the data type must be preceded by ARRAY [ dimensions ] OF.
- There are at most three dimensions, separated by commas.
- Each dimension is specified as 0 .. MaxBound (e.g., 0 .. 9).
Array1 : ARRAY [0 .. 99] OF DINT;
Matrix : ARRAY [0 .. 9, 0 .. 9, 0 .. 9] OF REAL;
Single Variable Input Value
You can specify an initial value for single variables.
- The initial value is entered after the data type and is preceded by :=.
- The initial value must be a valid constant expression that fits the data type.
MyBool : BOOL := TRUE;
MyString : STRING(80) := 'Hello';
MyLongReal : LREAL := lreal#1.0E300;
Additional Information and Description Texts
Variables may have additional properties and comment texts in the KAS-IDE.
Special directives are entered as IEC comments AFTER the declaration of the variable, to specify additional info.
These directives are available:
Directive |
Description |
---|---|
(*$desc=Text*) |
Variable description |
(*$embed=Text*) |
Variable embedded properties (the syntax is the one shown in the variable grid, in the "Property" column) |
(*$profile=ProfileName*) |
Variable embedded profile |
(*$tag=Text*) |
Variable tag (short comment) |
Optional: Use // single line comments to enter the directives:
//$tag=Text //$desc=Text //$profile=ProfileName //$embed=Text