From 611786df5108dca0bdcff03834cc285cba4b8e61 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 13 十月 2020 16:48:43 +0800
Subject: [PATCH] 2020-10-13-1

---
 HDL_ON/DriverLayer/Packet.cs |   64 +++++++++++++++++---------------
 1 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/HDL_ON/DriverLayer/Packet.cs b/HDL_ON/DriverLayer/Packet.cs
index 06b29b2..1d59954 100644
--- a/HDL_ON/DriverLayer/Packet.cs
+++ b/HDL_ON/DriverLayer/Packet.cs
@@ -62,41 +62,42 @@
             }
             else
             {
-                //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
-                if (!"HDLMIRACLE".Equals(System.Text.Encoding.ASCII.GetString(Bytes, 4, 10)))
+                try
                 {
-                    return;
-                }
+                    //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
+                    if (!"HDLMIRACLE".Equals(System.Text.Encoding.ASCII.GetString(Bytes, 4, 10)))
+                    {
+                        return;
+                    }
 
-                byte subnetID = this.Bytes[17]; //婧愬瓙缃戝彿
-                byte deviceID = this.Bytes[18]; //婧愯澶囧彿
+                    byte subnetID = this.Bytes[17]; //婧愬瓙缃戝彿
+                    byte deviceID = this.Bytes[18]; //婧愯澶囧彿
 
-                //婧愯澶囩被鍨�
-                int deviceType = this.Bytes[19] * 256 + this.Bytes[20];
+                    //婧愯澶囩被鍨�
+                    int deviceType = this.Bytes[19] * 256 + this.Bytes[20];
 
-                Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //鎿嶄綔鐮佹帶鍒跺懡浠�
+                    Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //鎿嶄綔鐮佹帶鍒跺懡浠�
 
-                byte targetSubnetID = this.Bytes[23];
-                byte targetDeviceID = this.Bytes[24];
+                    byte targetSubnetID = this.Bytes[23];
+                    byte targetDeviceID = this.Bytes[24];
 
-                //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
-                if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
-                {
-                    return;
-                }
-                byte[] usefulBytes = null;
-                if (this.Bytes[16] == 0xFF)
-                {
-                    usefulBytes = new byte[Bytes.Length - 16 - 11];
-                    System.Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length);
-                }
-                else
-                {
-                    //鏈夌敤鐨勯檮鍔犳暟鎹�
-                    usefulBytes = new byte[this.Bytes[16] - 11];
-                    Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length);
-
-
+                    //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
+                    if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
+                    {
+                        return;
+                    }
+                    byte[] usefulBytes = null;
+                    if (this.Bytes[16] == 0xFF)
+                    {
+                        usefulBytes = new byte[Bytes.Length - 16 - 11];
+                        System.Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length);
+                    }
+                    else
+                    {
+                        //鏈夌敤鐨勯檮鍔犳暟鎹�
+                        usefulBytes = new byte[this.Bytes[16] - 11];
+                        Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length);
+                    }
 
                     if (ReceiveEvent != null)
                     {
@@ -117,7 +118,10 @@
                     }
                     //澶勭悊鏄惁瑕侀噸鍙戞暟鎹�
                     Control.ManagerReceive(subnetID, deviceID, command, targetSubnetID, targetDeviceID, usefulBytes, RemoteEndPoint);
-
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log($"packet {ex.Message} ");
                 }
             }
         }

--
Gitblit v1.8.0