Add / modify / delete Interfaces

Interfaces of a TwinCAT module can be added, edited and deleted with the help of the TwinCAT Module Class (TMC) editor.

This article describes:

Step 1: generate a new interface

1. After starting the TMC Editor, select the Data Types node.
2. Click on Add a new interface to extend the list of interfaces by a new interface.
A new entry IInterface1 is then listed:
Add / modify / delete Interfaces 1:
3. To open the details you can either select the appropriate node in the tree or double-click on the row in the table.
Add / modify / delete Interfaces 2:
4. Enter a meaningful name - in this sample "IStateMachine".

Step 2: add methods to the interface

1. Click on Edit Methods... to get a list of the methods of this interface:
Add / modify / delete Interfaces 3:
2. Click on the + button to generate a new default method, "Method1".
Add / modify / delete Interfaces 4:
3. Double-click on the method or select a node in the tree to open the details.
4. Give the default "Method1" a more meaningful name.
5. Subsequently, you can add parameters by clicking on Add a new parameter or edit parameters of the "SetState" method.
Add / modify / delete Interfaces 5:
The new parameter, "Parameter1", is generated by default as "Normal Type" "INTEGER".
6. Edit the parameter by clicking on the name "Parameter1".
The "Normal Type" can also be changed to "Pointer" and so on – the data type itself can also be selected.
Add / modify / delete Interfaces 6:
In this case "NewState" is the new name – the rest of the settings are not changed.
Add / modify / delete Interfaces 7:
7. By repeating step 2 "Add methods to interface", all methods are listed – you can re-order the methods with the help of the move up / move down button.
Add / modify / delete Interfaces 8:
8. The interface is ready to be implemented by your module.
Add / modify / delete Interfaces 9:

Step 3: Add the new interface to Implemented Interfaces

1. Select the module that is to be extended by the new interface - in this case select the destination Modules->CModule1.
2. Extend the list of implemented interfaces by a new interface with Add a new interface to the module by clicking on the + button.
Add / modify / delete Interfaces 10:
3. All available interfaces are listed - select the new template "IStateMachine" and end with OK.
Add / modify / delete Interfaces 11:
The new interface "IStateMachine" is part of the module description.
Add / modify / delete Interfaces 12:

Step 4: Start the TwinCAT TMC Code Generator to generate code for the module description.

1. In order to generate the C/C++ code on the basis of this module description, right-click in the C/C++ project and then select the TwinCAT TMC Code Generator.
Add / modify / delete Interfaces 13:
The module "Module1" then contains the new interfaces
CModule1: Start()
CModule1: Stop()
CModule1: SetState(SHORT NewState).
Add / modify / delete Interfaces 14:
Done – the user-defined code can now be inserted in this area.

Optional change of the interface

Add / modify / delete Interfaces 15:

User-defined code will never be deleted

In the case of changes to the interface (e.g. the parameters of a method will be extended later), the user-defined code will never be deleted. Instead, the existing method will merely be provided with a comment if the TMC Code Generator cannot map the methods.

Add / modify / delete Interfaces 16: