Calling Functions
The Structured Text (ST) programming language enables calling functions. Function calls can be used in any expression.
Function calls | |
---|---|
Name | Name of the called function written in IEC 61131-3 language or in C |
Meaning | Calls a ST, IL, LD or FBD functions or a C function and gets its return value |
Syntax | <variable> := <funct> (<par1>, ... <parN> ); |
Operands | The type of return value and calling parameters must follow the interface defined for the function. |
Return value | Value returned by the function |
When setting the value of the return parameter in the body of a function, assign the return parameter using the same name as the function:
FunctionName := <expression>;
Example
Example1: IEC 61131-3 function call
(* Main ST program *) (* gets an integer value and converts it into a limited time value *) dint_timeprog := SPlimit ( tprog_cmd ); appl_timer := TMR (dint_timeprog * 100); (* Called FBD function named 'SPlimit' *)
Example2: "C" function call – same syntax as for IEC 61131-3 function calls
(* Functions used in complex expressions: min, max, right, mlen and left are standard "C" functions *) limited_value := min (16, max (0, input_value) ); rol_msg := right (message, mlen (message) - 1) + left (message, 1);
Provide Feedback