Declaration of function block instances in ST
VAR (* optional_begin *) CONSTANT RETAIN NON_RETAIN PUBLIC|PROTECTED|PRIVATE|INTERNAL (* optional_end *)
| VAR_INPUT (* optional_begin *) RETAIN NON_RETAIN (* optional_end *)
| VAR_OUTPUT (* optional_begin *) RETAIN NON_RETAIN (* optional_end *)
| VAR_GLOBAL (* optional_begin *) CONSTANT RETAIN NON_RETAIN (* optional_end *)
FB_instance_1, FB_instance_2, ..., FB_instance_n : FB-type := ( input_1 := initial-value, input_2 := initial-value, ..., output_n := initial-value);
FB_instance_A, FB_instance_B, ..., FB_instance_n: ARRAY [x..y] OF FB-type := [(input_1 := initial-value, input_2 := initial-value, ...), (input_1 := initial-value, input_2 := initial-value, ...), ...];
FB_instance_C, FB_instance_D, ..., FB_instance_n: ARRAY [x1..y1, x2..y2, x3..y3] OF FB-type; (* Initial values are also possible here. *)
(* Additional pieces of data, such as partial addresses, are also possible
for
the function block instances. *)
END_VAR
VAR_IN_OUT
FB_instance_1, FB_instance_2, ..., FB_instance_n : FB-type;
FB_instance_A, FB_instance_B, ..., FB_instance_n: ARRAY [x..y] OF FB-type;
FB_instance_C, FB_instance_D, ..., FB_instance_n: ARRAY [x1..y1, x2..y2, x3..y3] OF FB-type;
END_VAR
VAR_EXTERNAL (* optional_begin *) CONSTANT (* optional_end *)
name_1, name_2, ..., name_n : FB-type;
name_5, name_6, ..., name_n : ARRAY [x..y] OF FB-type;
name_7, name_8, ..., name_n : ARRAY [x1..y1, x2..y2, x3..y3] OF FB-type;
END_VAR
Meaning |
||||||||||
declaration of one or more →function block instances, FB_instance_1 etc. must be →IEC-identifiers. Providing the optional keyword RETAIN or NON_RETAIN makes all elements of this section →retentive or non-retentive. RETAIN or NON_RETAIN is possible within the declaration of a program and the declaration of a function block . If function block instances are declared in the current section with RETAIN or NON_RETAIN , see the FAQ-article "How is the keyword "RETAIN" considered for function block instances?" for the behavior of its variables concerning RETAIN and NON_RETAIN. 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. An existing →function block (created in →ST, →FBD or →LD) is possible as type for a function block instance. When declaring a function block instance within
the section VAR...END_VAR, VAR_INPUT...END_VAR or VAR_OUTPUT...END_VAR
, it is possible to initialize its →input variables and →output variables. The initial value must be of the same data type as the declared variable is of or it must be a data type that can be converted into this data type due to the implicit conversion. Moreover, it is possible to declare function block instances with one- or multi-dimensional arrays (this is similar to "Declaration of an ARRAY data type in ST" as well) or by means of structure elements (see "Declaration of a structured data type in ST"). Restriction and note on usage
|
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.
VAR
Inst1, Inst2 : TOF;
(* declaring two instances of function block 'TOF' *)
Inst3 : Control := (IN1 := 10, IN2 := 20, T1 := T#3ms);
(* declaring one instance of function block 'Control' and initializing its inputs 'IN1', 'IN2' and 'T1' *)
TONArr2 : ARRAY [0..2] OF TON := [(PT:=T#100ms), (PT:=T#50ms)];
(* declaring 3 instances of TON block and initializing the input 'PT' of the first 2 instances *)
END_VAR
VAR_INPUT
I_TON : TON;
END_VAR
VAR_OUTPUT
O_TON : TON;
END_VAR
VAR_IN_OUT
IO_TMR : TOF;
END_VAR
PROGRAM Test
VAR
myFB : FB := (in1 := 1, c := (re := 1, im := 2));
END_VAR
END_PROGRAM
FUNCTION_BLOCK FB
VAR_INPUT
in1 : int;
c : complex;
END_VAR
END_FUNCTION_BLOCK
TYPE
complex : STRUCT
re : REAL;
im : REAL;
END_STRUCT;
END_TYPE