A function block instance with a type-compliant interface must be assigned to a variable defined as type Interface. You can call methods via this variable only after this.
A variable of the interface type is always a reference to the assigned function block instance.
Example
An interface variable serves as a reference to a function block instance. It can reference any instance which implements this interface. The specific instance assigned can vary at runtime. Until the first assignment, the variable contains the value 0.
The I1 interface contains the GetName method.
The A and B function blocks implement the interface I1:
METHOD GetName : STRING
FUNCTION_BLOCK A IMPLEMENTS I1 FUNCTION_BLOCK B IMPLEMENTS I1
Both function blocks can include a method named GetName and the return type STRING.
A function includes the declaration of a variable of interface I1 type.
FUNCTION DeliverName : STRING
VAR_INPUT
l_i : I1;
END_VAR
Function blocks that implement the I1 interface can be assigned to these input variables.
Examples of function calls:
DeliverName(l_i := A_instance); // call with instance of type A DeliverName(l_i := B_instance); // call with instance of type B
Calling of interface methods:
In this case, it depends on the actual type of l_i whether the application calls A.GetName or B.GetName.
DeliverName := l_i.GetName();