Call of function in ST

Syntax
function-name();
 
function-name
(input_1:=x1,input_2:=x2,...,input_n:=xn,
output_1=>y1,output_2=>y2,...,output_n=>yn);

Meaning

formal call of the →function (= formal function →call) without or with parameter list
The call of a user function declared by you (e.g. Simple2) and of a system function (e.g. the IEC-block AND) is done with the same syntax.

No check of recursions

Recursions for →functions and →methods are not forbidden or checked by logi.CAD 3 . Nevertheless, do not call a function/method from within itself and avoid 2 (or more) functions/methods calling each other (= mutual recursion) within your application.
Mind that recursions of functions/methods might cause unexpected results when your application is executed. For example, the application might be executed in an infinite loop and/or the →runtime system might not respond anymore.

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 get the default →initial value.
    See the examples below.
    Special behavior: In case of extensible functions (such as the AND block), input variables after the top one specified are not considered for the functionality of the block. Hence, these input variables do not get the default initial value (see example below) .

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.

Example
Simple1();
Simple2(IN1:=10, IN2 :=20, T1 := T#3ms, OUT => result);
AND(IN1:=TRUE, IN2:=FALSE);

Examples for incomplete parameter list of formal call for a function:

Syntax

Meaning

FUNCTION fun1 : INT
VAR_INPUT
i1 : INT := 7;
i2 : INT := 8;
END_VAR
END_FUNCTION

declaration of the function fun1

declaration of the variables i1 and i2 with initial values

FUNCTION fun2 : INT
fun2:=22;
END_FUNCTION

declaration of the function fun2 (with the result value '22')

fun1();

call of the function fun1 without parameter list
fun1 gets the initial value 7 for i1 and the initial value 8 for i2.

fun1(i2:=3);

call of the function fun1 with incomplete parameter list
fun1 gets the initial value 7 for i1 and the assigned value 3 for i2.

fun1(i2:=fun2());

call of the function fun1 with incomplete parameter list
fun1 gets the initial value 7 for i1 and the return value 22 (of fun2) for i2.

fun1(i2:=fun2(EN:=FALSE));

call of the function fun1 with incomplete parameter list
fun1 gets the initial value 7 for i1 and the initial value 8 for i2.

Explanation: Because of EN := FALSE, fun2 is not called. Hence, i2 is supplied with the initial value.
See "Assignments in ST" for detailed information on the behavior of calls containing an assignment to the input EN.

Examples for incomplete parameter list of formal call for the extensible AND block:

Syntax

Meaning

AND();

call of the function AND without parameter list
This call is highlighted as faulty. Assignments to the first 2 inputs of the AND block are required.

AND(IN2:=TRUE);

call of the function AND with incomplete parameter list
The value TRUE is assigned to IN2.
The omitted input variable before IN2 (hence: IN1) gets the default initial value FALSE.
The omitted input variables after IN2 (hence: IN3 to IN16) are not considered for the functionality of AND .

AND(IN1:=TRUE,IN10:=TRUE);

call of the function AND with incomplete parameter list
The value TRUE is assigned to IN2 and IN10.
The omitted input variables before IN10 (hence: IN2 to IN9) get the default initial value FALSE.
The omitted input variables after IN10 (hence: IN11 to IN16) are not considered for the functionality of AND .