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.

../_images/81db8d5b9aa308ae0a317f3426d9b5b1

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. Regard the Recommendations \ on the naming of identifiers.

If you would like to set input and/or output parameters when you call the program, you can do this in the text languages IL and ST by assigning values to the parameters after the program name in parentheses (for input parameters this assignment takes place using “:=” just as with the initialization of variables ( Variables declaration) at the declaration position, for output parameters “=>” is to be used).

If the program is inserted via input assistant (<F2>) with option With arguments in the implementation window of a ST or IL POU, it will be displayed automatically according to this syntax with all of its parameters. But you not necessarily must assign these parameters.

Examples for program calls

In IL

CAL PRGexample2

LD PRGexample2.out_var

ST  ERG

or with assigning the parameters (input assistant     "With arguments", see above):

CAL PRGexample2(in_var:=33, out_var=>erg     )

In ST

PRGexample2;

Erg := PRGexample2.out_var;

or with assigning the parameters (input     assistant "With arguments", see above):

PRGexample2(in_var:=33, out_var=>erg );

In FBD

../_images/fb49b769437591e60a33139006eab46b

Example for a possible call sequence for \ PLC_PRG

See the program PRGexample shown in the picture at top of this chapter:

LD 0

ST  PRGexample.PAR (\*Default     setting for PAR is 0\*)

CAL IL call (\*ERG in IL call results     in 1\*)

CAL ST call (\*ERG in ST call results     in 2\*)

CAL FBD call (\*ERG in FBD call results     in 3\*)

If the variable PAR from the program PRGexample is initialized by a main program with 0, and then one after the other programs are called with above named program calls, then the ERG result in the programs will have the values 1, 2, and 3. If one exchanges the sequence of the calls, then the values of the given result parameters also change in a corresponding fashion.