Exemplo n.º 1
0
        private void ConnectThreadNew(object state)
        {
            ShowConnectingLabel();
            if (m_OBDInterface.CommSettings.AutoDetect)
            {
                if (m_OBDInterface.initDeviceAuto())
                {
                    m_OBDInterface.logItem("Connection Established!");
                    ShowConnectedLabel();
                    OBDParameter param = new OBDParameter();
                    param.OBDRequest = "0902";
                    param.Service    = 9;
                    param.Parameter  = 2;
                    param.ValueTypes = 4;
                    m_OBDInterface.getValue(param, true);
                }
                else
                {
                    MessageBox.Show("ProScan failed to find a compatible OBD-II interface attached to this computer.\r\n\r\nPlease verify that no other application is currently using the required port.", "Auto Detection Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    m_OBDInterface.logItem("Failed to find a compatible OBD-II interface.");
                    ShowDisconnectedLabel();
                }
            }
            else
            {
                int baudRate = m_OBDInterface.CommSettings.BaudRate;
                int comPort  = m_OBDInterface.CommSettings.ComPort;
                if (m_OBDInterface.initDevice(
                        m_OBDInterface.CommSettings.HardwareIndex,
                        comPort,
                        baudRate,
                        m_OBDInterface.CommSettings.ProtocolIndex
                        ))
                {
                    m_OBDInterface.logItem("Connection Established!");
                    ShowConnectedLabel();
                }
                else
                {
                    MessageBox.Show(
                        string.Format(@"ProScan failed to find a compatible OBD-II interface attached to {0} at baud rate {1} bps.

Please verify that no other application is currently using the required port and that the baud rate is correct.",
                                      m_OBDInterface.CommSettings.ComPortName,
                                      m_OBDInterface.CommSettings.BaudRate
                                      ),
                        "Connection Failure",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation
                        );
                    m_OBDInterface.logItem("Failed to find a compatible OBD-II interface.");
                    ShowDisconnectedLabel();
                }
            }
        }