예제 #1
0
        /// <summary>
        /// 监测
        /// </summary>
        private void LinsenAutoSetCount()
        {
            while (true)
            {
                if (CommonAutoRest.AutoResetCount >= 3)
                {
                    GobalSerialPort.ClearSendAndRecive();

                    CommonAutoRest.MEvent.Set();
                }
            }
        }
예제 #2
0
 /// <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);
     }
 }