Editing variables as text using IEC 61131-3 syntax

Using IEC61131-3ClosedIEC 61131-3 is the third part of the open international standard IEC 61131. The current (second) edition was published in 2003. IEC 61131-3 currently defines five programming languages for programmable control systems It deals with programming languages and defines two graphical and two textual PLC programming language standards syntax, variables are declared within structured blocks. Each blocks begins with "VAR", "VAR_INPUT", "VAR_OUTPUT" or "VAR_EXTERNAL" keyword and ending with "END_VAR" keyword (with no semicolon after). Below is the meaning of each keyword:

Keyword Meaning
VAR Memory variables. Can be global, local or retain depending on the edited group
VAR_INPUT Input parameters of a block. Available only when the edited group is a UDFBClosed"User Defined Function Block" UDFB can be used as a sub-function block in another program of the application. It is described using FBD, LD, ST or IL language. Input / output parameters of a UDFB (as well as private variables) are declared in the variable editor as local variables of the UDFB.
VAR_OUTPUT Output parameters of a block. Available only when the edited group is a UDFB.
VAR_EXTERNAL External variables. Can be global or local depending on the edited group

Basic syntax for declaring a variable:

To declare a variable, simply enter its symbol, followed by ":" and its data type. If the data type is STRING, it must be followed the maximum length between parentheses. Example:

MyVar : BOOL;
MyString : STRING(255);

To indicate that a variable has the "read only" attribute, insert the "CONSTANT " keyword at the beginning of the variable declaration:

CONSTANT VarName : DataType;

To declare an array, the data type must be preceeded by "ARRAY [ dimensions ] OF". There are at most 3 dimensions, separated by commas. Each dimension is specified as "0 .. MaxBound". Below are examples:

Array1 : ARRAY [0 .. 99] OF DINT;
Matrix : ARRAY [0 .. 9, 0 .. 9, 0 .. 9] OF REAL;

Additionally, 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. Examples:

MyBool : BOOL := TRUE;
MyString : STRING(80) := 'Hello';
MyLongReal : LREAL := lreal#1.0E300;

Additional information and description texts:

As a variable may have additional properties and comment texts in the KAS IDEClosed"Integrated development environment" An integrated development environment is a type of computer software that assists computer programmers in developing software. IDEs normally consist of a source code editor, a compiler and/or interpreter, build-automation tools, and a debugger, we use special directives entered as IECClosed"International Electrotechnical Commission" IEC is a not-for-profit, non-governmental international standards organization that prepares and publishes International Standards for all electrical, electronic and related technologies comments AFTER the declaration of the variable, to specify additional info. The following directives are available:

Directive Description
(*$tag=Text*) Variable tag (short comment)
(*$desc=Text*) Variable description
(*$profile=ProfileName*) Variable embedded profile
(*$embed=Text*) Variable embedded properties (the syntax is the one shown in the variable grid, in the "Property" column)

You can also use "//" single line comments to enter the directives:

//$tag=Text
//$desc=Text
//$profile=ProfileName
//$embed=Text