Objekt ‘Schnittstelle’

Symbol: e8c97132c61bc1a3c0a8640e00e9571a_fc53f645c65138abc0a8640e0101e21d

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 e8c97132c61bc1a3c0a8640e00e9571a_9a3f06830c0506c5c0a8640e012f0ace : Extends the interface that you enter in the input field or via the input assistant e8c97132c61bc1a3c0a8640e00e9571a_21d51bd0cd4519c1c0a8640e00abb4b7 . 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:

  • the function block contains the interface in its IMPLEMENTS list in its declaration part
  • the function block contains an implementation for all methods and property prototypes of the interface

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:

  • You may not define variables within an interface. An interface has no implementation part and no actions. Only a collection of methods is defined, in which you may define only input, output and input/output variables.
  • CODESYS always treats variables declared with the type of an interface as references.
  • A function block that implements an interface must contain implementation code for the methods of the interface. You have named the methods exactly as in the interface and the methods contain the same input, output and input/output variables as in the interface.

Attention

:strong: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.

../_images/881b28ffc2bec0d8c0a8640e00fd8d32