A function is a section of code that can be called by another part of a program or script.
In the Fernhill SCADA implementation of IEC 61131-3 there are three groups of functions:
In IEC 61131-3, all functions have the following two variables implicitly declared:
VAR_INPUT EN : BOOL := TRUE; END_VAR
VAR_OUTPUT ENO : BOOL; END_VAR
If the EN parameter is FALSE, the function body is skipped and ENO is set to FALSE.
If the EN parameter is TRUE, the function body is executed. If the function executes without error, the ENO parameter is set to TRUE. If there is an error in the execution of the function, the ENO parameter is set to FALSE.
In an informal function call, parameters are provided in the declared order. For example:
In an informal function call you cannot map variables to the implicitly declared EN and ENO parameters.
In an informal call, a runtime error in the function call will cause the program to halt.
In a formal function call, parameters are declared by name. For example:
SEL( G:=expression, IN0:=expression, IN1:=expression )
In a formal function call you can map variables to the implicitly declared EN and ENO parameters. For example:
SEL( G:=expression, IN0:=expression, IN1:=expression, ENO=>Result )
The way IEC 61131-3 code handles errors in function calls changes depending on whether ENO is present or absent:
ENO Parameter | Effect of error |
---|---|
Absent | Causes the program to halt. |
Present | The rest of the function is skipped. The ENO output is set to FALSE. Execution of the program continues. |
This table lists the common standard functions supported by Fernhill SCADA:
Function Type | Example |
---|---|
Conversion Functions | ANY_TO_STRING( 5 ) |
Mathematical Functions | SQRT( 5 ) |
Arithmetic Functions and Operators | ADD( A, 5 ) |
Bit Shift Functions | SHR( A, 4 ) |
Bitwise Boolean Functions | A AND 16#0F |
Conversion Functions | QUALITY_TO_STRING( 192, TRUE ) |
Selection Functions | SEL( InputValue, 'Off', 'On' ) |
Comparison Functions | A > B |
String Functions | FIND( 'The quick brown fox', 'quick' ) |
Date and time Functions | ADD_DT_TIME( DT#2013-01-07-16:46:00.000, T#4h30m) |
Validation Functions | IS_VALID( %"Tag Reference" ) |
Type Information Functions | IsTypeOf( A, ANY_INT ) |
This table lists the common functions supported by Fernhill SCADA:
Function Type | Example |
---|---|
System Functions | SysGetDateAndTime() |
Operator Action Functions | OpenGraphic() |
To learn about common elements of IEC 61131-3 scripts.
To learn about using scripts in Fernhill SCADA.
For the meaning of terms used in Fernhill SCADA.