コード例 #1
0
        private void StartOBDTest()
        {
            if (!_obdTest.AdvanceMode)
            {
                return;
            }
            _obdIfEx.Log.TraceInfo("Start OBD test in advance mode");
            Invoke((EventHandler) delegate {
                labelInfo.ForeColor    = Color.Black;
                labelInfo.Text         = "准备OBD检测";
                labelMESInfo.ForeColor = Color.Black;
                labelMESInfo.Text      = "准备上传数据";
            });
            _obdIfEx.Log.TraceInfo(">>>>>>>>>> Start to test vehicle of VIN: " + _obdTest.StrVIN_IN + " <<<<<<<<<<");
            string errorMsg = "";

            try {
                _obdTest.StartOBDTest(out errorMsg);
            } catch (Exception ex) {
                _obdIfEx.Log.TraceError("OBD test occurred error: " + errorMsg + ", " + ex.Message);
                MessageBox.Show(ex.Message, "OBD检测出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Invoke((EventHandler) delegate {
                if (_obdTest.OBDResult)
                {
                    labelInfo.ForeColor = Color.ForestGreen;
                    labelInfo.Text      = "OBD检测结束,结果:合格";
                }
                else
                {
                    string strCat = "";
                    if (!_obdTest.DTCResult)
                    {
                        strCat += ",存在故障码DTC";
                    }
                    if (!_obdTest.ReadinessResult)
                    {
                        strCat += ",就绪状态未完成项超过2项";
                    }
                    if (!_obdTest.VINResult)
                    {
                        strCat += ",VIN号不匹配";
                    }
                    labelInfo.ForeColor = Color.Red;
                    labelInfo.Text      = "OBD检测结束,结果:不合格" + strCat;
                }
                txtBoxVIN.ReadOnly = false;
            });
            if (_obdTest.CALIDCVNAllEmpty)
            {
                MessageBox.Show("CALID和CVN均为空!请检查OBD线缆接头连接是否牢固。", "OBD检测出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (_ctsOBDTestStart != null)
            {
                _ctsOBDTestStart.Cancel();
            }
            if (_ctsSetupColumnsDone != null)
            {
                _ctsSetupColumnsDone.Cancel();
            }
            if (_ctsWriteDbStart != null)
            {
                _ctsWriteDbStart.Cancel();
            }
            if (_ctsUploadDataStart != null)
            {
                _ctsUploadDataStart.Cancel();
            }
        }
コード例 #2
0
        private void StartOBDTest()
        {
            if (!_obdTest.AdvancedMode)
            {
                return;
            }
            Dispatcher.Invoke(() => {
                txtBlkInfo.Foreground = SystemColors.ControlTextBrush;
                txtBlkInfo.Text       = "准备OBD检测";
            });
            _obdIfEx.Log.TraceInfo(string.Format(">>>>>>>>>> Start to test vehicle of [VIN: {0}, VehicleType: {1}] MainVersion: {2} <<<<<<<<<<",
                                                 _obdTest.StrVIN_IN, _obdTest.StrType_IN, MainFileVersion.AssemblyVersion));
            if (_obdIfEx.OBDIf.ConnectedStatus)
            {
                _obdIfEx.OBDIf.Disconnect();
            }
            CancellationTokenSource tokenSource = UpdateUITask("正在连接车辆");

            if (!_obdIfEx.OBDDll.ConnectOBD())
            {
                tokenSource.Cancel();
                Dispatcher.Invoke(() => {
                    txtBlkInfo.Foreground = new SolidColorBrush(Colors.Red);
                    txtBlkInfo.Text       = "连接车辆失败!";
                });
                return;
            }
            tokenSource.Cancel();

            string errorMsg = string.Empty;

            try {
                _obdTest.StartOBDTest(out errorMsg);
            } catch (Exception ex) {
                _obdIfEx.Log.TraceError("OBD test occurred error: " + errorMsg + ", " + ex.Message);
                HandyControl.Controls.MessageBox.Error(ex.Message, "OBD检测出错");
            }

            Dispatcher.Invoke(() => {
                if (_obdTest.OBDResult)
                {
                    txtBlkInfo.Foreground = new SolidColorBrush(Colors.ForestGreen);
                    txtBlkInfo.Text       = "OBD检测结束,结果:合格";
                }
                else
                {
                    string strCat = string.Empty;
                    if (!_obdTest.DTCResult)
                    {
                        strCat += ",存在DTC故障码";
                    }
                    if (!_obdTest.CALIDCVNResult)
                    {
                        strCat += ",CAL_ID或CVN数据异常";
                    }
                    if (!_obdTest.VINResult)
                    {
                        strCat += ",VIN号不匹配";
                    }
                    if (!_obdTest.VehicleTypeExist)
                    {
                        strCat += ",缺少车型数据";
                    }
                    if (!_obdTest.CALIDCheckResult)
                    {
                        strCat += ",CAL_ID校验不合格";
                    }
                    if (!_obdTest.CVNCheckResult)
                    {
                        strCat += ",CVN校验不合格";
                    }
                    txtBlkInfo.Foreground = new SolidColorBrush(Colors.Red);
                    txtBlkInfo.Text       = "OBD检测结束,结果:不合格" + strCat;
                }
                txtBoxVIN.IsEnabled         = true;
                txtBoxVehicleType.IsEnabled = true;
            });
            if (_ctsOBDTestStart != null)
            {
                _ctsOBDTestStart.Cancel();
            }
            if (_ctsSetupColumnsDone != null)
            {
                _ctsSetupColumnsDone.Cancel();
            }
            if (_ctsWriteDbStart != null)
            {
                _ctsWriteDbStart.Cancel();
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: qqj1228/SH_OBD_WPF
        private void StartOBDTest()
        {
            _bCanOBDTest = false;
            Dispatcher.Invoke(() => {
                txtBlkResult.Foreground   = SystemColors.ControlTextBrush;
                txtBlkResult.Text         = "准备OBD检测";
                bderVINErr.Background     = null;
                txtBlkVINErr.Foreground   = SystemColors.GrayTextBrush;
                bderCALIDCVN.Background   = null;
                txtBlkCALIDCVN.Foreground = SystemColors.GrayTextBrush;
                bderDTC.Background        = null;
                txtBlkDTC.Foreground      = SystemColors.GrayTextBrush;
            });
            _obdIfEx.Log.TraceInfo(string.Format(">>>>>>>>>> Start to test vehicle of [VIN: {0}, VehicleType: {1}] MainVersion: {2} <<<<<<<<<<",
                                                 _obdTest.StrVIN_IN, _obdTest.StrType_IN, MainFileVersion.AssemblyVersion));
            if (_obdIfEx.OBDIf.ConnectedStatus)
            {
                _obdIfEx.OBDIf.Disconnect();
            }
            CancellationTokenSource tokenSource = UpdateUITask("正在连接车辆");

            if (!_obdIfEx.OBDDll.ConnectOBD())
            {
                tokenSource.Cancel();
                Dispatcher.Invoke(() => {
                    txtBlkResult.Foreground = new SolidColorBrush(Colors.Red);
                    txtBlkResult.Text       = "连接车辆失败!";
                });
                _bCanOBDTest = true;
                return;
            }
            tokenSource.Cancel();

            string errorMsg = "";

            try {
                _obdTest.StartOBDTest(out errorMsg);
            } catch (Exception ex) {
                _obdIfEx.Log.TraceError("OBD test occurred error: " + errorMsg + ", " + ex.Message);
                HandyControl.Controls.MessageBox.Error(ex.Message + "\n" + errorMsg, "OBD检测出错");
            } finally {
                _obdTest.StrVIN_IN  = "";
                _obdTest.StrType_IN = "";
                if (_ctsOBDTestStart != null)
                {
                    _ctsOBDTestStart.Cancel();
                }
                if (_ctsSetupColumnsDone != null)
                {
                    _ctsSetupColumnsDone.Cancel();
                }
                if (_ctsWriteDbStart != null)
                {
                    _ctsWriteDbStart.Cancel();
                }
                _bCanOBDTest = true;
            }

            Dispatcher.Invoke(() => {
                if (_obdTest.OBDResult)
                {
                    txtBlkResult.Foreground = new SolidColorBrush(Colors.GreenYellow);
                    txtBlkResult.Text       = "OBD检测结果:合格";
                }
                else
                {
                    if (!_obdTest.VINResult)
                    {
                        bderVINErr.Background   = new SolidColorBrush(Colors.Red);
                        txtBlkVINErr.Foreground = SystemColors.ControlTextBrush;
                    }
                    if (!_obdTest.CALIDCVNResult)
                    {
                        bderCALIDCVN.Background   = new SolidColorBrush(Colors.Red);
                        txtBlkCALIDCVN.Foreground = SystemColors.ControlTextBrush;
                    }
                    if (!_obdTest.DTCResult)
                    {
                        bderDTC.Background   = new SolidColorBrush(Colors.Red);
                        txtBlkDTC.Foreground = SystemColors.ControlTextBrush;
                    }
                    txtBlkResult.Foreground = new SolidColorBrush(Colors.Red);
                    if (_obdTest.VehicleTypeExist && _obdTest.CALIDCheckResult && _obdTest.CVNCheckResult)
                    {
                        txtBlkResult.Text = "OBD检测结果:不合格";
                    }
                    else
                    {
                        bderCALIDCVN.Background   = new SolidColorBrush(Colors.Red);
                        txtBlkCALIDCVN.Foreground = SystemColors.ControlTextBrush;
                        txtBlkResult.Text         = "结果:";
                    }
                    if (!_obdTest.VehicleTypeExist)
                    {
                        txtBlkResult.Text += "缺少车型数据";
                    }
                    if (!_obdTest.CALIDCheckResult)
                    {
                        if (txtBlkResult.Text.Length > 3)
                        {
                            txtBlkResult.Text += ",";
                        }
                        txtBlkResult.Text += "CALID校验不合格";
                    }
                    if (!_obdTest.CVNCheckResult)
                    {
                        if (txtBlkResult.Text.Length > 3)
                        {
                            txtBlkResult.Text += ",";
                        }
                        txtBlkResult.Text += "CVN校验不合格";
                    }
                }
            });
        }
コード例 #4
0
        private void StartOBDTest()
        {
            this.Invoke((EventHandler) delegate {
                this.lblResult.ForeColor   = Color.Black;
                this.lblResult.Text        = "准备OBD检测";
                this.lblVINError.BackColor = _backColor;
                this.lblVINError.ForeColor = Color.Gray;
                this.lblCALIDCVN.BackColor = _backColor;
                this.lblCALIDCVN.ForeColor = Color.Gray;
                this.lblOBDSUP.BackColor   = _backColor;
                this.lblOBDSUP.ForeColor   = Color.Gray;
            });
            _obdIfEx.Log.TraceInfo(">>>>>>>>>> Start to test vehicle of VIN: " + _obdTest.StrVIN_IN + " MainVersion: " + MainFileVersion.AssemblyVersion + " <<<<<<<<<<");
            if (_obdIfEx.OBDIf.ConnectedStatus)
            {
                _obdIfEx.OBDIf.Disconnect();
            }
            this.Invoke((EventHandler) delegate {
                this.lblResult.ForeColor = Color.Black;
                this.lblResult.Text      = "正在连接车辆。。。";
            });
            CancellationTokenSource tokenSource = UpdateUITask("正在连接车辆");

            if (!_obdIfEx.OBDDll.ConnectOBD())
            {
                tokenSource.Cancel();
                this.Invoke((EventHandler) delegate {
                    this.lblResult.ForeColor = Color.Red;
                    this.lblResult.Text      = "连接车辆失败!";
                });
                _bCanOBDTest = true;
                return;
            }
            tokenSource.Cancel();

            string errorMsg       = "";
            bool   bNoTestRecord  = false;
            bool   bTestException = false;

            try {
                _obdTest.StartOBDTest(out errorMsg);

                // 江铃股份操作工反应会有少量车辆漏检,故加入二次检查被测车辆是否已经检测过
                Dictionary <string, string> whereDic = new Dictionary <string, string> {
                    { "VIN", _obdTest.StrVIN_ECU }
                };
                DataTable dt = new DataTable("OBDData");
                _obdTest.DbLocal.GetRecords(dt, whereDic);
                if (dt.Rows.Count <= 0)
                {
                    _obdIfEx.Log.TraceError("No test record of this vehicle: " + _obdTest.StrVIN_ECU);
                    _obdTest.OBDResult = false;
                    bNoTestRecord      = true;
                }
            } catch (Exception ex) {
                if (_obdTest.StrVIN_ECU == null || _obdTest.StrVIN_ECU.Length == 0)
                {
                    _obdTest.StrVIN_ECU = _obdTest.StrVIN_IN;
                }
                _obdIfEx.Log.TraceError("OBD test occurred error: " + ex.Message + (errorMsg.Length > 0 ? ", " + errorMsg : ""));
                bTestException = true;
                MessageBox.Show(ex.Message + (errorMsg.Length > 0 ? "\n" + errorMsg : ""), "OBD检测出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Invoke((EventHandler) delegate {
                if (_obdTest.OBDResult)
                {
                    this.lblResult.ForeColor = Color.GreenYellow;
                    this.lblResult.Text      = "被检车辆: " + _obdTest.StrVIN_ECU + "\nOBD检测结果:合格";
                    this.txtBoxVIN.Text      = "";
                }
                else
                {
                    if (!_obdTest.VINResult)
                    {
                        this.lblVINError.BackColor = Color.Red;
                        this.lblVINError.ForeColor = Color.Black;
                    }
                    if (!_obdTest.CALIDCVNResult || !_obdTest.CALIDUnmeaningResult)
                    {
                        this.lblCALIDCVN.BackColor = Color.Red;
                        this.lblCALIDCVN.ForeColor = Color.Black;
                    }
                    if (!_obdTest.OBDSUPResult)
                    {
                        this.lblOBDSUP.BackColor = Color.Red;
                        this.lblOBDSUP.ForeColor = Color.Black;
                    }

                    this.lblResult.ForeColor = Color.Red;
                    if (bNoTestRecord)
                    {
                        this.lblResult.Text = "被检车辆: " + _obdTest.StrVIN_ECU + "\n没有本地检测记录";
                    }
                    else if (bTestException)
                    {
                        this.lblResult.Text = "被检车辆: " + _obdTest.StrVIN_ECU + "\nOBD检测过程发生异常";
                    }
                    else
                    {
                        this.lblResult.Text = "被检车辆: " + _obdTest.StrVIN_ECU + "\nOBD检测结果:不合格";
                    }
                }
            });
            if (_obdTest.CALIDCVNAllEmpty)
            {
                MessageBox.Show("CALID和CVN均为空!请检查OBD线缆接头连接是否牢固。", "OBD检测出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            _obdTest.StrVIN_IN  = "";
            _obdTest.StrVIN_ECU = "";
            if (_ctsOBDTestStart != null)
            {
                _ctsOBDTestStart.Cancel();
            }
            if (_ctsSetupColumnsDone != null)
            {
                _ctsSetupColumnsDone.Cancel();
            }
            if (_ctsWriteDbStart != null)
            {
                _ctsWriteDbStart.Cancel();
            }
            if (_ctsUploadDataStart != null)
            {
                _ctsUploadDataStart.Cancel();
            }
            _bCanOBDTest = true;
        }