Module-to-module communication
TcCOM modules can communicate with one another. This article is intended to provide an overview of the various options. There are four methods of module-to-module communication:
- IO Mapping (linking of input/output symbols)
- IO Data Pointer
- Method calls via interface
- ADS
These four methods will now be described.
IO Mapping (linking of input/output symbols)
The inputs and outputs of TcCOM modules can be linked by IO Mapping in the same way as the links to physical symbols in the fieldbus level. To do this, data areas are created in the TMC editor that describe the corresponding inputs/outputs. These are then linked in the TwinCAT solution.
Through mapping, the data are provided or accepted at the task beginning (inputs) or task end (outputs) respectively. The data consistency is ensured by synchronous or asynchronous mapping.
The implementing language (PLC, C++, Matlab) is unimportant.
The following sample shows the realization:
Sample12: Module communication: IO mapping used
IO Data Pointer
Direct memory access is also possible within a task via the Data Area Pointers, which are created in the TMC Editor.
If several callers of a task or callers from other tasks occur, the user must ensure the data consistency through appropriate mechanisms. Data pointers are available for C++ and Matlab.
The following sample shows the realization:
Sample10: Module communication: Use of data pointers
Method calls via interfaces
As already described, TcCOM modules can offer interfaces that are also defined in the TMC editor. If a module implements them ("Implemented Interfaces" in the TMC editor), it offers appropriate methods. A calling module will then have an "Interface Pointer" to this module in order to call the methods.
These are blocking calls, meaning that the caller blocks until the called methods come back and the return values of the methods can thus be directly used. If several callers of a task or callers from other tasks occur, the user must ensure the data consistency through appropriate mechanisms.
The following samples show the realization:
Sample11: Module communication: PLC module calls a method of a C-module
Sample11a: Module communication: C-module cites a method in the C-module
Further samples exist for the communication with the PLC.
ADS
As the internal communication of the TwinCAT system in general, ADS can also be used to communicate between modules. Communication in this case is acyclic, event-controlled communication.
At the same time ADS can also be used to collect or provide data from the UserMode and communicate with other controllers (i.e. via the network). ADS can also be used to ensure data-consistent communication, e.g. between tasks/cores/CPUs. In this case TcCOM modules can be both clients (requesters) and servers (providers). The implementing language (PLC, C++, Matlab) is unimportant.
The following samples show the realization:
Sample06: UI-C#-ADS client uploads the symbols from the module