Function, L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 71

Advertising
background image

L-force | PLC Designer

Concepts and Base Components

DMS 4.1 EN 03/2011 TD29

69

3.7.2

Function
A function is a POU, which yields exactly one data element (which can consist of
several elements, such as fields or structures) when it is processed, and whose call in
textual languages can occur as an operator in expressions.
A function POU can be added to the project via command "Add Object / POU". To
assign the function to an existing application, select the application entry in the
Devices view and use the command from the context menu. Otherwise it will be added
to the POUs view. In the Add POU dialog choose type 'Function', enter a name
(<function name>) and a return data type (<data type>) for the new function and
choose the desired implementation language. After confirming the settings with
button Open the editor window for the new function will open and you can start
editing:

Declaration:
A function declaration begins with the keyword FUNCTION. A name and a data type
must be defined.
Syntax:
FUNCTION <function name> : <data type>
This is followed by the variable declarations of input and function variables.
A result must be assigned to a function. That is that the function name is used as an
output variable.

Note: If a local variable is declared as RETAIN in a function, this is without any effect
! The variable will not be written to the Retain area.

Abb. 6

Example of a function in ST (This function takes three input variables and returns the product of
the second two added to the first one)

Advertising