Object Program

A program is a POU, which returns one or several values when executed. After a program execution, all values are retained until the program is executed again. The call sequence of the programs within a PLC project is defined in task objects.

In the PLC project tree, the program POUs have the suffix (PRG). The editor of a program consists of the declaration part and the implementation part.

The top line of the declaration part contains the following declaration:

PROGRAM <program>

Calling a program

Programs and function blocks can call a program. Program calls are not allowed in a function. Programs do not have instances.

If a POU calls a program and the call results in changes to the values of the program, the changes are retained until the next program call. The values of the program are also retained, if the next call occurs from another POU. This differs from a function block call. When a function block is called, only the values of the respective function block instance change. The changes are only relevant, if a POU calls the same instance again.

Alternatively, the input and/or output parameters for a program can also be set directly with the call.

Syntax:

<program>(<input variable> := <value>, <output value> => <value>):

If you add a program call via the input assistant and the option Insert with arguments is enabled in the Input assistant, TwinCAT adds input and/or output parameters to the program call, according to the corresponding syntax.

Examples:

IL:

Object Program 1:

With parameter assignment:

Object Program 2:

ST:

SampleProg();
nRes := SampleProg.nOut2;

With parameter assignment:

SampleProg(nIn1 := 2, nOut2 => nRes);

FBD:

Object Program 3: