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, ⮫ methods, ⮫ methods, ⮫ methods, ⮫ methods, ⮫ methods, ⮫ methods, ⮫ 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 “ITF” object is added to the application or the project by clicking “Project Add Object Interface”
For more information, see: ⮫ “Implementation of an Interface ”
“Inheritance” |
|
“Name” |
Interface name |
“Advanced” |
For more information, see: ⮫ “Extension of an interface ” |
You can add the “Interface Property” and “Interface Method” objects to the “ITF” object. Interface methods may contain only the declarations of input, output and VAR_IN_OUT 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.
Note the following:
-
You must 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 VAR_IN_OUT 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 VAR_IN_OUT variables as in the interface.




NOTICE

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.
