SUPER Pointer

Overview

For each function block that extends a base function block, a pointer with name SUPER is automatically available. It points to the base function block instances.

This provides an effective solution for the following issue:

  • SUPER offers access to methods of the base function block implementation. With the keyword SUPER, a method can be called which is valid in the base (parent) class instance. Thus, no dynamic name binding takes place.

SUPER may only be used in methods and in the associated function block implementation.

Because SUPER is a pointer to the base function block, you have to dereference it to get the address of the function block: SUPER^.METH_DoIt

SUPER Call in Different Implementation Languages

Implementation Language

Example

ST

SUPER^.METH_DoIt();

FBD/CFC/LD

NOTE: The functionality of SUPER is not yet implemented for Instruction List.

Example

Use of SUPER and THIS pointers.

FUNCTION_BLOCK FB_Base
VAR_OUTPUT
    iCnt : INT;
END_VAR
    METHOD METH_DoIt : BOOL
    iCnt := -1;
    
    METHOD METH_DoAlso : BOOL
    METH_DoAlso := TRUE;

FUNCTION_BLOCK FB_1 EXTENDS FB_Base
VAR_OUTPUT
    iBase: INT;
END_VAR
// Calls the method defined under FB_1
THIS^.METH_DoIt();
THIS^.METH_DoAlso();
// Calls the method defined under FB_Base
SUPER^.METH_DoIt();
SUPER^.METH_DoAlso();
iBase := SUPER^.iCnt;

    METHOD METH_DoIt : BOOL
    iCnt := 1111;
    METH_DoIt := TRUE;

PROGRAM PLC_PRG
VAR
    myBase: FB_Base;
    myFB_1: FB_1;
    iTHIS: INT;
    iBase: INT;
END_VAR
myBase();
iBase := myBase.iCnt;
myFB_1();
iTHIS := myFB_1.iCnt;