The extension of a function block is based on the concept of inheritance in object-oriented programming. A derived function block thereby extends a basic function block and in doing so is given the properties of the basic function block in addition to its own properties.
The extension of a function block means:
-
The inherited function block contains all data and methods that are defined by the basic function block. You can use an instance of the basic function block in every context in which CODESYS expects a function block of the type of the basic function block.
-
The derived function block can overwrite the methods that you have defined in the base function block. This means that the inherited function block can define a method with the same name, the same inputs and the same output as is defined by the basic function block.
Tip: You have the following support when overwriting methods, actions, attributes, and transitions that are inherited by the base block: When you insert a method, action, etc. below an inherited block, the “Add Object” dialog includes a combo box with a list of methods, actions, etc. used in the base block. You can accept these and adapt them accordingly.
-
The derived function block may not contain function block variables with the same names as used by the basic function block. The compiler reports this as an error.
The only exception: If you have declared a variable in the basic function block as
VAR_TEMP
, then the inherited function block may define a variable with the same name. In this case, the inherited function block can no longer access the variable of the basic function block. -
You can directly address the variables and methods of the basic function block within the scope of the inherited function block by using the
SUPER
pointer.




NOTICE

Multiple inheritance is not permitted.
Exception: A function block can implement multiple interfaces, and an interface can extend other interfaces.
Extension of a basic function block by a new function block
Requirement: the currently opened project possesses a basic function block, for example “POU_1(FB)”, which is to be extended by a new function block.
-
Right-click the “Application” object in the device tree and select “Project Add Object POU”.
The “Add POU” dialog opens.
-
Type the name for the new POU in the “Name” input field, for example “POU_Ex”.
-
Select “Function block”.
-
Click “Advanced” and then the more button (
).
-
In the category “Function blocks” under “Application” in the input assistant, select the POU(FB) that is to serve as the basic function block, for example
POU_1
, and click “OK”. -
As an option, you can select an “Access modifier” for the new function block from the drop-down list.
-
Select from the “Implementation language” combo box (example: “Structured text (ST)”.
-
Click “Add”.
CODESYS adds the
POU_Ex
function block to the device tree and opens the editor. The first line contains the text:FUNCTION_BLOCK POU_Ex EXTENDS POU_1
The function block
POU_Ex
extends the basic function blockPOU_1
.
Extension of a basic function block by an existing function block
Requirement: The open project possesses a base function block (example: POU_1(FB)
) and another function block (example: POU_Ex(FB)
). The function block POU_Ex(FB)
is also to be given the properties of the basic function block. This means that POU_Ex(FB)
should extend POU_1(FB)
.
-
Double-click the function block
POU_Ex(FB)
in the device tree.The function block editor opens.
-
Extend the existing entry in the top line
FUNCTION_BLOCK POU_Ex
withEXTENDS POU_1
.The function block POU_Ex extends the basic function block
POU_1
.