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: Create a new interface in the TMC file.
- Step 2: Add methods to the interface in the TMC file.
- Step 3: Use the interface by adding it to the "Implemented Interfaces" of the module.
- Step 4: Start the TwinCAT TMC Code Generator to generate code for the module description.
- Optional change of the interface.
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:
- 3. To open the details you can either select the appropriate node in the tree or double-click on the row in the table.
- 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:
- 2. Click on the + button to generate a new default method, "Method1".
- 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.
- 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.
- In this case "NewState" is the new name – the rest of the settings are not changed.
- 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.
- 8. The interface is ready to be implemented by your module.
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.
- 3. All available interfaces are listed - select the new template "IStateMachine" and end with OK.
- The new interface "IStateMachine" is part of the module description.
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.
- The module "Module1" then contains the new interfaces
CModule1: Start()
CModule1: Stop()
CModule1: SetState(SHORT NewState).
- Done – the user-defined code can now be inserted in this area.
Optional change of the interface
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. |