Declaration of internal variables in ST
VAR (* optional_begin *) CONSTANT RETAIN NON_RETAIN PUBLIC|PROTECTED|PRIVATE|INTERNAL { instanceParam } { noCodeGeneration } (* optional_end *)
name_1, name_2, ..., name_n : data-type (* optional_begin *) := initial-value {
@RELATES_TO
:= name_A;} (* optional_end *);
name_3, name_4, ..., name_n : STRING[length] (* optional_begin *) :=
'initial-value'
{
@RELATES_TO
:= name_B;} (* optional_end *);
name_5, name_6, ..., name_n : ARRAY [x..y] OF type (* optional_begin *) := [initial-value_1, initial-value_2, .., initial-value_n] {
@RELATES_TO
:= name_C;} (* optional_end *);
name_7, name_8, ..., name_n : ARRAY [x1..y1, x2..y2, x3..y3] OF data-type; (* Here, initial values and
'@RELATES_TO'
are possible as well. *)
name_9, name_10, ..., name_n : REF_TO type := REF(name_A);
(* Additional pieces of data, such as partial addresses, are also possible
for
the variables. *)
END_VAR
Meaning |
||||||||||
declaration of one or more internal →variables (also known as "local variables"), name_1 etc. must be →IEC-identifiers. Providing the optional keyword CONSTANT prevents all variables of this section from being overwritten during program execution (makes them →constants). Use the optional keywords for visibility to define the visibility of all elements of this section. These keywords are possible within the declaration of a function block only.
Deviations from IEC-standard
If you prefer that logi.CAD 3 applies different visibility to the elements without any keyword, define the logi.CAD 3 configuration variable lc3.var.access.default and the value PUBLIC
,
PRIVATE
or
INTERNAL
. Subsequently, this value will be used as the new default. In the case of the value
PROTECTED
for the c
onfiguration variable, the default
PROTECTED
is valid as this is specified by the →IEC-standard.
The optional
→pragmas
{ instanceParam }
,
{ noCodeGeneration }
and
{ @RELATES_TO := ...;} are intended for system integrators who want to
store data within the instance structure
. The variables within the section become so-called instance parameters due to these pragmas.
A →data type is possible as type for a variable. See "Supported data types" to learn which data types are supported for the declaration of variables. Use the optional →initial value [:= initial-value] to assign a value to the variable (see "Initialization of variables in ST" for details).
Local variables declared within a function block are →static variables . Local variables declared within a function or a method are →temporary variables. |
Moreover, logi.CAD 3 allows you to define a not yet fully specified location for the declaration. See "Declaration of a language element with partial address in ST" for details.
Moreover, logi.CAD 3 allows you to specify additional data for the declaration . See " Defining description, comment, JSON string or type for variables or data types " for details.
Within a section VAR...END_VAR, it is also possible to declare function block instances and to declare variables based on an interface.
VAR RETAIN
var1: BOOL;
var2, var3 : INT;
END_VAR
VAR
var4 : STRING[10];
var5: ARRAY [1..2] of BOOL;
var6 : INT;
myRef1: REF_TO INT;
var1 : INT;
END_VAR
FUNCTION_BLOCK ExampleVisibleVars
VAR PRIVATE // The variables "Var1" and "Var2" may only be used from inside this function block "ExampleVisibleVars".
Var1, Var2 : INT;
END_VAR
VAR // In case of default configuration: The variables "Var3" and "Var4" may only be used from inside this function block as well.
Var3, Var4 : BOOL;
END_VAR
VAR PUBLIC // The variable "Var5" may be used from any location where the function block can be used as well.
Var5 : TIME;
END_VAR
END_FUNCTION_BLOCK