A User Defined Function is a sequence of statements which may return an optional value.
A function that returns a value can be called from an Expression.
A function that does not return a value can be called through a Structured Text Function Call.
A Function uses this syntax:
function ::=
FUNCTION function-name [ : return-type ]
{ variable-declaration }
[ function-code ]
END_FUNCTION
return-type ::= [ Elementary Data Type | Derived Data Type ]
function-code ::= structured-text
Where:
Use any of the following for the return-type:
if the return-type is not used, the function does not return a value.
Use any of the following for the program-code:
A function can call other functions.
Function CalcStdDev : LREAL var_input v1,v2,v3,v4 : LREAL; end_var var SumOfSquares : LREAL; Mean : LREAL; end_var (* Calculate the mean *) Mean := (v1 + v2 + v3 + v4) / 4; (* Calculate the standard deviation *) SumOfSquares := (v1 - Mean) ** 2 + (v2 - Mean) ** 2 + (v3 - Mean) ** 2 + (v4 - Mean) ** 2; CalcStdDev := sqrt( SumOfSquares / 4 ); End_Function
Table 20a - IEC 61131-3 Second Edition.
Table 19 - IEC 61131-3 Third Edition.
To learn about other program units.
To learn about variable declarations.
To learn about ST Statements.
For the meaning of terms used in Fernhill SCADA.