Sample20: FileIO-Write
This article describes the implementation of TC3 C++ modules, which write (process) values to a file.
The writing of the file is triggered by a deterministic cycle - the execution of File IO is decoupled (asynchronous), i.e.: the deterministic cycle continues to run and is not hindered by writing to the file.
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 .
- The sample is ready for operation.
Description
The sample includes an instance of TcAsyncWritingModule, which writes data to the file AsyncTest.txt in directory BOOTPRJPATH (Windows: C:\TwinCAT\3.x\Boot; TwinCAT/BSD: /usr/local/etc/TwinCAT/3.1/Boot).
TcAsyncBufferWritingModule has two buffers (m_Buffer1, m_Buffer2), which are alternately filled with current data. The member variable m_pBufferFill points to the buffer that is currently to be filled. Once a buffer is filled, the member variable m_pBufferWrite is set such that it points to the full buffer.
These data are written to a file with the aid of TcFsmFileWriter.
Note that the file has no human-readable content, such as ASCII characters; in this sample, but binary data are written to the file.