Extension of Function Blocks

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:

Hint

Multiple inheritance is not permitted.

Exception: A function block can implement multiple interfaces, and an interface can extend other interfaces.

See also

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.

  1. Right-click the Application object in the device tree and select Project ‣ Add Object ‣ POU .

    ⇒ The Add POU dialog opens.

  2. Type the name for the new POU in the Name input field, for example POU_Ex.

  3. Select Function block.

  4. Click Advanced and then the more button ().

  5. 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.

  6. As an option, you can select an Access modifier for the new function block from the drop-down list.

  7. Select from the Implementation language combo box (example: Structured text (ST).

  8. 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 block POU_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).

  1. Double-click the function block POU_Ex(FB) in the device tree.

    ⇒ The function block editor opens.

  2. Extend the existing entry in the top line FUNCTION_BLOCK POU_Ex with EXTENDS POU_1.

    ⇒ The function block POU_Ex extends the basic function block POU_1.