public void ReadCodes() { m_ListDTC.Clear(); m_ListPending.Clear(); m_ListPermanent.Clear(); OBDParameterValue value; value = m_obdInterface.GetValue("SAE.MIL"); if (!value.ErrorDetected) { SetMilStatus(value.BoolValue); } value = m_obdInterface.GetValue("SAE.DTC_COUNT"); if (!value.ErrorDetected) { SetDTCTotal((int)value.DoubleValue); } value = m_obdInterface.GetValue("SAE.STORED_DTCS"); if (!value.ErrorDetected) { foreach (string dtc in value.ListStringValue) { m_ListDTC.Add(m_obdInterface.GetDTC(dtc)); } } value = m_obdInterface.GetValue("SAE.PENDING_DTCS"); if (!value.ErrorDetected) { foreach (string dtc in value.ListStringValue) { m_ListPending.Add(m_obdInterface.GetDTC(dtc)); } } value = m_obdInterface.GetValue("SAE.PERMANENT_DTCS"); if (!value.ErrorDetected) { foreach (string dtc in value.ListStringValue) { m_ListPermanent.Add(m_obdInterface.GetDTC(dtc)); } } }
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(); }); } }