Functions

Help Contents

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 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.

Formal Function Calls

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.

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)
Validation FunctionsIS_VALID( %"Tag Reference" )
Type Information FunctionsIsTypeOf( A, ANY_INT )

Extension Functions

This table lists the common functions supported by Fernhill SCADA:

Function TypeExample
System Functions SysGetDateAndTime()
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 the meaning of terms used in Fernhill SCADA.