public void InsertDtccode9() { MyMeans.AccessLink(); #region 插入DTC数据库 string title = "#" + _9DTCID + " " + C9dtcname + " " + C9BackTDCnumcode + " " + _C9Sactive + "\\" + _C9Tested; MyMeans.InsertDTC(title, C9S_Descrition_English, "", "", "", C9S_Descrition_Chinese); MyMeans.InsertDTC("", "Symptom", "", "", "", ""); MyMeans.InsertDTC("", "First", FirstStatuValue, "", "", ""); MyMeans.InsertDTC("", "Current", CurrentStatuValue, "", "", ""); MyMeans.InsertDTC("", "All", AllsStatuValue, "", "", ""); MyMeans.InsertDTC("", "Frequency counter", "", _C9s_Frequency_counter.ToString(), "", "发生频率"); MyMeans.InsertDTC("", "Error delete counter", "", "40", "", "完成测试数 (DLC)"); MyMeans.InsertDTC("", "Status", "", "", "", ""); MyMeans.InsertDTC("", "", "Debounce completed", Debounce_completed, "", ""); MyMeans.InsertDTC("", "", "Visible to OBD tool", Visible_to_OBD_tool, "", ""); MyMeans.InsertDTC("", "", "MIL lamp on", MIL_lamp_on, "", ""); MyMeans.InsertDTC("", "", "MIL lamp is blinking", MIL_lamp_is_blinking, "", ""); MyMeans.InsertDTC("", "", "System lamp on", System_lamp, "", ""); MyMeans.InsertDTC("", "Time since first appearance ", "", Time_since_first_appearance.ToString(), "", ""); MyMeans.InsertDTC("", "Active time", "", Active_Time.ToString(), "", ""); MyMeans.InsertDTC("", "Raw values:", C9_Value, "", "", ""); #endregion MyMeans.AccessBreak(); }
/// <summary> /// read dtc code /// </summary> public static void ReadECU13DTC() { CommonCmd.SendATE1(); GobalSerialPort.ClearSendAndRecive(); try { byte[] stringToalldtccodeA = StringToSendBytes.bytesToSend("1800FF00\n"); //发送命令的一个转化 GobalSerialPort.WriteByMessage(stringToalldtccodeA, 0, stringToalldtccodeA.Length); StringOfGets = GobalSerialPort.ResultBackString; string[] splitstring = StringOfGets.Split('\r'); if (splitstring[1] != null && (!splitstring[1].Contains("NO"))) { string result = splitstring[1]; string ss = result; ss = result.Replace(" ", ""); //这里是将空格改为空的字符串,但是还有其他的方法 string sub = ss.Substring(2, 2); string subtostr = sub.ToString(); int subtoint = Convert.ToInt32(subtostr, 16); //subint 是表示有多少个故障代码 string[] strsubtring = new string[subtoint]; //strsubtring 表示要开辟多少个字符串数组 ECU13DTC = new string[subtoint]; int[] strsubtint = new int[subtoint]; Console.WriteLine(subtoint); byte[][] C13DTwrite = new byte[subtoint][]; Save13BackDTC = new string[subtoint]; C13BackTDNumCode = new string[subtoint]; for (int i = 0; i < subtoint; i++) { C13DTwrite[i] = new byte[8]; } //初始化数据 SingleDtcFunction singleDtcFunction = new SingleDtcFunction(); MyMeans.DropDTC(); //清除原先数据 MyMeans.AccessLink(); int x = 4; for (int i = 0; i < subtoint; i++) { strsubtring[i] = ss.Substring(x, 6); x = x + 6; strsubtring[i] = strsubtring[i].Substring(0, 4); C13BackTDNumCode[i] = strsubtring[i]; int TheoneString = Convert.ToInt32(strsubtring[i].Substring(0, 1), 16); int _16TheoneString = int.Parse(TheoneString.ToString("X"), System.Globalization.NumberStyles.HexNumber); string ThethreeString = strsubtring[i].Substring(1, 3); //将前面的一个数据去掉前面的两位 string SUBba = Convert.ToString(_16TheoneString, 2).PadLeft(4, '0'); string C = SUBba.Substring(2, 2); string D = "00" + C; string Fianba = (Convert.ToInt32("00" + C)).ToString("X"); string Fianba1 = Convert.ToInt32(D, 2).ToString(); strsubtring[i] = Fianba1 + ThethreeString; ECU13DTC[i] = strsubtring[i]; ECU13DTCSingle = strsubtring[i]; strsubtring[i] = "17" + strsubtring[i]; C13DTwrite[i] = StringToSendBytes.bytesToSend(strsubtring[i] + "\n"); try { GobalSerialPort.WriteByMessage(C13DTwrite[i], 0, C13DTwrite[0].Length); StringOfGets = GobalSerialPort.ResultBackString; Save13BackDTC[i] = StringOfGets; Save13BackDTCSingle = StringOfGets; //Date int count = i + 1; singleDtcFunction.ShowDtcCodeF(count); } catch (Exception e) { log.Info("the error fo message is :" + e.Message); continue; } } MainF.ShowBoxTex("读取故障完毕"); MyMeans.AccessBreak(); SaveFileFunction.Dtc_SaveExcel(); } } catch (Exception e) { SaveFileFunction.Dtc_SaveExcel(); log.Info("Dtc final error :" + e.Message); } }