Browse Source

重连PLC后刷新车位,号牌无论获取与否皆反馈1给PLC,netty重连最后一次尝试后关闭该连接,避免持续占用cpu资源

yc_t 6 years ago
parent
commit
009f4b4f10

BIN
NettyCommunication/nettyCommunication.dll


+ 14 - 0
PLCLinker/PLCConnector/App.config

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
+    </startup>
+  <appSettings>
+    <add key="plcIpAddress" value="192.168.10.60" />
+    <add key="plcRack" value="0" />
+    <add key="plcSlot" value="1" />
+    <add key="plcDatablockId" value="18,41,20" />
+    <!--日志写入地址配置文件-->
+    <add key="LogAddress" value="E:\superScene\智能停车项目\测试包\snap7\LoggerTest" />
+  </appSettings>
+</configuration>

+ 2 - 0
PLCLinker/centralController/FormCentralController.cs

@@ -462,6 +462,7 @@ namespace centralController
                 {
                     Monitor.Monitor.SetNotification("检测到PLC掉线,尝试重连", TextColor.Info);
                     Monitor.Monitor.PLC.PLCConnect();
+                    Monitor.Monitor.updateCount = true;
                 }
                 else
                 {
@@ -472,6 +473,7 @@ namespace centralController
                     Monitor.Monitor.SetNotification("尝试关闭并重新建立与PLC的连接", TextColor.Info);
                     Monitor.Monitor.PLC.PLCDisconnect();
                     Monitor.Monitor.PLC.PLCConnect();
+                    Monitor.Monitor.updateCount = true;
                     //}
                     //else
                     //{

+ 9 - 0
PLCLinker/centralController/Monitor/Monitor.cs

@@ -97,6 +97,10 @@ namespace Monitor
         /// </summary>
         public static object PLCReadLock = new object();
         /// <summary>
+        /// 是否初始化PLC数据更新次数的计数,重连PLC后初始化该值以刷新车位
+        /// </summary>
+        public static bool updateCount = false;
+        /// <summary>
         /// 将显示在界面的提示字符串
         /// </summary>
         private static Queue<string> notificationQueue = new Queue<string>();
@@ -109,6 +113,11 @@ namespace Monitor
             bool disconnected = false;
             while (!isClosing)
             {
+                if (updateCount)
+                {
+                    count = 0;
+                    updateCount = false;
+                }
                 if (count > 10000)
                     count = 11;
                 count++;

+ 6 - 3
PLCLinker/centralController/Terminal/Terminal.cs

@@ -382,7 +382,7 @@ namespace Terminal
                     }
                     else
                     {
-                        ts.licVerification = 2;//验证失败
+                        ts.licVerification = 1;//验证失败
                         Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
                         status = 2;
                         Log.WriteLog(LogType.process, LogFile.WARNING, "号牌验证失败");
@@ -548,7 +548,7 @@ namespace Terminal
                                 paymentStatus = -1,
                                 parkingFee = -1,
                                 userType = -1,
-                                licVerification = (short)2
+                                licVerification = (short)1
                             };
                             Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
                             Thread.Sleep(500);
@@ -594,7 +594,7 @@ namespace Terminal
                             }
                             if (term.btnStatus == (short)0)
                             {
-                                ts.licVerification = 2;
+                                ts.licVerification = 1;
                                 Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
                                 Log.WriteLog(LogType.process,LogFile.ERROR,"空按钮状态拍号牌");
                             }
@@ -661,6 +661,9 @@ namespace Terminal
                     {
                         if (!idLicMap.ContainsKey(currentTerm))
                         {
+                            Thread.Sleep(500);
+                            ClearTerminal(term.terminalID, false);
+                            ResetCompleteSignal();
                             Log.WriteLog(LogType.process, LogFile.ERROR, "停车结束时未找到号牌");
                         }
                         break;

+ 8 - 5
PLCLinker/centralController/WebServer/WebServer.cs

@@ -485,15 +485,15 @@ namespace centralController.WebServer
             Task.Factory.StartNew(() =>
             {
                 //初始化后与web持续连接
-                while (!isClosing)
-                {
+                //while (!isClosing)
+                //{
                     try
                     {
-                        Connections.close();
+                        //Connections.close();
                         Connections.Connection();
                         connected = true;
                         comm = new Communication();
-                        break;
+                        //break;
                     }
                     catch (Exception)
                     {
@@ -501,7 +501,7 @@ namespace centralController.WebServer
                         Console.WriteLine("服务没有开启,请检查服务器");
                     }
                     Thread.Sleep(2000);
-                }
+                //}
                 Connect();
             });
             //持续接收消息
@@ -618,7 +618,10 @@ namespace centralController.WebServer
                         if (count == 12 && connected)
                             Monitor.Monitor.SetNotification("web连接已断开", parkMonitor.model.TextColor.Warning);
                         else if (count == 0)
+                        {
+                            Connections.close();
                             break;
+                        }
                         connected = false;
                         count--;
                         try

BIN
PLCLinker/centralController/obj/Release/centralController.Properties.Resources.resources


+ 1 - 1
PLCLinker/centralController/obj/Release/centralController.csproj.CoreCompileInputs.cache

@@ -1 +1 @@
-87053e9854ba639958c40694ac0e08932cbc872e
+e2e18498797396c0c4d793777c2850f188bce73b

BIN
PLCLinker/centralController/obj/Release/centralController.csproj.GenerateResource.Cache


BIN
PLCLinker/centralController/sdk/dotNetty/nettyCommunication.dll


+ 1 - 1
PLCLinker/centralController/serversettings.json

@@ -1,7 +1,7 @@
 {
 
   "ssl": "false",
-  "host": "192.168.10.125",
+  "host": "192.168.10.106",
   "garageID":"2",
   "port": "9000",
   "size": "1024"

+ 14 - 0
PLCLinker/newPLCConnector/App.config

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
+    </startup>
+  <appSettings>
+    <add key="plcIpAddress" value="192.168.10.60" />
+    <add key="plcRack" value="0" />
+    <add key="plcSlot" value="1" />
+    <add key="plcDatablockId" value="18,41,20" />
+    <!--日志写入地址配置文件-->
+    <add key="LogAddress" value="E:\superScene\智能停车项目\测试包\snap7\LoggerTest" />
+  </appSettings>
+</configuration>