Example: Start-Stop
This sample shows the use of the TwinCAT 3 EventLogger when starting and stopping TwinCAT. A message is used with arguments that map the different states of the C++ module.
Download the sample: https://github.com/Beckhoff/Tc3Eventlogger_Samples/tree/main/C%2B%2B(RT)/Tc3EventLogger_CppStartStop_Sample
The message is used in the methods of the state machines:
- SetObjStatePS(): The EventLogger is being started by TwinCAT. Use in this state is thus impossible.
- SetObjStateSO(): Here, the reference to the EventLogger is procured through TcQuerySmartObjectInterface and the messages initiated by CreateMessage(). A corresponding message is dispatched. A message is dispatched with AddModuleToCaller(). A message is also dispatched here at the end of the transition.
- CycleUpdate(): in this example no messages are dispatched. The behavior of the module towards the OP state is thus equivalent to that of a "Cyclic IO" module.
- SetObjStateOS(): A message is dispatched with RemoveModuleFromCaller(). A message is also dispatched here at the end of the transition. Thereafter the references to the message and to the EventLogger are set to ZERO, which is also notified by means of a message.
- SetObjStatePS(): The EventLogger is shut down by TwinCAT. Use in this state is thus impossible.
The following messages result: