Object ‘Interface’

Symbol:

Keyword: INTERFACE

An interface is a means of object-oriented programming. The object ITF describes a set of method and property prototypes. In this context, prototype means that the methods and properties contain only declarations and no implementation.

This allows different function blocks having common properties to be used in the same way. An object ITF is added to the application or the project with the command Project ‣ Add object ‣ Interface .

Adding an interface
Inheritance
Name Interface name
Extends : Extends the interface that you enter in the input field or via the input assistant . This means that all methods of the interface that extend the new interface are also available in the new interface.

You can add the objects Interface property and Interface method to the object ITF. Interface methods may contain only the declarations of input, output and input/output variables, but no implementation.

So that you can also use an interface in the program, there must be a function block that implements this interface.

This means:

A function block can implement one or more interfaces. You can use the same method with identical parameters, but different implementation code in different function blocks.

Please note the following:

Hint

Interface references and online change The following can happen with a compiler version < 3.4.1.0: if a function block changes its data because variables are added or deleted, or because the type of variables changes, then CODESYS copies all instances of the function block to a new memory location. In this case, however, an interface reference refers not to the new memory location, but still to the old one.

In case of compiler versions >= 3.4.1.0, CODESYS automatically re-addresses the interface references so that CODESYS also references the correct interface in case of an online change. CODESYS requires additional code and more time for this, so that jitter problems can occur depending on the number of objects concerned. Therefore, CODESYS displays the number of variables and interface references concerned before the execution of the online change and you can then decide whether the online change should be executed or aborted.

Example

Definition of an interface and its use in a function block

You have inserted the interface ITF below the application. The interface contains the methods Method1 and Method2. ITF, Method1 and Method2 contain no implementation code. You insert the required variable declarations only in the declaration part of the methods.

If you subsequently insert a function block in the device tree that implements the interface ITF, CODESYS automatically also inserts the methods Method1 and Method2 under the function block. Here you can implement function-block-specific code in the methods.