Sample37: Archive data

The sample TcCOM object archive describes restoration and saving of an object state during initialization and deinitialization.

Sample37: Archive data 1:

TwinCAT supports retain data

TwinCAT also supports retain data, in order to utilize the NOVRAM of a device to make data persistent.

Download

Get 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 Sample37: Archive data 2:.
The sample is ready for operation.

Description

The sample TcCOM object archive describes restoration and saving of an object state during initialization and deinitialization. The state of the sample class CmoduleArchive corresponds to the value of the counter CModuleArchive::m_counter.

During the transition from PREOP to SAFEOP, i.e. when calling the method CModuleArchive::SetObjStatePS(), the object archive server (ITComObjArchiveServer) is used to create an object archive for reading, which is accessed via the interface ITComArchiveOp. This interface provides overloads from operator>>() in order to read them in the archive.

During the transition from SAFEOP to PREOP, i.e. when calling the method CModuleArchive::SetObjStateSP(), the TCOM object archive server is used to create an object archive for writing, which is accessed via the interface ITComArchiveOp. This interface provides overloads from operator<<() in order to write them in the archive.

The interface used here was not developed for the real-time context, therefore the interface can only be used in the non-real-time context.