Sample11a: Module communication: C module calls a method of another C module

This article describes how TC3 C++ modules could communicate via method calls. The method protects the data with a critical section thus the access could be initiated from different contexts / tasks.

Download

Here you can access the source code for this sample.

1. Unpack the downloaded ZIP file.
2. Using a Visual Studio with TwinCAT installed, open the project via Open Project ....
3. Configure signing for this project by switching on TwinCAT signing with a right-click on Project->Properties->Tc Sign and configure your certificate and password if necessary.
For more information on signing C++ projects, click here.
4. Select your target system.
5. Build the sample (e.g. Build->Build Solution).
6. Activate the configuration by clicking on Sample11a: Module communication: C module calls a method of another C module 1:.
The sample is ready for operation.

Description

The project contains three modules:

The read/write instances are configured for access to the DataProvider instance, which can be seen in the Interface Pointer menu on the instance configuration.
The context (task), in which the instances are to be executed, can also be configured there. In this sample two tasks are used, TaskRead and TaskWrite.
The DataWriteCounterModul parameters of CModuleDataWrite and DataReadCounterModulo (CModuleDataRead) enable the moment to be determined, at which the module instances initiate the access.

CriticalSections are described in the SDK in TcRtInterfaces.h and are therefore intended for the real-time context.