Calling a function

A function calculates a result according to the current value of its inputs. Unlike a function block, a function has no internal data and is not linked to declared instances. A function has only one output: the result of the function. A function can be:
- a standard function (SHL, SIN...)
- a function written in "C" language and embedded on the target

ST Language

To call a function block in ST, you have to enter its name, followed by the input parameters written between parenthesis and separated by comas. The function call may be inserted into any complex expression. a function call can be used as an input parameter of another function. The following example demonstrates a call to "ODD" and "SEL" functions:

(* the following statement converts any odd integer value into the nearest even integer *)
iEvenVal := SEL ( ODD( iValue ), iValue, iValue+1 );

FBD and LD Languages

To call a function block in FBD or LD languages, you just need to insert the function in the diagram and to connect its inputs and output.

IL Language:

To call a function block in IL language, you must load its first input parameter before the call, and then use the function name as an instruction, followed by the other input parameters, separated by comas. The result of the function is then the current result. The following example demonstrates a call to "ODD" and "SEL" functions:

(* the following statement converts any odd integer into "0" *)
Op1: LD    iValue
     ODD
     SEL   iValue, 0
     ST    iResult