From 2bec9c838d2d688025698de8ec1de401ffd7dd1f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 11 八月 2020 14:13:55 +0800
Subject: [PATCH] 20200811

---
 HDL_ON/DriverLayer/Control_Bus.cs |   55 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control_Bus.cs b/HDL_ON/DriverLayer/Control_Bus.cs
index 472b644..e4eadf7 100644
--- a/HDL_ON/DriverLayer/Control_Bus.cs
+++ b/HDL_ON/DriverLayer/Control_Bus.cs
@@ -15,6 +15,10 @@
     public partial class Control
     {
         public DateTime LatestDateTime = DateTime.Now;
+        /// <summary>
+        /// 鎺у埗澶辫触娆℃暟
+        /// </summary>
+        public static int controlLostCount = 0;
 
         /// <summary>
         /// 鎵�鏈夊井淇″涓�绔彛鐨勬帶鍒堕兘浼氭斁鍒拌繖涓泦鍚堥噷
@@ -45,6 +49,8 @@
             return control.UsefulBytes;
         }
 
+        static DAL.Net.TcpListener tcpListener;
+
         /// <summary>
         /// 000E 鎼滅储鍥炲
         /// </summary>
@@ -59,6 +65,11 @@
                     return;
                 }
 
+                if (tcpListener == null)
+                {
+                    tcpListener = new DAL.Net.TcpListener();
+                    tcpListener.OpenServer(8586);
+                }
 
                 if (!CommonPage.isHttpListenerStart)
                 {
@@ -339,14 +350,14 @@
                     //case Command.ReadWirelessPanelButtonKeyACK:
                     //case Command.WriteWirelessPanelButtonKeyACK:
                     //case Command.ReadDryContactStatusACK:
-                    //case Command.InstructionPanelKeyACK:
-                    //case Command.ReadInstructionPanelKeyACK:
-                    //case Command.ReadAnalogValueACK:
-                    //case Command.ReadSensorTargetRemarkACK:
-                    //case Command.SetHornTargetStateACK:
-                    //case Command.ReadHornTargetStateACK:
-                    //    receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
-                    //    break;
+                    case Command.InstructionPanelKeyACK:
+                    case Command.ReadInstructionPanelKeyACK:
+                        //case Command.ReadAnalogValueACK:
+                        //case Command.ReadSensorTargetRemarkACK:
+                        //case Command.SetHornTargetStateACK:
+                        //case Command.ReadHornTargetStateACK:
+                        receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
+                        break;
                     //case Command.AssignedAddressACK:
                     //case Command.UpdataCurtainModelRunTimeACK:
                     //case Command.ReadCurtainStutasACK:
@@ -502,6 +513,19 @@
              鈥�            }
             else
             {
+                //Bus socket鏃犳硶鎺у埗锛岄噸鍚満鍒�
+                if (controlLostCount > 10)
+                {
+                    BusSocket.Stop();
+                    new System.Threading.Thread(() =>
+                    {
+                        System.Threading.Thread.Sleep(1000);
+                        BusSocket.Start(6000);
+                        controlLostCount = 0;
+                    })
+                    { IsBackground = true }.Start();
+                }
+
                 try
                 {
                     MainPage.Log("鍙戦�佹暟鎹�:" + SendFlag);
@@ -511,10 +535,11 @@
                     //杩欓噷鏄噸鍙戜袱娆�
                     while (Packet.HaveSendCount < 3)
                     {
-                        if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= System.DateTime.Now.Ticks)
+                        if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
                         {
                             MainPage.Log("閲嶅彂鏁版嵁:" + SendFlag);
                             BusSocket.AsyncBeginSend(Packet);
+                            controlLostCount++;
                         }
                         System.Threading.Thread.Sleep(100);
                     }
@@ -696,12 +721,12 @@
                 //case Command.SetCurtainModelStutas:
                 //case Command.DownloadInfrared:
                 //case Command.UpLoadInfrared:
-                //case Command.InstructionPanelKey:
-                //case Command.ReadInstructionPanelKey:
-                //case Command.ReadSensorTargetRemark:
-                //case Command.SetHornTargetState:
-                //    this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
-                //    break;
+                case Command.InstructionPanelKey:
+                case Command.ReadInstructionPanelKey:
+                    //case Command.ReadSensorTargetRemark:
+                    //case Command.SetHornTargetState:
+                    this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
+                    break;
                 //case Command.AssignedAddress:
                 //case Command.UpdataCurtainModelRunTime:
                 //case Command.ReadCurtainStatus:

--
Gitblit v1.8.0