The use of interfaces is a means of object-oriented programming. An interface POU defines a set of methods and properties without an implementation. An interface can be described as an empty shell of a function block. It must be implemented in the declaration of the function block in order to get realized in the function block instances. A function block can implement one or several interfaces.
The same method can be realized with identical parameters but different implementation code by different function blocks. Therefore, an interface can be used/called in any POU without the need that the POU identifies the particular function block that is concerned.
An interface IFT
is inserted below an application. It contains 2 methods Method1
and Method2
. Neither the interface nor the methods contain any implementation code. Just the declaration part of the methods is to be filled with the desired variable declarations:
Interface with 2 methods:
1 or multiple function blocks can now be inserted, implementing the above defined interface ITF
.
Creating a function block implementing an interface
When function block POU
is added to the , the methods Method1
and Method2
are automatically inserted below as defined by ITF
. Here they can be filled with function block-specific implementation code.
Using the interface in the function block definition
An interface can extend other interfaces by using EXTENDS
(see following example Example for Extending an Interface) in the interface definition.
An interface can also define an interface property, consisting of the accessor methods Get
and/or Set
. For further information on properties, refer to the chapter Property. A property in an interface like the possibly included methods is just a prototype that means it contains no implementation code. Like the methods, it is automatically added to the function block, which implements the interface. There it can be filled with specific programming code.
Consider the following:
It is not allowed to declare variables within an interface. An interface has no body (implementation part) and no actions. Just a collection of methods is defined within an interface and those methods are only allowed to have input variables, output variables, and input/output variables.
Variables declared with the type of an interface are treated as references.
A function block implementing an interface must have assigned methods and properties which are named exactly as they are in the interface. They must contain identically named inputs, outputs, and inputs/outputs.
To add an interface to an application, select the
node in the , click the green plus button and select . Alternatively, execute the command . If you select the node before you execute the command, the new interface is available for all applications.In the extension of another interface.
dialog box, enter a name for the new interface (<interface name>). Optionally you can activate the option if you want the current interface to be an
If ITF1
extends ITF_base
, all methods described by ITF_base
will be automatically available in ITF1
.
Extending an interface
Click
to confirm the settings. The editor view for the new interface opens.Syntax
INTERFACE <interface name>
For an interface extending another one:
INTERFACE <interface name> EXTENDS <base interface name>
Example
INTERFACE interface1 EXTENDS interface_base
To complete the definition of the interface, add the desired collection of methods. For this purpose, select the interface node in the
and execute the command . The dialog box opens for defining a method to be part of the interface. Alternatively, select the interface node in the , click the green plus button and select . Add as many methods as desired and remember that these methods are only allowed to have input variables, output variables, and input/output variables, but no body (implementation part).