Beispiel #1
0
 public bool TryAnalysisReslut()
 {
     // 还没发送
     if (!IsSent)
     {
         return(false);
     }
     if ((DateTime.Now - SendTime).TotalMilliseconds > (Timeout != 0 ? Timeout : 3000))
     {
         if (CmdActions.ContainsKey(CmdKey))
         {
             ReadTime = DateTime.Now;
             Log.debug("告知" + CmdKey + "处理函数超时!");
             CmdActions[CmdKey](this);
         }
         return(true);
     }
     // 正确获得结果
     if (ResultString.StartsWith("TS->"))
     {
         ResultStringList.Add(ResultString);
         Log.shell(ResultString.Replace("\r", ""));
         ResultByte.Clear();
         IsRead = true;
         if (CmdActions.ContainsKey(CmdKey))
         {
             Log.debug("执行" + CmdKey + "的结果分析");
             CmdActions[CmdKey](this);
         }
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 public void SaveResult(byte ReadByte)
 {
     ResultByte.Add(ReadByte);
     if (RawCmdKey.Contains(CmdKey))
     {
         if (ReadByte <= 0x7f)
         {
             AsciiCount++;
         }
         else
         {
             AsciiCount = 0;
         }
         if (ReadByte == '\n' && AsciiCount >= 3 && AsciiCount == ResultByte.Count)
         {
             ResultStringList.Add(ResultString.Replace("\r", ""));
             Log.shell(ResultString.Replace("\r", ""));
             ResultByte.Clear();
             AsciiCount = 0;
         }
         else if (ResultString.EndsWith("TS->") && ResultByte.Count > 4)
         {
             ResultByteList.Add(ResultByte.Take(ResultByte.Count - 4).ToArray());
             ResultStringList.Add("RawData Saved\n");
             ResultByte.RemoveRange(0, ResultByte.Count - 4);
             Log.shell(ResultStringList.Last());
             AsciiCount = 0;
         }
     }
     else if (ReadByte == '\n')
     {
         ResultStringList.Add(ResultString);
         Log.shell(ResultString.Replace("\r", ""));
         ResultByte.Clear();
     }
     ReadTime = DateTime.Now;
 }