Skip to main content

Object: Program

A program is a POU that yields one or more values when executed. All values remain unchanged after program execution until the next execution. The call order of programs in an application are defined in task objects.

You add the object to the application or the project by clicking Project → Add Object → POU. In the device tree and in the POUs view, the program POUs have the (PRG) suffix.

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. A program call is not allowed in a function. There are not instances of programs.

If a POU calls a program and values of the program change as a result, then these changes are retained until the next program call. The values of the program are retained even if the next call is made by another POU. This is different from calling a function block. When the function block is called, only the values of the respective instance of the function block change. The changes are to be considered only when a POU calls the same instance again.

You can also set the input and/or output parameters for a program directly when you call it.

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

If you use the Input Assistant to insert a program call and the Insert with arguments option is selected in the Input Assistant, then CODESYS adds input and/or output parameters to the program call according to the syntax.

Example 511. Examples

Calls:

AWL:

_cds_img_program_cal_awl2.png

With assignment of the parameters:

_cds_img_program_call_awl.png

ST:

PLC_PRG()
erg := PLC_PRG.out2;

With assignment of the parameters:

PLC_PRG(in1:=2, out1=>erg);
_cds_img_program_call_fbd.png