Материал: m912201e

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

14WAGO-I/O-PRO 32 V2.2 Overview

Project Components

If you define functions with the names CheckRangeSigned and CheckRangeUnsigned, then range exceeding of variables declared with subrange types (see chapter Data types of the online help chapters,) can be intercepted.

All these check function names are reserved for the described usage. For further description please see chapter Datatypes of the Online Help chapters, Array.

2.3.4 Function Block

A function block is a POU which provides one or more values during the procedure. As opposed to a function, a function block provides no return value.

A function block declaration begins with the keyword FUNCTION_BLOCK.

Reproductions or instances (copies) of a function block can be created.

x Example of a function block in IL

Example in IL of a function block with two input variables and two output variables. One output is the product of the two inputs, the other a comparison for equality:

2.3.5 Function Block Instances

Reproductions or instances (copies) of a function block can be created.

Each instance possesses its own identifier (the instance name), and a data structure which contains its inputs, outputs, and internal variables. Instances

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

WAGO-I/O-PRO 32 V2.2 Overview

15

Project Components

 

 

 

are declared locally or globally as variables, whereas the name of the function block is indicated as the type of an identifier.

Example of an instance with the name INSTANCE of the FUB function block:

INSTANCE: FUB;

Function blocks are always called through the instances described above.

Only the input and output parameters can be accessed from outside of an function block instance, not its internal variables.

x Example for accessing an input variable

The function block FB has an input variable in1 of the type INT.

PROGRAM prog

VAR

inst1:fb; END_VAR

LD 17

ST inst1.in1

CAL inst1

END_PROGRAM

The declaration parts of function blocks and programs can contain instance declarations. Instance declarations are not permitted in functions.

Access to a function block instance is limited to the POU in which it was declared unless it was declared globally.

The instance name of a function block instance can be used as the input for a function or a function block.

Note:

All values are retained after processing a function block until the next it is processed. Therefore, function block calls with the same arguments do not always return the same output values!

Note:

If there at least one of the function block variables is a retain variable, the total instance is stored in the retain area.

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

16WAGO-I/O-PRO 32 V2.2 Overview

Project Components

2.3.6 Calling a function block

The input and output variables of a function block can be accessed from another POU by setting up an instance of the function block and specifying the desired variable using the following syntax:

<Instance name>.<Variable name>

If you would like to set the input parameters when you open the function block, you can do this in the text languages IL and ST by assigning values to the parameters after the instance name of the function block in parentheses (this assignment takes place using ":=" just as with the initialization of variables at the declaration position).

Please regard, that the InOutVariables (VAR_IN_OUT) of a function block are handed over as pointers. For this reason in a call of a function block no constants can be assigned to VAR_IN_OUTs and there is no read or write access from outside to them.

VAR

inst:fubo;

var:int;

END_VAR var1:=2;

inst(instout1:=var1^);

not allowed in this case: inst(instout1:=2); or inst.inout1:=2;

Examples for calling function block FUB:

The multiplication result is saved in the variable ERG, and the result of the comparison is saved in QUAD. An instance of FUB with the name INSTANCE is declared.

x This is how the instance of a function block is called in IL

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

WAGO-I/O-PRO 32 V2.2 Overview

17

Project Components

 

 

 

x This is how the instance of a function block is called in ST (the declaration part the same as with IL)

x This is how the instance of a function block is called in FBD (the declaration part the same as with IL)

In SFC function block calls can only take place in steps.

2.3.7 Program

A program is a POU which returns several values during operation. Programs are recognized globally throughout the project. All values are retained from the last time the program was run until the next.

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

18WAGO-I/O-PRO 32 V2.2 Overview

Project Components

x Example of a program

Programs can be called. A program call in a function is not allowed. There are also no instances of programs.

If a POU calls a program, and if thereby values of the program are changed, then these changes are retained the next time the program is called, even if the program has been called from within another POU.

This is different from calling a function block. There only the values in the given instance of a function block are changed.

These changes therefore play a role only when the same instance is called.

A program declaration begins with the keyword PROGRAM and ends with END_PROGRAM.

Examples for program calls:

In IL:

CAL PRGExample

LD PRGexample.PAR

ST ERG

In ST:

PRGExample;

Erg := PRGexample.PAR;

In FBD :

Example for a possible call sequence for PLC_PRG:

LD 0

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32