public override void Handle(MDB_BOARD board) { Thread.Sleep(1000); board.UpdateMessage = "Error detected during testing"; Thread.Sleep(1000); Debug.WriteLine("ERROR"); if (board.NucleoPort.IsOpen) { board.CloseSerialPort(); } board.State = new SQL_Update(); }
public override void Handle(MDB_BOARD board) { board.UpdateMessage = "Saving into database"; try { if (board.NucleoPort != null) { board.CloseSerialPort(); } board.InsertTestResult(); GoToNextState(board, true); } catch (Exception e) { GoToNextState(board, false); Debug.WriteLine("Database Error - Exception: " + e.Message); } }
private void Start_test_button_Click(object sender, RoutedEventArgs e) { if (!CheckIfFormComplete()) { MessageBox.Show("Please select all itens correctly", "Wrong Fields", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); SetStartButtonState(true); return; } MDB_Board = new MDB_BOARD(new Init_State()) { BoardOperator = operator_txtbox.Text, BoardWorkstation = combo_workStation.Text, SerialNumber = GetSerialNumber(), BoardErrorDescription = "No Errors" }; MDB_Board.ConnectToMysql(server, database, uid, password); //Check for a Valid DB Connection - Error Exit Program if (!UpdateDBConnectionBox()) { MessageBox.Show("Error Connecting to Database", "Check Database configuration", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); SetStartButtonState(true); return; } //Check for a valid Serial Number or a Repeated One - Error Exit Program if (String.IsNullOrEmpty(MDB_Board.SerialNumber) || MDB_Board.CheckRepeatedTest()) { MessageBox.Show("Error In Serial Number", "Repeated Serial Number", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); SetStartButtonState(true); return; } //So far so good... ResetProgressBar(); //Assign Serial Communication Ports MDB_Board.RS232Port = SerialCom.SelectedItem.ToString(); MDB_Board.NucleoSerialCommunication(CurrentPort.SelectedItem.ToString()); //Validate Serial Ports - Error Exit Program if (!MDB_Board.CorrectPortConfig()) { MDB_Board.CloseSerialPort(); MessageBox.Show("Wrong Port Selection", "Wrong Fields", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); SetStartButtonState(true); return; } //Set Correct Power Supply MDB_Board.SetMDBSupply(); //Everything is Ok //Start Testing with scripts in a Thread try { MDB_Board.InitializeList(); test_list.ItemsSource = MDB_Board.list_itens; UpdateTextEvolution(Environment.NewLine + "---------------------------"); StartTimer(); Thread Test_Thread = new Thread(() => MDB_Board.StartTesting()); Test_Thread.Start(); } catch { SetStartButtonState(true); MessageBox.Show("Can't communicate with board" + Environment.NewLine + "Please check cable connection", "No communication with board", MessageBoxButton.OK, MessageBoxImage.Error); timer.Stop(); } }