// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Universal Robot connection handler /// <summary>Opens a window showing the error.</summary> /// <param name="error">Error message.</param> private void ConnectionLostUR(string error) { Dispatcher.BeginInvoke((Action) delegate { if (progDialog != null) { if (progDialog.IsActive) { progDialog.Close(); // If the progressbar is active from a previous attempt it will be closed progDialog = null; } } if (infoDlg == null) { infoDlg = new InfoAndErrorWindow("Fejlmeddelelse", error, "Forsøg igen", "Annuller"); infoDlg.OnDialogFinished -= infoDlg_DialogFinished; infoDlg.OnDialogFinished += infoDlg_DialogFinished; infoDlg.OnDialogFinished -= handleUR; infoDlg.OnDialogFinished += handleUR; infoDlg.Owner = this; infoDlg.ShowDialog(); } }); }
/// <summary>Presents the result of the configuration for the user.</summary> /// <param name="result">Result of the process.</param> private void ConfigCompleted(bool result) { Dispatcher.BeginInvoke((Action)async delegate { progDialog.Close(); progDialog = null; if (result) // Show a message that the process was successful { lb_configConfirmation.Content = "Indstillingerne er gemt"; lb_configConfirmation.Visibility = System.Windows.Visibility.Visible; lb_configConfirmation.Foreground = Brushes.Green; } else { // Open a window for the user to try again if (infoDlg == null) { infoDlg = new InfoAndErrorWindow("Fejlmeddelelse", "Indstillingerne kunne ikke gemmes", "Forsøg igen", "Annuller"); infoDlg.OnDialogFinished += infoDlg_DialogFinished; infoDlg.OnDialogFinished -= handleConfig; infoDlg.OnDialogFinished += handleConfig; infoDlg.Owner = this; infoDlg.ShowDialog(); } } await Task.Delay(2000); lb_configConfirmation.Visibility = System.Windows.Visibility.Hidden; // Hide the message again }); }
/// <summary>Opens a window showing the error, when the robot is in the wrong mode for movement.</summary> /// <param name="error">Error message.</param> private void URNotRunning(string error) { Dispatcher.BeginInvoke((Action) delegate { if (infoDlg == null) { infoDlg = new InfoAndErrorWindow("Fejlmeddelelse", error, "Luk program"); infoDlg.OnDialogFinished -= infoDlg_DialogFinished; infoDlg.OnDialogFinished += infoDlg_DialogFinished; infoDlg.OnDialogFinished -= handleURNOTRUNNING; infoDlg.OnDialogFinished += handleURNOTRUNNING; infoDlg.Owner = this; infoDlg.Show(); Thread NotRunning = new Thread(() => // Wait until the robots modes fulfill the right conditions { while (true) { if (connection.robotMode == "ROBOT_MODE_RUNNING" && connection.safetyMode == "SAFETY_MODE_NORMAL") { break; } } Dispatcher.BeginInvoke((Action) delegate { infoDlg.Close(); infoDlg = null; }); }); NotRunning.IsBackground = true; NotRunning.Start(); } }); }
/// <summary>Handles the respons from the user.</summary> private void handleConnection(object sender, string e) { Dispatcher.BeginInvoke((Action) delegate { if (e == "Ok") // If the user confirms the establishment a progressbar is presented and a establish connection process is initialized { progDialog = new ProgressDialog("Forbinder..."); progDialog.Owner = this; this.IsEnabled = false; progDialog.Show(); Logic.OnException -= new Logic.LogicExceptionEventHandler(ShowException); Logic.OnException += new Logic.LogicExceptionEventHandler(ShowException); Connection.OnConnectionCompleted -= new Connection.ConnectionCompletedEventHandler(ConnectionCompleted); Connection.OnConnectionCompleted += new Connection.ConnectionCompletedEventHandler(ConnectionCompleted); Thread connThread = new Thread(() => // Calls the establish connection in a thread so the progressbar isnt blocked { logic.EstablishConnection(); }); connThread.IsBackground = true; connThread.Start(); } else if (e == "Annuller") // The user cancels the establishment and the window is closed { infoDlg.Close(); infoDlg = null; this.IsEnabled = true; } }); }
/// <summary>Opens a new window to show the error message to the user.</summary> private void ShowException(string error, string source) { Dispatcher.BeginInvoke((Action) delegate { infoDlg = new InfoAndErrorWindow("Fejlmeddelelse", error, "OK"); infoDlg.OnDialogFinished -= infoDlg_DialogFinished; infoDlg.OnDialogFinished += infoDlg_DialogFinished; infoDlg.Owner = this; infoDlg.ShowDialog(); }); }
/// <summary>Establish connection event. Opens a window for the user to confirm the establishment.</summary> private void btn_establishConnection_Click(object sender, RoutedEventArgs e) { if (infoDlg == null) { infoDlg = new InfoAndErrorWindow("Bekræftigelse", "Vil du oprette forbindelse til " + lb_units.SelectedItem.ToString() + "?", "Ok", "Annuller"); infoDlg.OnDialogFinished -= handleConnection; infoDlg.OnDialogFinished += handleConnection; infoDlg.Owner = this; infoDlg.ShowDialog(); } }
/// <summary>Opens a window showing the error.</summary> /// <param name="error">Error message.</param> private void ConnectionLostVF(string error) { Dispatcher.BeginInvoke((Action) delegate { if (infoDlg == null) { infoDlg = new InfoAndErrorWindow("Fejlmeddelelse", error, "Forsøg igen", "Annuller"); infoDlg.OnDialogFinished -= infoDlg_DialogFinished; infoDlg.OnDialogFinished += infoDlg_DialogFinished; infoDlg.OnDialogFinished -= handleVF; infoDlg.OnDialogFinished += handleVF; infoDlg.Owner = this; infoDlg.ShowDialog(); } }); }
/// <summary>Opens the MainWindow if connection is successful.</summary> private void ConnectionCompleted(bool result) { Dispatcher.BeginInvoke((Action) delegate { if (result) { Logic.OnException -= new Logic.LogicExceptionEventHandler(ShowException); // Remove the listener from this window to prevent duplicate MainWindow mainWin = new MainWindow(); mainWin.Show(); this.Close(); progDialog.Close(); infoDlg.Close(); infoDlg = null; } }); }
/// <summary>Open a new window to present the error to the user.</summary> /// <param name="error">Error message</param> /// <param name="source">Source of the error</param> private void ShowException(string error, string source) { Dispatcher.BeginInvoke((Action) delegate { if (infoDlg != null) { infoDlg.Close(); infoDlg = null; } progDialog.Close(); this.IsEnabled = true; if (errorDlg == null) { errorDlg = new InfoAndErrorWindow("Fejlmeddelelse", "Der kunne ikke oprettes forbindelse til " + source, "Ok"); errorDlg.OnDialogFinished -= infoDlg_Error_DialogFinished; errorDlg.OnDialogFinished += infoDlg_Error_DialogFinished; errorDlg.Owner = this; errorDlg.ShowDialog(); } }); }
/// <summary>DialogFinished event that closes the window.</summary> private void infoDlg_DialogFinished(object sender, string e) { InfoAndErrorWindow dlg = sender as InfoAndErrorWindow; dlg.Close(); }
/// <summary>DialogFinished event that closes the window.</summary> void infoDlg_DialogFinished(object sender, string e) { infoDlg.Close(); infoDlg = null; }
/// <summary>DialogFinished event that closes the window.</summary> void infoDlg_Error_DialogFinished(object sender, string e) { errorDlg.Close(); errorDlg = null; }