Beispiel #1
0
 private void ConnectThreadNew()
 {
     ShowConnectingLabel();
     if (m_obdInterface.CommSettings.AutoDetect)
     {
         if (m_obdInterface.InitDeviceAuto())
         {
             m_obdInterface.GetLogger().TraceInfo("Connection Established!");
             ShowConnectedLabel();
         }
         else
         {
             m_obdInterface.GetLogger().TraceWarning("Failed to find a compatible OBD-II interface.");
             MessageBox.Show("无法找到与本机相连的兼容的OBD-II硬件设备。\r\n请确认没有其他软件正在使用所需端口。", "自动探测失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             ShowDisconnectedLabel();
             m_obdInterface.Disconnect();
         }
     }
     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.GetLogger().TraceInfo("Connection Established!");
             ShowConnectedLabel();
         }
         else
         {
             m_obdInterface.GetLogger().TraceWarning("Failed to find a compatible OBD-II interface.");
             MessageBox.Show(
                 string.Format("在 \"端口:{0},波特率:{1}\" 通讯设置下,无法找到兼容的OBD-II协议设备。\r\n请确认没有其他软件正在使用所需端口且波特率设置正确。",
                               m_obdInterface.CommSettings.ComPortName,
                               m_obdInterface.CommSettings.BaudRate
                               ),
                 "连接失败",
                 MessageBoxButtons.OK,
                 MessageBoxIcon.Exclamation
                 );
             ShowDisconnectedLabel();
             m_obdInterface.Disconnect();
         }
     }
 }