Call of function block instance in ST

Syntax
FB_instance_1(); (* calls of function block instances without parameter list *)
FB_instance_2[n](); (* This function block instance is declared by means of 'ARRAY [x..y] OF'. *)
FB_instance_2[n, n](); (* This function block instance is declared by means of 'ARRAY [x1..y1, x2..y2] OF'. *)
FB_instance_3
(input_1:=x1,input_2:=x2,...,input_n:=xn,
output_1=>y1,output_2=>y1,...,output_n=>yn); (* call of a function block instance with parameter list *)

Meaning

formal call of the →function block instance (= formal function block →call) without or with parameter list
When calling a function block instance that is declared by means of an one-dimensional array, specify the →ARRAY subscript after the name and enclose it in []. When calling a function block instance that is declared by means of a multi-dimensional arrays, specify the appropriate array subscript in [] after the name as well.

This parameter list of a formal →call may contain the following elements:

  • →assignments to →input variables (incl. to input EN)
    The expression on the right side of the assignment operator ":=" in the assignments to input variables may be one of the constructs as listed under Assignment.

  • assignments to →in-out variables
    The expression on the right side of the assignment operator ":=" in the assignments to in-out variables may be just a construct which might be on the left side of the assignment operator ":=" as well.

  • assignments of →output variables (incl. to output ENO)
    The expression on the right side of the assignment operator "=>" in the assignments of output variables may be a declared →variable (e.g. result) of a fitting →data type.

As alternatives, you can use the following variants for the call:

  • non-formal call
    The parameter list must contain the same number of input variables, in exactly the same order and of fitting data types as given in the declaration , except the execution control parameters EN and ENO.

    Example: Inst2 (10,20,T#3ms); – This non-formal call is equivalent to the formal call: Inst2 (EN := TRUE,IN1:=10,IN2 := 20,T1 := T#3ms, OUT => result);

  • incomplete parameter list of formal call
    You can omit input variables and output variables within the parameter list. Omitted input variables keep the values of a possibly preceding call or assignment (see example below). If there are not preceding calls or assignments, the →initial value of the input variable is used.

  • accesses defined separately from the formal call (except for EN)
    You can enter accesses to input variable and/or output variables before/after the call (e.g. in assignments). In this case, define an input variable or output variable by the name of the function block instance, the character . and the name of the input variable or output variable itself (e.g. Inst1.IN1). The values from the assignments are processed at the next call of the instance (unless overwritten otherwise).
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg An assignment to input EN of the block is only allowed within the formal call of the block.

Enhancement to IEC-standard

An enhancement to the →IEC-standard, it is possible to:

  • use partial elements of in- and output variables. Such partial elements are e.g. the access to an ARRAY element or a structure element; see the following example for Inst4.

  • use assignments of output ENO of the block separately from the call of the block.

The FAQ article "When to use a formal call? When to use a non-formal call?" lists a table when to use formal call vs. non-formal call.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg If you want to call the body of the base function block from within a derived function block, use SUPER(); . See under " Declaration of a function block in ST " for an example.

Example
Inst1();
Inst2a[5](); (* call of a function block instance that is declared by means of an one-dimensional array *)
Inst2b[1, 3] (); (* call of a function block instance that is declared by means of a two-dimensional array *)
Inst2c[2, 4, 1] (); (* call of a function block instance that is declared by means of a three-dimensional array
The call of a function block instance that is declared by means of a four-dimensional array is similar. *)
Inst3 (IN1 := 10, IN2 := 20, T1 := T#3ms, OUT => result);
 
(* call of the function block instance 'Inst4' with assignments to 2 array elements and assignment of a structure element *)
(* Conditions: Input variable 'arrVar' has been declared as array variable with index subrange [1..2]. *)
(* Output variable 'out' has been declared based on a structured data type with structure element 'Elem1'. *)
Inst4(arrVar[1] := 16#01, arrVar[2] := 16#02, out.Elem1 => result1);

Examples for incomplete parameter list of formal call for a function block instance and accesses defined separately:

Syntax

Meaning

Inst1.IN1:=10;

assigning value 10 to input IN1 of function block instance Inst1

Inst2a[5].IN1

:= 10;

assigning value 10 to input IN1 of function block instance Inst2a that has been declared by means of ARRAY OF [1..5]

Inst1(IN2:=20);

calling the function block instance Inst1, assigning value 20 to input IN2 while input IN1 keeps value 10

result:=Inst1.OUT;

because of the read output OUT of Inst1: assigning value 30 (under the assumption that Inst1 adds the values) to local variable result

Inst1(IN2 := fun2(EN := FALSE));

calling the function block instance Inst1,
Because of EN := FALSE, fun2 is not called and assigned to input IN2 . Hence, input IN2 keeps value 20 from the last call .
See "Assignments in ST" for detailed information on the behavior of calls containing an assignment to the input EN.