Browse Source

【模块名称】
串口与HTTP通信模块
【问题原因】
G客户查找DSN慢的原因,需要针对特定的GSN函数进行耗时计算并输出Log
【修改描述】
在关键函数添加Stopwatch计算函数业务耗时值。
【测试结果】

sat23 3 years ago
parent
commit
919384d8cc
2 changed files with 18 additions and 11 deletions
  1. 4 1
      SCBC Factory Tools/Business/CommonMethod.cs
  2. 14 10
      SCBC Factory Tools/IO/SerialCMD.cs

+ 4 - 1
SCBC Factory Tools/Business/CommonMethod.cs

@@ -1998,6 +1998,9 @@ namespace MOKA_Factory_Tools
 
 
         public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
         public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
         {
         {
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             dsn = "";
             dsn = "";
             error = "";
             error = "";
             HttpHelper http = new HttpHelper();
             HttpHelper http = new HttpHelper();
@@ -2017,7 +2020,7 @@ namespace MOKA_Factory_Tools
                 Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
                 Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
                 if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
                 if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
                 {
                 {
-                    Log.WriteGetKeyLog("\r\nDSN=" + dsn);
+                    Log.WriteGetKeyLog(string.Format("\r\nDSN= {0}\r\nHttp Get Dsn Elapsed = {1}", dsn, watch.Elapsed.TotalMilliseconds));
                     return true;
                     return true;
                 }
                 }
                 else
                 else

+ 14 - 10
SCBC Factory Tools/IO/SerialCMD.cs

@@ -7,6 +7,7 @@ using CrcTest;
 using System.Collections;
 using System.Collections;
 using System.Threading;
 using System.Threading;
 using SXLibrary;
 using SXLibrary;
+using System.Diagnostics;
 
 
 namespace MOKA_Factory_Tools
 namespace MOKA_Factory_Tools
 {
 {
@@ -1822,14 +1823,15 @@ namespace MOKA_Factory_Tools
         /// <returns></returns>
         /// <returns></returns>
         public static bool GetFireTVDevcieCode(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
         public static bool GetFireTVDevcieCode(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
         {
         {
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             if (Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0xEC }, new byte[] { 0x11,0x06 }, true, false, out result, out data, out error, waitTime))
             if (Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0xEC }, new byte[] { 0x11,0x06 }, true, false, out result, out data, out error, waitTime))
             {
             {
                 if (data[0] == 0x11 & data[1] == 0x06)
                 if (data[0] == 0x11 & data[1] == 0x06)
                 {
                 {
                     data = data.Skip(2).Take(data.Length - 2).ToArray();
                     data = data.Skip(2).Take(data.Length - 2).ToArray();
-                    if (data.Length == 3)
-                        return true;
-                    else
+                    if (data.Length != 3)
                     {
                     {
                         error = "返回DevcieCode长度错误,应为3 bytes";
                         error = "返回DevcieCode长度错误,应为3 bytes";
                         return false;
                         return false;
@@ -1840,11 +1842,11 @@ namespace MOKA_Factory_Tools
                     error = "返回DevcieCode类型错误,应为0x11 0x06";
                     error = "返回DevcieCode类型错误,应为0x11 0x06";
                     return false;
                     return false;
                 }
                 }
-
             }
             }
-            else
-                return false;
 
 
+            Log.WriteInfoLog(string.Format("GetDeviceCode Elapsed = {0}", watch.Elapsed.TotalMilliseconds));
+            
+            return true;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -2272,22 +2274,24 @@ namespace MOKA_Factory_Tools
         /// <returns></returns>
         /// <returns></returns>
         public static bool ReadFireTVPSN(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
         public static bool ReadFireTVPSN(SerialPort Comport, out byte[] result, out byte[] data, out string error, int waitTime)
         {
         {
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             if (Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0xFC }, new byte[] { 0x03, 0x05 }, true, false, out result, out data, out error, waitTime))
             if (Sendcmd(Comport, new byte[] { 0xAA }, new byte[] { 0xFC }, new byte[] { 0x03, 0x05 }, true, false, out result, out data, out error, waitTime))
             {
             {
                 if (data[0] == 0x04 && data[1] == 0x05)
                 if (data[0] == 0x04 && data[1] == 0x05)
                 {
                 {
                     data = data.Skip(2).Take(data.Length - 2).ToArray();
                     data = data.Skip(2).Take(data.Length - 2).ToArray();
+                    Log.WriteInfoLog(string.Format("Read PSN Elapsed={0}", watch.Elapsed.TotalMilliseconds));
                     return true;
                     return true;
                 }
                 }
                 else
                 else
                 {
                 {
                     error = "返回PSN类型错误,应为0x04 0x05";
                     error = "返回PSN类型错误,应为0x04 0x05";
-                    return false;
                 }
                 }
-
             }
             }
-            else
-                return false;
+            
+            return false;
         }
         }
 
 
         /// <summary>
         /// <summary>