protected override void OnStartup(StartupEventArgs e) { try { SerialPortAccess.StartCOMPort(); } catch (Exception error) { MessageBox.Show("WARNING! Serial Connection could not be established." + '\n' + error); } base.OnStartup(e); }
private void TryConnectSerialPort(object parameter) { try { if (!SerialPortAccess.SerialIsOpen) { SerialPortAccess.StartCOMPort(); SerialPortConnected = true; MessageBox.Show("Connection Successful", "COM Connection", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Serial Port is already open", "COM Connection", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception e) { MessageBox.Show("Could not connect COM port", "COM Connection", MessageBoxButton.OK, MessageBoxImage.Error); } }
protected override void OnExit(ExitEventArgs e) { SerialPortAccess.CloseCOMPort(); base.OnExit(e); }