Closing the sample
When you press X to exit the sample, PowerAxis is called to disable all the axes. Since each axis needs some time to be disabled, we use WaitForCommand to give each 5 seconds.
Next, Stop is called, which stops the EtherCAT network and the KINGSTAR Subsystem. WaitForCommand is used to give 2 seconds for Stop to do its work.
Finally, Destroy closes the link to the KINGSTAR Subsystem and terminates the Subsystem.
ksWorker::~ksWorker()
{
for (int i = 0; i < maSts.AxesCount; i++)
{
KsCommandStatus Command = { 0 };
Command = WaitForCommand(5, FALSE, PowerAxis(i, FALSE, FALSE, FALSE));
}
WaitForCommand(2, FALSE, Stop());
Destroy();
}