Functions

Introduction

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:

EN and ENO

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.

Informal Function Calls

In an informal function call, parameters are provided in the declared order. For example:

SEL( G, IN0, IN1 )

In an informal function call you can not specify the implicitly declared EN and ENO parameters.

In an informal call, a runtime error in the function call will cause the program to halt.

Formal Function Calls

In a formal function call, parameters are specified by name. For example:

SEL( G:=expression, IN0:=expression, IN1:=expression )

In an formal function call you can specify the implicitly declared EN and ENO parameters. For example:

SEL( G:=expression, IN0:=expression, IN1:=expression, ENO=>Result )

If the ENO parameter is not specified, a runtime error in a function will cause the program to halt.

If the ENO parameter is specified, a runtime error in a function will set the ENO output to FALSE and execution will continue.

Standard Functions

This table lists the common standard functions supported by Fernhill SCADA:

Function TypeExample
Conversion FunctionsANY_TO_STRING( 5 )
Mathematical FunctionsSQRT( 5 )
Arithmetic Functions and OperatorsADD( A, 5 )
Bit Shift FunctionsSHR( A, 4 )
Bitwise Boolean FunctionsA AND 16#0F
Conversion FunctionsQUALITY_TO_STRING( 192, TRUE )
Selection FunctionsSEL( InputValue, 'Off', 'On' )
Comparison FunctionsA > B
String FunctionsFIND( 'The quick brown fox', 'quick' )
Date and time FunctionsADD_DT_TIME( DT#2013-01-07-16:46:00.000, T#4h30m)

Extension Functions

This table lists the common functions supported by Fernhill SCADA:

Function TypeExample
System Functions SYS_GET_TIMESTAMP()
Operator Action Functions OpenGraphic()

Further Information

IEC 61131-3 Common Elements

To learn about common elements of IEC 61131-3 scripts.

IEC 61131-3 Scripts

To learn about using scripts in Fernhill SCADA.

Glossary

For definitions of the terms used in Fernhill SCADA.