/// <summary>
        /// Initiates the connection process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnOk_Click(object sender, RoutedEventArgs e)
        {
            // Clear the port connection status list
            _portConnectionStatusList.Clear();
            _curPortConnectionStatus = null;

            // Get the correct Connector
            IConnector connector = _conFactory.GetConnector(SelectedConnector, ConstructConnectionSettings());

            // Hook into the connector's events
            connector.CheckingPort          += Connector_NextPort;
            connector.UpdateMessages        += Connector_UpdateMessage;
            connector.ConnectionComplete    += Connector_Complete;
            connector.ConnectionEstablished += Connector_ConnectionEstablished;
            connector.PortSuccess           += Connector_PortSuccess;

            // If this application is already connected on a SerialPort, close the connection
            if (ELM327Connection.Connection != null && ELM327Connection.Connection.IsOpen)
            {
                lblStatus.Content = "Closing existing ELM327 connection on port " + ELM327Connection.Connection.PortName + "...";
                log.Info("Closing existing ELM327 connection on port [" + ELM327Connection.Connection.PortName + "].");
                ELM327Connection.DestroyConnection();
            }

            // Log
            log.Info("Spawning thread for finding an Elm327 port and connecting.");

            // Disable Controls
            btnOk.IsEnabled       = false;
            cmbPortList.IsEnabled = false;
            btnCancel.Content     = "Cancel";

            // Start our Progress Bar
            pbProgressBar.IsIndeterminate = true;

            // Update the Status
            lblStatus.Content = "Connecting...";

            // Store a reference to the new IConnector
            _runningConnector = connector;

            // Spawn a thread
            _getSerialPortThread = new Thread(new ThreadStart(connector.GetSerialPort));
            _getSerialPortThread.SetApartmentState(ApartmentState.STA);
            _getSerialPortThread.Start();
        }
Esempio n. 2
0
 private void OnApplicationExit(object sender, ExitEventArgs e)
 {
     ApplicationSettings.Default.Save();
     ELM327Connection.DestroyConnection();
 }
Esempio n. 3
0
 /// <summary>
 /// Handles clean-up tasks before closing.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _mainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     // Alerts any running threads to exit.
     Variables.ShouldClose = true;
     ELM327Connection.DestroyConnection();
 }
Esempio n. 4
0
 /// <summary>
 /// Closes a connection to an ELM327.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FileMenu_Disconnect_Click(object sender, RoutedEventArgs e)
 {
     ELM327Connection.DestroyConnection();
 }