Closing the sample
When you press X to exit the sample, ISubsystem.Destroy is called to close the link to the KINGSTAR Subsystem and terminate the Subsystem.
For a clean shutdown, the EtherCAT link should be stopped (ISubsystem.Stop) before the KINGSTAR Subsystem (ISubsystem.Destroy). Stopping the KINGSTAR Subsystem while the EtherCAT link is open may cause errors. We have already used Stop for the Disconnect button, so we use only Destroy for the closing method.
private async void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("This will destroy KINGSTAR subsystem. Continue?",
"KINGSTAR", MessageBoxButton.YesNo) == MessageBoxResult.No)
{
e.Cancel = true;
return;
}
try
{
await ViewModel.Subsystem.Destroy();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}