Vai al contenuto

Function and Function Block Statements

Semantics
  • Functions are invoked as elements of expressions consisting of the function name followed by a parenthesized list of arguments. Each argument can be a literal, a variable, or an arbitrarily complex expression.
  • Function blocks are invoked by a statement consisting of the name of the function block instance followed by a parenthesized list of arguments. Both invocations with formal argument list and with assignment of arguments are supported.
  • RETURN: function and function block control statements consist of the mechanisms for invoking function blocks and for returning control to the invoking entity before the physical end of a function or function block. The RETURN statement provides early exit from a function or a function block (e.g., as the result of the evaluation of an IF statement).
Syntax
  • Function::
dst_var := function_name( arg1, arg2 , … , argN );
  • Function block with formal argument list:
instance_name( var_in1 := arg1 ,var_in2 := arg2 ,… ,var_inN := argN );
  • Function block with assignment of arguments:
instance_name.var_in1 := arg1;…instance_name.var_inN := argN;instance_name();
  • Function and function block control statement:
RETURN;ExamplesCMD_TMR( IN := %IX5, PT:= 300 ) ;FB invocation with formal argument list:IN := %IX5 ;PT:= 300 ;CMD_TMR() ;FB invocation with assignment of arguments:a := CMD_TMR.Q;FB output usage:RETURN ;early exit from function or function block.