Jelajahi Sumber

去除delay函数,同时在第二段重新设置ReadTimeout时间。

sat23 3 tahun lalu
induk
melakukan
e4cb4cdc3c
1 mengubah file dengan 29 tambahan dan 7 penghapusan
  1. 29 7
      SCBC Factory Tools/IO/SerialCMD.cs

+ 29 - 7
SCBC Factory Tools/IO/SerialCMD.cs

@@ -2520,7 +2520,31 @@ namespace MOKA_Factory_Tools
             return Sendcmd(Comport, new byte[] { 0xAA, 0xFE }, new byte[] { 0xFC, 0x00, 0x0A }, param, false, false, out result, out data, out error, waitTime);
         }
 
+        #region 波兰工厂临时功能-抄写所有Key后执行Trigger和Check指令;
+        public static bool TriggerDHA(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
+        {
+            return Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0x96, 0x03 }, new byte[]{ 0x00 }, false, false, out result, out data, out error, waitTime);
+        }
 
+        public static bool CheckDHA(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
+        {
+            if (Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0x9A }, new byte[] { 0x014 }, true, false, out result, out data, out error, waitTime))
+            {
+                if (data[0] == 0x14 && data[1] == 0x01)
+                {
+                    data = data.Skip(1).Take(data.Length - 1).ToArray();
+                    return true;
+                }
+                else
+                {
+                    error = "Check DHA失败,应为01";
+                }
+            }
+
+            return false;
+        }
+
+        #endregion
         /// <summary>
         /// 通讯逻辑
         /// </summary>
@@ -2572,13 +2596,14 @@ namespace MOKA_Factory_Tools
                 {
                     wdata= wdata.Concat(b).ToArray();                  
                 }
+                Comport.WriteTimeout = 3000;
                 Comport.Write(wdata, 0, wdata.Length);
                 s += SerialInit.ByteToHex(wdata);
                 Log.WriteInfoLog("Write:" + s);
                 bool mark = false;
                 // 设置读超时;
                 Comport.ReadTimeout = ReadTimeout;
-                // delay(Comport, CMDID);//已有ReadTimeout了,这里多余;
+                //delay(Comport, CMDID);//已有ReadTimeout了,这里多余;
                 // ReadTimeout对ReadByte生效的话,所有ReadByte都会有超时响应,如果异常存在会导致更长的延时?
                 while (true)
                 {
@@ -2640,7 +2665,8 @@ namespace MOKA_Factory_Tools
                     {
                         string Br = "";
                         string Sr = "";
-                        Comport.ReadTimeout = 500;
+                        // 分2段2次返回,第2次同样要再次设置超时值;
+                        Comport.ReadTimeout = ReadTimeout;
                         while (Comport.BytesToRead >= 0)
                         {
                             if (Comport.ReadByte() == ACKhead[0])
@@ -2723,13 +2749,9 @@ namespace MOKA_Factory_Tools
 
             while (Comport.BytesToRead < 5 && l < num)
             {
-                Thread.Sleep(150);
+                Thread.Sleep(SerialTimeout);
                 l++;
             }
-
-            Thread.Sleep(receive2 ? (SerialTimeout*50) : 50);
         }
     }
-
-
 }