Exemple #1
0
        private void ReadFreezeFrameData()
        {
            while (true)
            {
                this.BeginInvoke(new Action(() => {
                    freezeFrame.Reset();
                }));
                OBDParameter parameter = m_obdInterface.LookupParameter("SAE.FF_DTC");
                if (parameter == null)
                {
                    MessageBox.Show(
                        "加载SAE.FF_DTC参数时发生错误",
                        "出错",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand
                        );
                    break;
                }

                OBDParameterValue value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (value.ErrorDetected)
                {
                    m_obdInterface.GetLogger().TraceError("Error while requesting SAE.FF_DTC");
                    MessageBox.Show(
                        "请求SAE.FF_DTC命令时发生错误",
                        "出错",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand
                        );
                    break;
                }

                if (string.Compare(value.StringValue, "P0000") == 0)
                {
                    MessageBox.Show(
                        string.Format("在 #{0} 帧中,没有发现冻结帧信息", m_FrameNumber),
                        "信息",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Asterisk
                        );
                    break;
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Value = 0;
                    freezeFrame.DTC   = value.StringValue;
                }));

                parameter = m_obdInterface.LookupParameter("SAE.FUEL1_STATUS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.FuelSystem1Status = value.StringValue;
                    }));
                }

                parameter = m_obdInterface.LookupParameter("SAE.FUEL2_STATUS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.FuelSystem2Status = value.StringValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LOAD_CALC");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.CalculatedLoad = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.ECT");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.EngineCoolantTemp = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT1");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.STFT1 = value.DoubleValue;
                    }));
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT3");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.STFT3 = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT1");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.LTFT1 = value.DoubleValue;
                    }));
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT3");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.LTFT3 = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT2");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.STFT2 = value.DoubleValue;
                    }));
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT4");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.STFT4 = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT2");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.LTFT2 = value.DoubleValue;
                    }));
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT4");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.LTFT4 = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.MAP");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.IntakePressure = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.RPM");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.EngineRPM = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.VSS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.VehicleSpeed = value.DoubleValue;
                    }));
                }

                this.BeginInvoke(new Action(() => {
                    progressBar.Increment(progressBar.Step);
                }));
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.SPARKADV");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.GetValue(parameter.GetFreezeFrameCopy(m_FrameNumber));
                if (!value.ErrorDetected)
                {
                    this.BeginInvoke(new Action(() => {
                        freezeFrame.SparkAdvance = value.DoubleValue;
                    }));
                }

                break;
            }
            this.BeginInvoke(new Action(() => {
                progressBar.Value  = progressBar.Maximum;
                btnRefresh.Enabled = true;
                btnCancel.Enabled  = false;
            }));
        }
        private void CollectData()
        {
            DisplayStatusMessage("请求MIL状态和故障码数量");
            DisplayRequest("0101");
            OBDParameterValue value5 = m_obdInterface.GetValue("SAE.MIL");

            this.BeginInvoke((EventHandler) delegate {
                progressBar.Value += 1;
            });
            if (!value5.ErrorDetected)
            {
                if (value5.BoolValue)
                {
                    DisplayDetailMessage("MIL状态: On");
                    m_bReportForm.ReportPage1.MilStatus = true;
                }
                else
                {
                    DisplayDetailMessage("MIL状态: Off");
                    m_bReportForm.ReportPage1.MilStatus = false;
                }
            }
            OBDParameterValue value3 = m_obdInterface.GetValue("SAE.DTC_COUNT");

            this.BeginInvoke((EventHandler) delegate {
                progressBar.Value += 1;
            });
            if (!value3.ErrorDetected)
            {
                m_bReportForm.ReportPage1.TotalCodes = (int)value3.DoubleValue;
                DisplayDetailMessage("存储的故障码数量: " + value3.DoubleValue.ToString());
            }
            DisplayStatusMessage("请求存储的故障码列表");
            OBDParameterValue value4 = m_obdInterface.GetValue("SAE.STORED_DTCS");

            this.BeginInvoke((EventHandler) delegate {
                progressBar.Value += 1;
            });
            if (!value4.ErrorDetected)
            {
                m_bReportForm.ReportPage1.DTCList.Clear();
                foreach (string strVal in value4.ListStringValue)
                {
                    m_bReportForm.ReportPage1.DTCList.Add(strVal);
                    DisplayDetailMessage("存储的故障码: " + strVal);
                    DTC dtc2 = m_obdInterface.GetDTC(strVal);
                    if (dtc2 != null)
                    {
                        m_bReportForm.ReportPage1.DTCDefinitionList.Add(dtc2.Description);
                    }
                }
            }
            DisplayStatusMessage("请求未决故障码列表");
            OBDParameterValue value2 = m_obdInterface.GetValue("SAE.PENDING_DTCS");

            this.BeginInvoke((EventHandler) delegate {
                progressBar.Value += 1;
            });
            if (!value2.ErrorDetected)
            {
                m_bReportForm.ReportPage1.PendingList.Clear();
                foreach (string strVal in value2.ListStringValue)
                {
                    m_bReportForm.ReportPage1.PendingList.Add(strVal);
                    DisplayDetailMessage("未决故障码: " + strVal);
                    DTC dtc = m_obdInterface.GetDTC(strVal);
                    if (dtc != null)
                    {
                        m_bReportForm.ReportPage1.PendingDefinitionList.Add(dtc.Description);
                    }
                }
            }

            DisplayStatusMessage("检查冻结帧数据");
            OBDParameter parameter = m_obdInterface.LookupParameter("SAE.FF_DTC");

            if (parameter != null)
            {
                OBDParameter freezeFrameCopy = parameter.GetFreezeFrameCopy(0);
                value2 = m_obdInterface.GetValue(freezeFrameCopy);
                this.BeginInvoke((EventHandler) delegate {
                    progressBar.Value += 1;
                });
                if (!value2.ErrorDetected)
                {
                    m_bReportForm.ReportPage1.FreezeFrameDTC = value2.StringValue;
                    DisplayDetailMessage("找到冻结帧数据 " + value2.StringValue);
                    CollectFreezeFrameData();
                }
                else
                {
                    m_bReportForm.ReportPage1.FreezeFrameDTC = "P0000";
                    DisplayDetailMessage("未找到冻结帧数据");
                }
                CollectMonitoringTestData();
                this.BeginInvoke((EventHandler) delegate {
                    progressBar.Value   = progressBar.Maximum;
                    btnGenerate.Enabled = true;
                    // ReportForm窗体类里需要调用SaveFileDialog.ShowDialog()
                    // 该方法需要调用COM对象(系统中的打开文件通用对话框),故需要调用者线程具有STA模式(单线程单元模式)
                    // 而Task无法显式设置线程模式为STA,故只能在主UI线程里调用ReportForm窗体类
                    m_bReportForm.ShowDialog();
                });
            }
        }