Browse Source

PLC调试工具与主程序共用句柄,加入中控心跳,根据多加的点位调整PLC通信dll文件,检查预约指令可操作性,停车依然接收PLC启动号牌指令并给予反馈

yc_t 6 years ago
parent
commit
f42671d6d4
32 changed files with 580 additions and 355 deletions
  1. BIN
      PLCLinker/PLCConnector/PLC/PLCS7.dll
  2. 16 1
      PLCLinker/PLCConnector/PLC/PLCS7.xml
  3. 27 7
      PLCLinker/PLCLinker/Program.cs
  4. BIN
      PLCLinker/PLCLinker/bin/Release/PLCLinker.exe
  5. BIN
      PLCLinker/PLCLinker/bin/Release/PLCLinker.pdb
  6. BIN
      PLCLinker/PLCLinker/obj/Release/PLCLinker.exe
  7. BIN
      PLCLinker/PLCLinker/obj/Release/PLCLinker.pdb
  8. 6 4
      PLCLinker/PLCS7/PLCS7.cs
  9. BIN
      PLCLinker/PLCS7/bin/Release/PLCS7.dll
  10. BIN
      PLCLinker/PLCS7/bin/Release/PLCS7.pdb
  11. 16 3
      PLCLinker/PLCS7/entity.cs
  12. BIN
      PLCLinker/PLCS7/obj/Release/PLCS7.dll
  13. BIN
      PLCLinker/PLCS7/obj/Release/PLCS7.pdb
  14. 1 1
      PLCLinker/centralController/App.config
  15. 69 69
      PLCLinker/centralController/FormCentralController.Designer.cs
  16. 1 0
      PLCLinker/centralController/FormCentralController.cs
  17. 6 5
      PLCLinker/centralController/FormPLCConf.cs
  18. 35 30
      PLCLinker/centralController/Monitor/Monitor.cs
  19. 25 4
      PLCLinker/centralController/Monitor/SystemInitializer.cs
  20. 5 2
      PLCLinker/centralController/NumMachine/NumMachine.cs
  21. 198 178
      PLCLinker/centralController/Terminal/Terminal.cs
  22. 0 1
      PLCLinker/centralController/WebServer/MultiSocketThread.cs
  23. 157 47
      PLCLinker/centralController/WebServer/WebServer.cs
  24. BIN
      PLCLinker/centralController/obj/Release/centralController.csproj.GenerateResource.Cache
  25. BIN
      PLCLinker/centralController/sdk/PLC/PLCS7.dll
  26. 16 1
      PLCLinker/centralController/sdk/PLC/PLCS7.xml
  27. BIN
      PLCLinker/centralController/sdk/dotNetty/nettyCommunication.dll
  28. 2 2
      PLCLinker/centralController/serversettings.json
  29. BIN
      PLCLinker/socketTest/bin/Release/socketTest.exe
  30. BIN
      PLCLinker/socketTest/bin/Release/socketTest.pdb
  31. BIN
      PLCLinker/socketTest/obj/Release/socketTest.exe
  32. BIN
      PLCLinker/socketTest/obj/Release/socketTest.pdb

BIN
PLCLinker/PLCConnector/PLC/PLCS7.dll


+ 16 - 1
PLCLinker/PLCConnector/PLC/PLCS7.xml

@@ -221,6 +221,11 @@
             启动对应号牌机
             </summary>
         </member>
+        <member name="F:PLCS7.TerminalStru.termHeartbeat">
+            <summary>
+            终端心跳
+            </summary>
+        </member>
         <member name="T:PLCS7.MainBlockStru">
             <summary>
             中控与PLC交互使用数据块的结构体
@@ -306,6 +311,16 @@
             本地手动模式
             </summary>
         </member>
+        <member name="F:PLCS7.MainBlockStru.centralHearbeat">
+            <summary>
+            中控心跳
+            </summary>
+        </member>
+        <member name="F:PLCS7.MainBlockStru.reserveTotalSpace">
+            <summary>
+            预约车位总数
+            </summary>
+        </member>
         <member name="T:PLCS7.ParkingSpaceStru">
             <summary>
             车位单元结构体
@@ -343,7 +358,7 @@
         </member>
         <member name="F:PLCS7.ParkingSpaceStru.spaceStatus">
             <summary>
-            车位状态,0空位-1占用-2保留-3故障
+            车位状态,0空位-1占用-2保留-3已预约-4故障
             </summary>
         </member>
         <member name="F:PLCS7.ParkingSpaceStru.frontWheelbase">

+ 27 - 7
PLCLinker/PLCLinker/Program.cs

@@ -16,6 +16,7 @@ namespace PLCTest
     class Program
     {
         //public static int haha = int.Parse("123456");
+        static int count = 0;
         static void Main(string[] args)
         {
             #region PLC
@@ -82,14 +83,33 @@ namespace PLCTest
             //result[0] = regChar.Replace(strs, "");
             //result[1] = regNum.Replace(strs, "");
             //Console.WriteLine(result[0] + "," + result[1]);
-            Task.Factory.StartNew(() =>
-            {
-                PrintWord("a", 1000);
-            });
-            Task.Factory.StartNew(() =>
+
+            int[] arr = { 13, 2, 812, 21, 55, 251,713,29,68 };
+            for (int i = 0; i < arr.Length; i++)
             {
-                PrintWord("bbb", 2000);
-            });
+                //Console.WriteLine(i);
+                Task.Factory.StartNew(() =>
+                {
+                    int temp = count;
+                    count++;
+                    try
+                    {
+                        Thread.Sleep(arr[temp]);
+                        Console.Write(arr[temp] + ",");
+                    }
+                    catch (Exception e) { Console.WriteLine(temp + "," + e.Message); }
+                });
+            }
+            //Task.Factory.StartNew(() =>
+            //{
+            //    //PrintWord("a", 1000);
+            //});
+
+            //Task.Factory.StartNew(() =>
+            //{
+            //    //PrintWord("bbb", 2000);
+            //});
+
             //Console.WriteLine(haha);
             Console.ReadLine();
         }

BIN
PLCLinker/PLCLinker/bin/Release/PLCLinker.exe


BIN
PLCLinker/PLCLinker/bin/Release/PLCLinker.pdb


BIN
PLCLinker/PLCLinker/obj/Release/PLCLinker.exe


BIN
PLCLinker/PLCLinker/obj/Release/PLCLinker.pdb


+ 6 - 4
PLCLinker/PLCS7/PLCS7.cs

@@ -29,7 +29,7 @@ namespace PLCS7
     {
         protected const int mainBlockOffset = 52;
         protected const int parkingSpaceOffset = 18;
-        protected const int terminalLength = 44;
+        protected const int terminalLength = 46;
         protected const int parkingSpaceLength = 24;
         /// <summary>
         /// PLC 连接状态flag
@@ -393,9 +393,11 @@ namespace PLCS7
                 {
                     //只允许中控写入,且中控只允许写入号牌获取状态
                     MainBlockStru mbs = (MainBlockStru)abstractPLCMsg;
-                    byte[] temp = BitConverter.GetBytes(BytesRevert(mbs.licenseReceived));
-                    ErrorCode ec = plc.WriteBytes(DataType.DataBlock, centralDB, mainBlockOffset, temp);
-                    if (!ec.Equals(ErrorCode.NoError)) { return false; }
+                    //byte[] temp = BitConverter.GetBytes(BytesRevert(mbs.licenseReceived));
+                    if (mbs.centralHearbeat != (short)-1) { plc.WriteBytes(DataType.DataBlock, centralDB, mainBlockOffset + 8, BitConverter.GetBytes(BytesRevert(mbs.centralHearbeat))); }
+                    if (mbs.licenseReceived != (short)-1) { plc.WriteBytes(DataType.DataBlock, centralDB, mainBlockOffset, BitConverter.GetBytes(BytesRevert(mbs.licenseReceived))); }
+                    //ErrorCode ec = plc.WriteBytes(DataType.DataBlock, centralDB, mainBlockOffset, temp);
+                    //if (!ec.Equals(ErrorCode.NoError)) { return false; }
                 }
                 else if (abstractPLCMsg.GetType().Equals(typeof(ParkingSpaceStru)) && whoami.Equals(PLCDataType.central))
                 {

BIN
PLCLinker/PLCS7/bin/Release/PLCS7.dll


BIN
PLCLinker/PLCS7/bin/Release/PLCS7.pdb


+ 16 - 3
PLCLinker/PLCS7/entity.cs

@@ -79,12 +79,17 @@ namespace PLCS7
         /// 启动对应号牌机
         /// </summary>
         public short numMachineLaunch;
+        /// <summary>
+        /// 终端心跳
+        /// </summary>
+        public short termHeartbeat;
 
         public override string ToString()
         {
             return "[终端id(0):" + terminalID + ",终端状态(2):" + terminalStatus + ",按钮状态(4):" + btnStatus + ",终端指令(6):" + cmd + ",用户id(8):" + licenseCodeA + ","
                 + licenseCodeB + "," + licenseCodeC + "," + licenseCodeD + ",凭证号(24):" + receiptNum + ",支付状态(28):" + paymentStatus
-                + ",号牌验证(30):" + licVerification + ",停车费用(32):" + parkingFee + ",用户类型(34):" + userType + ",X坐标(36):" + coordX + ",Y坐标(38):" + coordY + ",地感信号(40):" + groundStatus + ",启动号牌机:" + numMachineLaunch + "]";
+                + ",号牌验证(30):" + licVerification + ",停车费用(32):" + parkingFee + ",用户类型(34):" + userType + ",X坐标(36):" + coordX + ",Y坐标(38):" + coordY + 
+                ",地感信号(40):" + groundStatus + ",启动号牌机(42):" + numMachineLaunch + ",终端心跳(44):" + termHeartbeat + "]";
         }
 
         public override bool Equals(object obj)
@@ -193,13 +198,21 @@ namespace PLCS7
         /// 本地手动模式
         /// </summary>
         public short localManualMode;
+        /// <summary>
+        /// 中控心跳
+        /// </summary>
+        public short centralHearbeat;
+        /// <summary>
+        /// 预约车位总数
+        /// </summary>
+        public short reserveTotalSpace;
 
         public override string ToString()
         {
             return "[id(0):" + terminalID + ",号牌(2):" + numMachineLaunch + ",摆扫(4):" + sweepLaserLaunch + ",轮距(6):" + wheelbaseLaserLaunch + ",急停(8):" + stop
                 + ",就绪(10):" + ready + ",停车启动(12):" + parkingRunning + ",取车启动(14):" + fetchingRunning + ",流程完成(16):" + processCompleted + ",流程中止(18):" +
                 processStopped + ",摆扫状态(20):" + sweepLaserStatus + ",轮距状态(22):" + wheelbaseLaserStatus + ",号牌获取(52):" + licenseReceived
-                + ",本地自动(54):" + localAutoMode + ",远程模式(56):" + remoteMode + ",本地手动(58):" + localManualMode + "," + groundAStatus
+                + ",本地自动(54):" + localAutoMode + ",远程模式(56):" + remoteMode + ",本地手动(58):" + localManualMode + ",中控心跳(60):" + centralHearbeat + ",预约车位总数(62)" + reserveTotalSpace + "," + groundAStatus
                 + "," + groundBStatus + "," + groundCStatus + "," + arriveAAndOpen + "," + arriveBAndOpen + "," + arriveCAndOpen
                  + "]";
         }
@@ -253,7 +266,7 @@ namespace PLCS7
         /// </summary>
         public int receiptNum;
         /// <summary>
-        /// 车位状态,0空位-1占用-2保留-3故障
+        /// 车位状态,0空位-1占用-2保留-3已预约-4故障
         /// </summary>
         public short spaceStatus;
         /// <summary>

BIN
PLCLinker/PLCS7/obj/Release/PLCS7.dll


BIN
PLCLinker/PLCS7/obj/Release/PLCS7.pdb


+ 1 - 1
PLCLinker/centralController/App.config

@@ -9,7 +9,7 @@
     <!--<add key="remoteDBConnStr" value="Data Source=59.175.148.85;port=3306;uid=root;pooling=true;max pool size=1024;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;"/>-->
     <!--<add key="remoteDBConnStr" value="Data Source=192.168.111.61;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>-->
     <add key="remoteDBConnStr" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;max pool size=1024;pwd=yct;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>
-    <!--<add key="remoteDBConnStr" value="Data Source=192.168.111.61;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>-->
+    <!--<add key="remoteDBConnStr" value="Data Source=192.168.10.125;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>-->
     <add key="localDBConnStr" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;max pool size=1024;pwd=yct;database=zxpark_local;CharSet=utf8;Allow Zero Datetime=true;"/>
     <add key="DBtimeout" value="3"/>
     <!--号牌机信息-->

+ 69 - 69
PLCLinker/centralController/FormCentralController.Designer.cs

@@ -40,10 +40,14 @@
             this.paymentPanel = new DevComponents.DotNetBar.PanelDockContainer();
             this.ParkingSpaceMonitorPanel = new DevComponents.DotNetBar.PanelDockContainer();
             this.testPanel = new DevComponents.DotNetBar.PanelDockContainer();
+            this.button2 = new System.Windows.Forms.Button();
             this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
             this.button1 = new System.Windows.Forms.Button();
             this.textBox2 = new System.Windows.Forms.TextBox();
             this.textBox1 = new System.Windows.Forms.TextBox();
+            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+            this.pictureBox1 = new System.Windows.Forms.PictureBox();
+            this.labelX1 = new DevComponents.DotNetBar.LabelX();
             this.dci_NumMachine = new DevComponents.DotNetBar.DockContainerItem();
             this.dci_payment = new DevComponents.DotNetBar.DockContainerItem();
             this.dci_ParkingSpace = new DevComponents.DotNetBar.DockContainerItem();
@@ -117,15 +121,13 @@
             this.dockContainerItem1 = new DevComponents.DotNetBar.DockContainerItem();
             this.panelDockContainer8 = new DevComponents.DotNetBar.PanelDockContainer();
             this.controlContainerItem1 = new DevComponents.DotNetBar.ControlContainerItem();
-            this.labelX1 = new DevComponents.DotNetBar.LabelX();
-            this.pictureBox1 = new System.Windows.Forms.PictureBox();
-            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
-            this.button2 = new System.Windows.Forms.Button();
             this.dockSite_mainView.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.bar_mainWin)).BeginInit();
             this.bar_mainWin.SuspendLayout();
             this.NumMachineMonitorPanel.SuspendLayout();
             this.testPanel.SuspendLayout();
+            this.tableLayoutPanel1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.bar_bottom)).BeginInit();
             this.bar_bottom.SuspendLayout();
             this.RecordsMonitorPanel.SuspendLayout();
@@ -141,8 +143,6 @@
             ((System.ComponentModel.ISupportInitialize)(this.bar_shortcut)).BeginInit();
             this.bar_shortcut.SuspendLayout();
             this.panel_freeSpace.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
-            this.tableLayoutPanel1.SuspendLayout();
             this.SuspendLayout();
             // 
             // dotNetBarManager1
@@ -189,8 +189,8 @@
             this.dockSite_mainView.Dock = System.Windows.Forms.DockStyle.Fill;
             this.dockSite_mainView.DocumentDockContainer = new DevComponents.DotNetBar.DocumentDockContainer(new DevComponents.DotNetBar.DocumentBaseContainer[] {
             ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentDockContainer(new DevComponents.DotNetBar.DocumentBaseContainer[] {
-                        ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentBarContainer(this.bar_mainWin, 672, 326))),
-                        ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentBarContainer(this.bar_side, 208, 326)))}, DevComponents.DotNetBar.eOrientation.Horizontal))),
+                        ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentBarContainer(this.bar_mainWin, 621, 326))),
+                        ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentBarContainer(this.bar_side, 259, 326)))}, DevComponents.DotNetBar.eOrientation.Horizontal))),
             ((DevComponents.DotNetBar.DocumentBaseContainer)(new DevComponents.DotNetBar.DocumentBarContainer(this.bar_bottom, 871, 181)))}, DevComponents.DotNetBar.eOrientation.Vertical);
             this.dockSite_mainView.Location = new System.Drawing.Point(0, 121);
             this.dockSite_mainView.Name = "dockSite_mainView";
@@ -211,10 +211,10 @@
             this.bar_mainWin.CanDockRight = false;
             this.bar_mainWin.CanDockTop = false;
             this.bar_mainWin.CanHide = true;
-            this.bar_mainWin.Controls.Add(this.testPanel);
+            this.bar_mainWin.Controls.Add(this.NumMachineMonitorPanel);
             this.bar_mainWin.Controls.Add(this.paymentPanel);
             this.bar_mainWin.Controls.Add(this.ParkingSpaceMonitorPanel);
-            this.bar_mainWin.Controls.Add(this.NumMachineMonitorPanel);
+            this.bar_mainWin.Controls.Add(this.testPanel);
             this.bar_mainWin.DockTabAlignment = DevComponents.DotNetBar.eTabStripAlignment.Top;
             this.bar_mainWin.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.bar_mainWin.IsMaximized = false;
@@ -226,9 +226,9 @@
             this.bar_mainWin.LayoutType = DevComponents.DotNetBar.eLayoutType.DockContainer;
             this.bar_mainWin.Location = new System.Drawing.Point(0, 0);
             this.bar_mainWin.Name = "bar_mainWin";
-            this.bar_mainWin.SelectedDockTab = 3;
+            this.bar_mainWin.SelectedDockTab = 0;
             this.bar_mainWin.SingleLineColor = System.Drawing.SystemColors.ControlDarkDark;
-            this.bar_mainWin.Size = new System.Drawing.Size(672, 326);
+            this.bar_mainWin.Size = new System.Drawing.Size(621, 326);
             this.bar_mainWin.Stretch = true;
             this.bar_mainWin.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
             this.bar_mainWin.TabIndex = 0;
@@ -241,7 +241,7 @@
             this.NumMachineMonitorPanel.DisabledBackColor = System.Drawing.Color.Empty;
             this.NumMachineMonitorPanel.Location = new System.Drawing.Point(3, 28);
             this.NumMachineMonitorPanel.Name = "NumMachineMonitorPanel";
-            this.NumMachineMonitorPanel.Size = new System.Drawing.Size(666, 295);
+            this.NumMachineMonitorPanel.Size = new System.Drawing.Size(615, 295);
             this.NumMachineMonitorPanel.Style.Alignment = System.Drawing.StringAlignment.Center;
             this.NumMachineMonitorPanel.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
             this.NumMachineMonitorPanel.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
@@ -255,7 +255,7 @@
             this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
             this.flowLayoutPanel1.Name = "flowLayoutPanel1";
-            this.flowLayoutPanel1.Size = new System.Drawing.Size(666, 295);
+            this.flowLayoutPanel1.Size = new System.Drawing.Size(615, 295);
             this.flowLayoutPanel1.TabIndex = 1;
             this.flowLayoutPanel1.Resize += new System.EventHandler(this.flowLayoutPanel1_Resize);
             // 
@@ -264,7 +264,7 @@
             this.paymentPanel.DisabledBackColor = System.Drawing.Color.Empty;
             this.paymentPanel.Location = new System.Drawing.Point(3, 28);
             this.paymentPanel.Name = "paymentPanel";
-            this.paymentPanel.Size = new System.Drawing.Size(666, 295);
+            this.paymentPanel.Size = new System.Drawing.Size(615, 295);
             this.paymentPanel.Style.Alignment = System.Drawing.StringAlignment.Center;
             this.paymentPanel.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
             this.paymentPanel.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
@@ -277,7 +277,7 @@
             this.ParkingSpaceMonitorPanel.DisabledBackColor = System.Drawing.Color.Empty;
             this.ParkingSpaceMonitorPanel.Location = new System.Drawing.Point(3, 28);
             this.ParkingSpaceMonitorPanel.Name = "ParkingSpaceMonitorPanel";
-            this.ParkingSpaceMonitorPanel.Size = new System.Drawing.Size(666, 295);
+            this.ParkingSpaceMonitorPanel.Size = new System.Drawing.Size(615, 295);
             this.ParkingSpaceMonitorPanel.Style.Alignment = System.Drawing.StringAlignment.Center;
             this.ParkingSpaceMonitorPanel.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
             this.ParkingSpaceMonitorPanel.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
@@ -296,7 +296,7 @@
             this.testPanel.DisabledBackColor = System.Drawing.Color.Empty;
             this.testPanel.Location = new System.Drawing.Point(3, 28);
             this.testPanel.Name = "testPanel";
-            this.testPanel.Size = new System.Drawing.Size(666, 295);
+            this.testPanel.Size = new System.Drawing.Size(615, 295);
             this.testPanel.Style.Alignment = System.Drawing.StringAlignment.Center;
             this.testPanel.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
             this.testPanel.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
@@ -304,6 +304,16 @@
             this.testPanel.Style.GradientAngle = 90;
             this.testPanel.TabIndex = 38;
             // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(271, 44);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(75, 23);
+            this.button2.TabIndex = 8;
+            this.button2.Text = "button2";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
             // dateTimePicker1
             // 
             this.dateTimePicker1.Location = new System.Drawing.Point(257, 108);
@@ -335,6 +345,42 @@
             this.textBox1.Size = new System.Drawing.Size(100, 21);
             this.textBox1.TabIndex = 4;
             // 
+            // tableLayoutPanel1
+            // 
+            this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+            this.tableLayoutPanel1.ColumnCount = 1;
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+            this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 0, 1);
+            this.tableLayoutPanel1.Controls.Add(this.labelX1, 0, 0);
+            this.tableLayoutPanel1.Location = new System.Drawing.Point(9, 72);
+            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+            this.tableLayoutPanel1.RowCount = 2;
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 80F));
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(185, 168);
+            this.tableLayoutPanel1.TabIndex = 3;
+            // 
+            // pictureBox1
+            // 
+            this.pictureBox1.Location = new System.Drawing.Point(3, 36);
+            this.pictureBox1.Name = "pictureBox1";
+            this.pictureBox1.Size = new System.Drawing.Size(179, 127);
+            this.pictureBox1.TabIndex = 2;
+            this.pictureBox1.TabStop = false;
+            // 
+            // labelX1
+            // 
+            // 
+            // 
+            // 
+            this.labelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
+            this.labelX1.Location = new System.Drawing.Point(3, 3);
+            this.labelX1.Name = "labelX1";
+            this.labelX1.Size = new System.Drawing.Size(179, 27);
+            this.labelX1.TabIndex = 3;
+            this.labelX1.Text = "label1\r\nlable2";
+            this.labelX1.TextAlignment = System.Drawing.StringAlignment.Center;
+            // 
             // dci_NumMachine
             // 
             this.dci_NumMachine.Control = this.NumMachineMonitorPanel;
@@ -533,10 +579,10 @@
             this.bar_side.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
             this.dci_terminal});
             this.bar_side.LayoutType = DevComponents.DotNetBar.eLayoutType.DockContainer;
-            this.bar_side.Location = new System.Drawing.Point(675, 0);
+            this.bar_side.Location = new System.Drawing.Point(624, 0);
             this.bar_side.Name = "bar_side";
             this.bar_side.SelectedDockTab = 0;
-            this.bar_side.Size = new System.Drawing.Size(208, 326);
+            this.bar_side.Size = new System.Drawing.Size(259, 326);
             this.bar_side.Stretch = true;
             this.bar_side.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
             this.bar_side.TabIndex = 2;
@@ -547,7 +593,7 @@
             this.terminalMonitorPanel.DisabledBackColor = System.Drawing.Color.Empty;
             this.terminalMonitorPanel.Location = new System.Drawing.Point(3, 28);
             this.terminalMonitorPanel.Name = "terminalMonitorPanel";
-            this.terminalMonitorPanel.Size = new System.Drawing.Size(202, 295);
+            this.terminalMonitorPanel.Size = new System.Drawing.Size(253, 295);
             this.terminalMonitorPanel.Style.Alignment = System.Drawing.StringAlignment.Center;
             this.terminalMonitorPanel.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
             this.terminalMonitorPanel.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
@@ -559,7 +605,7 @@
             // 
             this.dci_terminal.Control = this.terminalMonitorPanel;
             this.dci_terminal.Name = "dci_terminal";
-            this.dci_terminal.Text = "终端监控";
+            this.dci_terminal.Text = "地面车位监控";
             // 
             // dockSite1
             // 
@@ -1107,52 +1153,6 @@
             this.controlContainerItem1.MenuVisibility = DevComponents.DotNetBar.eMenuVisibility.VisibleAlways;
             this.controlContainerItem1.Name = "controlContainerItem1";
             // 
-            // labelX1
-            // 
-            // 
-            // 
-            // 
-            this.labelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
-            this.labelX1.Location = new System.Drawing.Point(3, 3);
-            this.labelX1.Name = "labelX1";
-            this.labelX1.Size = new System.Drawing.Size(179, 27);
-            this.labelX1.TabIndex = 3;
-            this.labelX1.Text = "label1\r\nlable2";
-            this.labelX1.TextAlignment = System.Drawing.StringAlignment.Center;
-            // 
-            // pictureBox1
-            // 
-            this.pictureBox1.Location = new System.Drawing.Point(3, 36);
-            this.pictureBox1.Name = "pictureBox1";
-            this.pictureBox1.Size = new System.Drawing.Size(179, 127);
-            this.pictureBox1.TabIndex = 2;
-            this.pictureBox1.TabStop = false;
-            // 
-            // tableLayoutPanel1
-            // 
-            this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
-            this.tableLayoutPanel1.ColumnCount = 1;
-            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
-            this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 0, 1);
-            this.tableLayoutPanel1.Controls.Add(this.labelX1, 0, 0);
-            this.tableLayoutPanel1.Location = new System.Drawing.Point(9, 72);
-            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
-            this.tableLayoutPanel1.RowCount = 2;
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 80F));
-            this.tableLayoutPanel1.Size = new System.Drawing.Size(185, 168);
-            this.tableLayoutPanel1.TabIndex = 3;
-            // 
-            // button2
-            // 
-            this.button2.Location = new System.Drawing.Point(271, 44);
-            this.button2.Name = "button2";
-            this.button2.Size = new System.Drawing.Size(75, 23);
-            this.button2.TabIndex = 8;
-            this.button2.Text = "button2";
-            this.button2.UseVisualStyleBackColor = true;
-            this.button2.Click += new System.EventHandler(this.button2_Click);
-            // 
             // centralController
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -1181,6 +1181,8 @@
             this.NumMachineMonitorPanel.ResumeLayout(false);
             this.testPanel.ResumeLayout(false);
             this.testPanel.PerformLayout();
+            this.tableLayoutPanel1.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.bar_bottom)).EndInit();
             this.bar_bottom.ResumeLayout(false);
             this.RecordsMonitorPanel.ResumeLayout(false);
@@ -1196,8 +1198,6 @@
             ((System.ComponentModel.ISupportInitialize)(this.bar_shortcut)).EndInit();
             this.bar_shortcut.ResumeLayout(false);
             this.panel_freeSpace.ResumeLayout(false);
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
-            this.tableLayoutPanel1.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }

+ 1 - 0
PLCLinker/centralController/FormCentralController.cs

@@ -452,6 +452,7 @@ namespace centralController
             if (result.Equals(DialogResult.OK))
             {
                 Monitor.Monitor.ins.Stop();
+
             }
             else
             {

+ 6 - 5
PLCLinker/centralController/FormPLCConf.cs

@@ -29,7 +29,7 @@ namespace PLCConnector
                 rack = Int16.Parse(ConfigurationManager.AppSettings.Get("plcRack"));
                 slot = Int16.Parse(ConfigurationManager.AppSettings.Get("plcSlot"));
                 blockIds = (ConfigurationManager.AppSettings.Get("plcDatablockId")).Split(',');
-                
+                pl = (PLCLinker)Monitor.Monitor.PLC;
             }
             catch (Exception e) { MessageBox.Show("配置文件异常"); }
             Control.ControlCollection cc = this.Controls;
@@ -278,15 +278,15 @@ namespace PLCConnector
         private void btn_refresh_Click(object sender, EventArgs e)
         {
             Timer timer1 = new Timer();
-            timer1.Interval = 1000;
+            timer1.Interval = 500;
             timer1.Tick += new EventHandler(button2_Click);
             timer1.Start();
             Timer timer2 = new Timer();
-            timer2.Interval = 1000;
+            timer2.Interval = 500;
             timer2.Tick += new EventHandler(button3_Click);
             timer2.Start();
             Timer timer3 = new Timer();
-            timer3.Interval = 1000;
+            timer3.Interval = 500;
             timer3.Tick += new EventHandler(button4_Click);
             timer3.Start();
         }
@@ -428,7 +428,8 @@ namespace PLCConnector
         {
             if (pl == null)
             {
-                pl = new PLCLinker(CpuType.S71500, ip, rack, slot, int.Parse(blockIds[0]), int.Parse(blockIds[1]), int.Parse(blockIds[2]), 6, 200);
+                //pl = new PLCLinker(CpuType.S71500, ip, rack, slot, int.Parse(blockIds[0]), int.Parse(blockIds[1]), int.Parse(blockIds[2]), 6, 200);
+                pl = (PLCLinker)Monitor.Monitor.PLC;
             }
             if (!pl.isConnected)
             {

+ 35 - 30
PLCLinker/centralController/Monitor/Monitor.cs

@@ -85,7 +85,7 @@ namespace Monitor
         /// <summary>
         /// 系统关闭状态
         /// </summary>
-        bool isClosing;
+        public static bool isClosing;
         /// <summary>
         /// 车库ID
         /// </summary>
@@ -106,7 +106,7 @@ namespace Monitor
                 {
                     if (PLC.isConnected)
                     {
-                        if (disconnected) {disconnected = false; SetNotification("PLC已重新连接连接"); }
+                        if (disconnected) {disconnected = false; SetNotification("PLC已重新连接"); }
                         linkCount = 0;
                         List<object> received = PLC.ReadFromPLC(PLCDataType.terminal, 0);
                         //首先获取所有终端信息
@@ -484,12 +484,16 @@ namespace Monitor
         /// <summary>
         /// 返回空闲正常车位数
         /// </summary>
-        /// <param name="state">状态:0.空闲与保留,1.空闲,2.保留</param>
+        /// <param name="state">状态:0.空闲与保留,1.空闲,2.保留,3.预约车位总数</param>
         /// <returns></returns>
         public int GetFreeSpaceCount(int state)
         {
             int freeSpaceCount = 0;
             int reservedSpaceCount = 0;
+            if(state == 3)
+            {
+                return mainBlockInfo.reserveTotalSpace;
+            }
             if (parkingSpaceInfo != null)
             {
                 foreach (ParkingSpaceStru psStru in parkingSpaceInfo)
@@ -518,33 +522,33 @@ namespace Monitor
         /// 暂未使用,查询本地数据库返回可预约车位数
         /// </summary>
         /// <returns></returns>
-        public int GetBookableSpaceCount()
-        {
-            int bookableSpaceCount = 0;
-            string bookableSpaceSql = "select currentBookableSpace from garageproperties where garageID = " + garageID + ";";
-            if (localDBOper != null)
-            {
-                MySqlDataReader reader = localDBOper.Query(bookableSpaceSql);
-                if (reader != null)
-                {
-                    try
-                    {
-                        if (reader.Read() && reader.HasRows)
-                        {
-                            bookableSpaceCount = reader.GetInt32("currentBookableSpace");
-                        }
-                    }
-                    catch { }
-                    try
-                    {
-                        reader.Close();
-                        reader.Dispose();
-                    }
-                    catch { }
-                }
-            }
-            return bookableSpaceCount;
-        }
+        //public int GetBookableSpaceCount()
+        //{
+        //    int bookableSpaceCount = 0;
+        //    string bookableSpaceSql = "select currentBookableSpace from garageproperties where garageID = " + garageID + ";";
+        //    if (localDBOper != null)
+        //    {
+        //        MySqlDataReader reader = localDBOper.Query(bookableSpaceSql);
+        //        if (reader != null)
+        //        {
+        //            try
+        //            {
+        //                if (reader.Read() && reader.HasRows)
+        //                {
+        //                    bookableSpaceCount = reader.GetInt32("currentBookableSpace");
+        //                }
+        //            }
+        //            catch { }
+        //            try
+        //            {
+        //                reader.Close();
+        //                reader.Dispose();
+        //            }
+        //            catch { }
+        //        }
+        //    }
+        //    return bookableSpaceCount;
+        //}
         /// <summary>
         /// 系统初始化,启动plc监控
         /// </summary>
@@ -575,6 +579,7 @@ namespace Monitor
         public void Stop()
         {
             sysInitializer.Stop();
+            System.Environment.Exit(0);
         }
     }
 

+ 25 - 4
PLCLinker/centralController/Monitor/SystemInitializer.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Configuration;
 using System.Linq;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using allInOneMachine;
 using BroadcastModule;
@@ -84,8 +85,8 @@ namespace Monitor
 
             //初始化web对象
             Monitor.SetNotification("初始化云端连接...");
-            Monitor.webServer = new CentralForWeb();
-            //Monitor.webServer = new MyWebServer();
+            //Monitor.webServer = new CentralForWeb();
+            Monitor.webServer = new MyWebServer();
             initStatus = initStatus && Monitor.webServer.Start(Monitor.webPort);
             //webServer初始化结束,进入状态4
             if (!initStatus) { return; }
@@ -127,8 +128,8 @@ namespace Monitor
             Monitor.numMachineLinker.Start();
             //初始化显示板对象,显示板udp面向无连接
             Monitor.SetNotification("初始化屏显...");
-            BroadcastLinker.Start();
-            Monitor.allInOneMachine = BroadcastLinker.ins;//new BroadcastBoard(Monitor.allInOneMachineIP, Monitor.allInOneMachinePort);
+            //BroadcastLinker.Start();
+            //Monitor.allInOneMachine = BroadcastLinker.ins;//new BroadcastBoard(Monitor.allInOneMachineIP, Monitor.allInOneMachinePort);
             //初始化广告实例
             Monitor.advertMgr = new AdvertManager();
             //initStatus = initStatus && AdvertMgrInit(3);
@@ -189,6 +190,26 @@ namespace Monitor
                 }
                 else if (Monitor.PLC.isConnected)
                 {
+                    //启动心跳进程
+                    Task.Factory.StartNew(() =>
+                    {
+                        while (!Monitor.isClosing)
+                        {
+                            if (Monitor.PLC.isConnected)
+                            {
+                                MainBlockStru mbs = new MainBlockStru();
+                                List<object> list = Monitor.PLC.ReadFromPLC(PLCDataType.central, 0);
+                                if (list.Count != 0)
+                                {
+                                    mbs = (MainBlockStru)list[0];
+                                    mbs.centralHearbeat = (mbs.centralHearbeat == (short)254) ? (short)255 : (short)254;
+                                    mbs.licenseReceived = (short)-1;
+                                    Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
+                                }
+                            }
+                            Thread.Sleep(1000);
+                        }
+                    });
                     return true;
                 }
                 else { Monitor.PLC.PLCConnect(); }

+ 5 - 2
PLCLinker/centralController/NumMachine/NumMachine.cs

@@ -512,8 +512,11 @@ namespace NumMachine
                                     if (node != null && ipIdMap.TryGetValue(node.ip, out node.id))
                                     {
                                         LicBuffer.Enqueue((NumberMachineNode)node.Clone());
-                                        Monitor.Monitor.allInOneMachine.DispForAWhile(2, node.LicenseNum, 25, 1, node.LicenseNum + ",入场");
-                                        Monitor.Monitor.allInOneMachine.DispForAWhile(3, "号牌机编号:" + node.id, 25, 1, "");
+                                        if (Monitor.Monitor.allInOneMachine != null)
+                                        {
+                                            Monitor.Monitor.allInOneMachine.DispForAWhile(2, node.LicenseNum, 25, 1, node.LicenseNum + ",入场");
+                                            Monitor.Monitor.allInOneMachine.DispForAWhile(3, "号牌机编号:" + node.id, 25, 1, "");
+                                        }
                                     }
                                 }
                             }

+ 198 - 178
PLCLinker/centralController/Terminal/Terminal.cs

@@ -25,7 +25,7 @@ namespace Terminal
         /// </summary>
         public static Dictionary<int, bool> termUsedMap = new Dictionary<int, bool>();
         private static Dictionary<int, FetchInfo> fetchMap = new Dictionary<int, FetchInfo>();
-        private static List<object> lockList = new List<object>();
+        private static List<bool> lockList = new List<bool>();
         public static bool isClosing = false;
 
         public void FeeCal()
@@ -403,108 +403,120 @@ namespace Terminal
                 }
             }
         }
-        #region 早期获取号牌方法,已弃用
+        #region 获取号牌方法,已调整
         /// <summary>
         /// 停车流程,收到号牌机启动后操作过程
         /// </summary>
+        private static void ParkNumSubProcess()
+        {
+            //int numMachineLaunch = Monitor.Monitor.mainBlockInfo.numMachineLaunch;
+            //if (numMachineLaunch != 0)
+            //{
+            for (int i = 0; i < terminalInfo.Count; i++)
+            {
+                //启动指令与终端id匹配
+                //if (numMachineLaunch == terminalInfo[i].terminalID)
+                if (terminalInfo[i].numMachineLaunch == 1 && terminalInfo[i].licVerification == 0)
+                {
+                    int numReceivedStatus = 0;//1获得,2终止
+                    TerminalStru term = terminalInfo[i];
+                    if (term.terminalStatus == (short)1)
+                    {
+                        string license = "";
+                        //判断之前是否已拍摄号牌
+                        if (!idLicMap.ContainsKey(terminalInfo[i].terminalID))
+                        {
+                            license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
+                            Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
+                        }
+                        else
+                        {
+                            idLicMap.TryGetValue(terminalInfo[i].terminalID, out license);
+                        }
+                        //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
+                        if (license == "")
+                        {
+                            MainBlockStru mb = new MainBlockStru
+                            {
+                                licenseReceived = (short)2
+                            };
+                            Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
+                            TerminalStru ts = new TerminalStru
+                            {
+                                terminalID = (short)terminalInfo[i].terminalID,
+                                paymentStatus = -1,
+                                parkingFee = -1,
+                                userType = -1,
+                                licVerification = (short)2
+                            };
+                            Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
+                            Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
+                        }
+                        else
+                        {
+                            //记录或更新当前号牌
+                            lock (idLicMap)
+                            {
+                                if (idLicMap.ContainsKey(terminalInfo[i].terminalID) && idLicMap[terminalInfo[i].terminalID] != license)
+                                {
+                                    idLicMap[terminalInfo[i].terminalID] = license;
+                                }
+                                else
+                                {
+                                    idLicMap.Add(terminalInfo[i].terminalID, license);
+                                }
+                            }
+                            Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
+
+                            TerminalStru ts = new TerminalStru
+                            {
+                                terminalID = (short)terminalInfo[i].terminalID,
+                                paymentStatus = -1,
+                                parkingFee = -1,
+                                userType = -1
+                            };
+                            //注册用户
+                            if (term.btnStatus == (short)2)
+                            {
+                                int userID = term.licenseCodeA;
+                                string userLicense = GetLicenseFromTerm(term);
+                                //与云端数据比对
+                                ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
+                                if (numReceivedStatus == 2)
+                                {
+                                    idLicMap.Remove(terminalInfo[i].terminalID);
+                                }
+                            }
+                            //非注册用户
+                            else if (term.btnStatus == (short)1)
+                            {
+                                numReceivedStatus = 1;
+                                ts.licVerification = 1;
+                                Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
+                            }
+                            //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
+                            MainBlockStru mb = new MainBlockStru
+                            {
+                                licenseReceived = (short)numReceivedStatus
+                            };
+                            Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
+                            //号牌获取结果被清零才跳出
+                            Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
+                        }
+                        while (term.numMachineLaunch != 0)
+                        {
+                            Thread.Sleep(1000);
+                        }
+                        Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
+                    }
+                }
+            }
+        }
+        #endregion
         //private static void ParkNumSubProcess()
         //{
-        //    //int numMachineLaunch = Monitor.Monitor.mainBlockInfo.numMachineLaunch;
-        //    //if (numMachineLaunch != 0)
-        //    //{
-        //    for (int i = 0; i < terminalInfo.Count; i++)
-        //    {
-        //        //启动指令与终端id匹配
-        //        //if (numMachineLaunch == terminalInfo[i].terminalID)
-        //        if (terminalInfo[i].numMachineLaunch == 1 && !idLicMap.ContainsKey(terminalInfo[i].terminalID) && terminalInfo[i].licVerification == 0)
-        //        {
-        //            int numReceivedStatus = 0;//1获得,2终止
-        //            TerminalStru term = terminalInfo[i];
-        //            if (term.terminalStatus == (short)1)
-        //            {
-        //                string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
-        //                Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
-        //                //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
-        //                if (license == "")
-        //                {
-        //                    MainBlockStru mb = new MainBlockStru
-        //                    {
-        //                        licenseReceived = (short)2
-        //                    };
-        //                    Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
-        //                    TerminalStru ts = new TerminalStru
-        //                    {
-        //                        terminalID = (short)terminalInfo[i].terminalID,
-        //                        paymentStatus = -1,
-        //                        parkingFee = -1,
-        //                        userType = -1,
-        //                        licVerification = (short)2
-        //                    };
-        //                    Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
-        //                    Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
-        //                }
-        //                else
-        //                {
-        //                    //记录或更新当前号牌
-        //                    lock (idLicMap)
-        //                    {
-        //                        if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
-        //                        {
-        //                            idLicMap[terminalInfo[i].terminalID] = license;
-        //                        }
-        //                        else
-        //                        {
-        //                            idLicMap.Add(terminalInfo[i].terminalID, license);
-        //                        }
-        //                    }
-        //                    Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
 
-        //                    TerminalStru ts = new TerminalStru
-        //                    {
-        //                        terminalID = (short)terminalInfo[i].terminalID,
-        //                        paymentStatus = -1,
-        //                        parkingFee = -1,
-        //                        userType = -1
-        //                    };
-        //                    //注册用户
-        //                    if (term.btnStatus == (short)2)
-        //                    {
-        //                        int userID = term.licenseCodeA;
-        //                        string userLicense = GetLicenseFromTerm(term);
-        //                        //与云端数据比对
-        //                        ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
-        //                        if (numReceivedStatus == 2)
-        //                        {
-        //                            idLicMap.Remove(terminalInfo[i].terminalID);
-        //                        }
-        //                    }
-        //                    //非注册用户
-        //                    else if (term.btnStatus == (short)1)
-        //                    {
-        //                        numReceivedStatus = 1;
-        //                        ts.licVerification = 1;
-        //                        Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
-        //                    }
-        //                    //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
-        //                    MainBlockStru mb = new MainBlockStru
-        //                    {
-        //                        licenseReceived = (short)numReceivedStatus
-        //                    };
-        //                    Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
-        //                    //号牌获取结果被清零才跳出
-        //                    Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
-        //                }
-        //                while (term.numMachineLaunch != 0)
-        //                {
-        //                    Thread.Sleep(1000);
-        //                }
-        //                Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
-        //            }
-        //        }
-        //    }
         //}
-        #endregion
-
         /// <summary>
         /// 停车流程,收到PLC停车完成信号后操作过程
         /// </summary>
@@ -614,89 +626,97 @@ namespace Terminal
                 lockList.Clear();
                 for (int i = 0; i < terminalInfo.Count; i++)
                 {
-                    lockList.Add(new object());
+                    lockList.Add(false);
                 }
             }
 
             //找到停车终端,且有地感无按钮数据
             for (int i = 0; i < terminalInfo.Count; i++)
             {
-                if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
+                //Console.WriteLine(i);
+                if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0 && !lockList[i])
                 {
-                    Task.Factory.StartNew(() =>
-                    {
-                        lock (lockList[i])
-                        {
-                            string license = "";
-                            int countdown = 2;
-                            short registered = 4;
-                            while (license == "" && countdown-- > 0)
-                            {
-                                license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
-                            }
-                            if (license != "")
-                            {
-                                //map中加入或更新号牌,供完成时写入数据库用
-                                if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
-                                {
-                                    idLicMap[terminalInfo[i].terminalID] = license;
-                                }
-                                else
-                                {
-                                    idLicMap.Add(terminalInfo[i].terminalID, license);
-                                }
-                                if (Monitor.Monitor.webServer.ReservedCarCheck(license))
-                                {
-                                    registered = 3;
-                                }
-                                #region 通过数据库查询是否预约车,方法待定
-                                //int vehicleState = -1;
-                                //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
-                                //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
-                                //if (reader != null)
-                                //{
-                                //    try
-                                //    {
-                                //        if (reader.Read())
-                                //        {
-                                //            vehicleState = reader.GetInt32("vehiclepParkState");
-                                //        }
-                                //    }
-                                //    catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
-                                //    try
-                                //    {
-                                //        reader.Close();
-                                //        reader.Dispose();
-                                //    }
-                                //    catch { }
-                                //}
-                                //已预约车辆入场
-                                //if (vehicleState == 4)
-                                //{
-                                //    registered = 3;
-                                //}
-                                #endregion
-                                TerminalStru ts = new TerminalStru
-                                {
-                                    terminalID = terminalInfo[i].terminalID,
-                                    paymentStatus = (short)-1,
-                                    btnStatus = registered,
-                                    cmd = (short)-1,
-                                    licenseCodeA = -1,
-                                    licenseCodeB = -1,
-                                    licenseCodeC = -1,
-                                    licenseCodeD = -1,
-                                    receiptNum = -1
-                                };
-                                Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
-                            }
-                            Thread.Sleep(500);
-                        }
-                    });
-                    
+                    Action<int> reserveAction = new Action<int>(ReservedOper);
+                    reserveAction(i);
                 }
             }
         }
+        private static void ReservedOper(int index)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                lockList[index] = true;
+                string license = "";
+                int countdown = 2;
+                short registered = 4;
+                while (license == "" && countdown-- > 0)
+                {
+                    license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
+                }
+                if (license != "")
+                {
+                    //map中加入或更新号牌,供完成时写入数据库用
+                    if (idLicMap.ContainsKey(terminalInfo[index].terminalID))
+                    {
+                        idLicMap[terminalInfo[index].terminalID] = license;
+                    }
+                    else
+                    {
+                        idLicMap.Add(terminalInfo[index].terminalID, license);
+                    }
+                    if (Monitor.Monitor.webServer.ReservedCarCheck(license))
+                    {
+                        registered = 3;
+                    }
+                    #region 通过数据库查询是否预约车,方法待定
+                    //int vehicleState = -1;
+                    //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
+                    //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
+                    //if (reader != null)
+                    //{
+                    //    try
+                    //    {
+                    //        if (reader.Read())
+                    //        {
+                    //            vehicleState = reader.GetInt32("vehiclepParkState");
+                    //        }
+                    //    }
+                    //    catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
+                    //    try
+                    //    {
+                    //        reader.Close();
+                    //        reader.Dispose();
+                    //    }
+                    //    catch { }
+                    //}
+                    //已预约车辆入场
+                    //if (vehicleState == 4)
+                    //{
+                    //    registered = 3;
+                    //}
+                    #endregion
+                    TerminalStru ts = new TerminalStru
+                    {
+                        terminalID = terminalInfo[index].terminalID,
+                        paymentStatus = (short)-1,
+                        btnStatus = registered,
+                        cmd = (short)-1,
+                        licenseCodeA = -1,
+                        licenseCodeB = -1,
+                        licenseCodeC = -1,
+                        licenseCodeD = -1,
+                        receiptNum = -1
+                    };
+                    Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
+                    Thread.Sleep(1000);
+                }
+                else
+                {
+                    Thread.Sleep(500);
+                }
+                lockList[index] = false;
+            });
+        }
         /// <summary>
         /// 停车相关操作
         /// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
@@ -708,14 +728,14 @@ namespace Terminal
         /// 
         private static void ParkProcess()
         {
-            //Task.Factory.StartNew(() =>
-            //{
-            //    while (!isClosing)
-            //    {
-            //        ParkNumSubProcess();
-            //        Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
-            //    }
-            //});
+            Task.Factory.StartNew(() =>
+            {
+                while (!isClosing)
+                {
+                    ParkNumSubProcess();
+                    Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
+                }
+            });
 
             Task.Factory.StartNew(() =>
             {
@@ -1178,7 +1198,7 @@ namespace Terminal
         {
             for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
             {
-                lockList.Add(new object());
+                lockList.Add(false);
             }
             ParkProcess();
             FetchProcess();

+ 0 - 1
PLCLinker/centralController/WebServer/MultiSocketThread.cs

@@ -4,7 +4,6 @@ using System.Linq;
 using System.Text;
 using System.Net.Sockets;
 using System.Threading.Tasks;
-
 using parkMonitor.Tools;
 using parkMonitor.entity;
 

+ 157 - 47
PLCLinker/centralController/WebServer/WebServer.cs

@@ -14,6 +14,7 @@ namespace centralController.WebServer
         private Queue<MessageUTF8> reserveQueue = null;
         private object reserveLock = new object();
         private Communication comm = null;
+        private Thread receiveMsg = null;
         private bool isClosing { get; set; }
         private bool connected { get; set; }
 
@@ -26,7 +27,14 @@ namespace centralController.WebServer
         {
             throw new NotImplementedException();
         }
-
+        /// <summary>
+        /// 更新预约车车辆状态
+        /// </summary>
+        /// <param name="localDB"></param>
+        /// <param name="state"></param>
+        /// <param name="orderRecordsID"></param>
+        /// <param name="license"></param>
+        /// <returns></returns>
         private bool UpdateVehicleState(bool localDB, int state, int orderRecordsID, string license)
         {
             string vehicleUpdateSql = "";
@@ -70,7 +78,16 @@ namespace centralController.WebServer
                 else return true;
             }
         }
-
+        /// <summary>
+        /// 预约数据库操作
+        /// </summary>
+        /// <param name="localDB"></param>
+        /// <param name="userID"></param>
+        /// <param name="parking"></param>
+        /// <param name="license"></param>
+        /// <param name="orderTime"></param>
+        /// <param name="orderLength"></param>
+        /// <returns></returns>
         private bool OrderDBOperation(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength)
         {
             //预约记录插入db
@@ -104,41 +121,91 @@ namespace centralController.WebServer
             return true;
         }
 
-        private void MsgHandling(MessageUTF8 msg)
+        private bool ReservationValidate(MessageUTF8 msg)
         {
-            switch (msg.cmd)
+            //可预约车位总数
+            int allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(3);
+            int count = 0;
+            DateTime start, end;
+            try
             {
-                //预约停
-                case "a":
-                    lock (reserveLock)
-                    {
-                        reserveQueue.Enqueue(msg);
-                    }
-                    //通知PLC减少可预约车位数
-                    //预约记录与车辆状态写入数据库
-                    OrderDBOperation(true, msg.sender, true, msg.context, msg.bookTime, 3);
-                    OrderDBOperation(false, msg.sender, true, msg.context, msg.bookTime, 3);
-                    break;
-                //预约取
-                case "b":
-                    break;
-                //更新广告
-                case "c":
-                    string adAlert = "";
-                    bool result = Monitor.Monitor.advertMgr.UpdateAdvert(out adAlert);
-                    if (!result)
-                    {
-                        Monitor.Monitor.SetNotification("广告更新失败,请尝试手动更新");
-                    }
-                    else
+                start = DateTime.Parse(msg.bookTime);
+                end = start.AddHours(msg.bookLength);
+            }
+            catch { return false; }
+            lock (reserveLock)
+            {
+                Queue<MessageUTF8>.Enumerator enumer = reserveQueue.GetEnumerator();
+                while (enumer.MoveNext())
+                {
+                    DateTime tempStart, tempEnd;
+                    try
                     {
-                        Monitor.Monitor.SetNotification("广告更新成功\n" + adAlert);
+                        tempStart = DateTime.Parse(enumer.Current.bookTime);
+                        tempEnd = start.AddHours(enumer.Current.bookLength);
                     }
-                    break;
-                default:
-                    Monitor.Monitor.SetNotification("接收到无法识别的指令");
-                    break;
+                    catch { return false; }
+                    if(!((tempStart-end).TotalMinutes>0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
+                }
+            }
+            if (allBookableSpace >= count)
+                return false;
+            else
+                return true;
+        }
+
+        private void MsgHandling(MessageUTF8 msg)
+        {
+            try
+            {
+                switch (msg.cmd)
+                {
+                    //预约停
+                    case "RESERVE":
+                        lock (reserveLock)
+                        {
+                            reserveQueue.Enqueue(msg);
+                        }
+                        //预约记录与车辆状态写入数据库
+                        OrderDBOperation(true, msg.sender, true, msg.context, msg.bookTime, 3);
+                        OrderDBOperation(false, msg.sender, true, msg.context, msg.bookTime, 3);
+                        //回复给web
+
+                        msg.cmd = "0";
+                        comm.SendMessage(msg);
+                        break;
+                    //预约取
+                    case "PREFETCH":
+                        break;
+                    //停车
+                    case "PARK":
+                        break;
+                    //取车
+                    case "FETCH":
+                        break;
+                    //连接断开消息
+                    case "DISCONNECT":
+                        Monitor.Monitor.SetNotification("收到连接断开提示消息");
+                        break;
+                    //更新广告
+                    case "ADVERT":
+                        string adAlert = "";
+                        bool result = Monitor.Monitor.advertMgr.UpdateAdvert(out adAlert);
+                        if (!result)
+                        {
+                            Monitor.Monitor.SetNotification("广告更新失败,请尝试手动更新");
+                        }
+                        else
+                        {
+                            Monitor.Monitor.SetNotification("广告更新成功\n" + adAlert);
+                        }
+                        break;
+                    default:
+                        Monitor.Monitor.SetNotification("接收到无法识别的指令");
+                        break;
+                }
             }
+            catch (Exception ex) { Console.WriteLine("收消息," + ex.Message + "\n" + ex.StackTrace); }
         }
         /// <summary>
         /// 启动消息接收,启动超时指令处理
@@ -148,11 +215,11 @@ namespace centralController.WebServer
         public bool Start(int port)
         {
             isClosing = false;
-
-            MessageUTF8 message = new MessageUTF8();
-            message.context = "sending message test";
-            message.cmd = "S";
-            message.parkingRecordsID = 1;
+            reserveQueue = new Queue<MessageUTF8>();
+            //MessageUTF8 message = new MessageUTF8();
+            //message.context = "sending message test";
+            //message.cmd = "S";
+            //message.parkingRecordsID = 1;
 
             Task.Factory.StartNew(() =>
             {
@@ -171,11 +238,12 @@ namespace centralController.WebServer
                         connected = false;
                         Console.WriteLine("服务没有开启,请检查服务器");
                     }
-                    Thread.Sleep(1500);
+                    Thread.Sleep(2000);
                 }
-                //持续监听
+                //持续判断连接状态并重连
                 while (!isClosing)
                 {
+                    Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
                     if (Connections.isAlive())
                     {
                         if (!connected)
@@ -183,17 +251,29 @@ namespace centralController.WebServer
                             comm = new Communication();
                         }
                         connected = true;
-                        if (comm != null)
+                        if (receiveMsg.ThreadState == ThreadState.Aborted)
                         {
-                            //comm.SendMessage(message);//消息
-                            MessageUTF8 msg = ((MessageUTF8)comm.ReceiveMessage());
-                            MsgHandling(msg);
-                            Console.WriteLine(msg.context);
+                            try
+                            {
+                                receiveMsg.Start();
+                            }
+                            catch (Exception ex) { Console.WriteLine(ex.Message); }
                         }
                     }
                     else
                     {
                         connected = false;
+                        try
+                        {
+                            if (receiveMsg.ThreadState == ThreadState.WaitSleepJoin)
+                            {
+                                receiveMsg.Interrupt();
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            Monitor.Monitor.SetNotification("连接断开,终止消息接收线程");
+                        }
                         Console.WriteLine(" 连接关闭,需要重新连接注册");
                         try
                         {
@@ -207,6 +287,24 @@ namespace centralController.WebServer
                     Thread.Sleep(1000);
                 }
             });
+            //持续接收消息
+            receiveMsg = new Thread(() =>
+            {
+                while (!isClosing)
+                {
+                    try
+                    {
+                        if (connected && comm != null)
+                        {
+                            MessageUTF8 msg = ((MessageUTF8)comm.ReceiveMessage());
+                            MsgHandling(msg);
+                            Monitor.Monitor.SetNotification(msg.context);
+                        }
+                    }
+                    catch { Console.WriteLine("线程已中断"); }
+                }
+            });
+            receiveMsg.Start();
             //处理超时预约指令
             Task.Factory.StartNew(() =>
             {
@@ -220,11 +318,16 @@ namespace centralController.WebServer
                             {
                                 MessageUTF8 msg = reserveQueue.Dequeue();
                                 DateTime startTime = DateTime.Parse(msg.bookTime);
-                                //if ((DateTime.Now - startTime).TotalMinutes > msg.bookLength * 60)
-                                if ((DateTime.Now - startTime).TotalMinutes > 3 * 60)
+                                TimeSpan ts = DateTime.Now - startTime;
+                                if (ts.TotalMinutes > msg.bookLength * 60)
                                 {
                                     //通知PLC将可预约车位数恢复一个
                                 }
+                                else if (ts.TotalMinutes >= 0)
+                                {
+                                    //通知PLC减少一个可预约车位数
+                                    reserveQueue.Enqueue(msg);
+                                }
                                 else
                                 {
                                     reserveQueue.Enqueue(msg);
@@ -259,7 +362,14 @@ namespace centralController.WebServer
                     MessageUTF8 msg = reserveQueue.Dequeue();
                     if (msg.context == license)
                     {
-                        return true;
+                        if((DateTime.Now - DateTime.Parse(msg.bookTime)).TotalMinutes >= 0)
+                        {
+                            return true;
+                        }
+                        else
+                        {
+                            //车辆提前入场,不算为预约车辆
+                        }
                     }
                     else
                     {

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


BIN
PLCLinker/centralController/sdk/PLC/PLCS7.dll


+ 16 - 1
PLCLinker/centralController/sdk/PLC/PLCS7.xml

@@ -221,6 +221,11 @@
             启动对应号牌机
             </summary>
         </member>
+        <member name="F:PLCS7.TerminalStru.termHeartbeat">
+            <summary>
+            终端心跳
+            </summary>
+        </member>
         <member name="T:PLCS7.MainBlockStru">
             <summary>
             中控与PLC交互使用数据块的结构体
@@ -306,6 +311,16 @@
             本地手动模式
             </summary>
         </member>
+        <member name="F:PLCS7.MainBlockStru.centralHearbeat">
+            <summary>
+            中控心跳
+            </summary>
+        </member>
+        <member name="F:PLCS7.MainBlockStru.reserveTotalSpace">
+            <summary>
+            预约车位总数
+            </summary>
+        </member>
         <member name="T:PLCS7.ParkingSpaceStru">
             <summary>
             车位单元结构体
@@ -343,7 +358,7 @@
         </member>
         <member name="F:PLCS7.ParkingSpaceStru.spaceStatus">
             <summary>
-            车位状态,0空位-1占用-2保留-3故障
+            车位状态,0空位-1占用-2保留-3已预约-4故障
             </summary>
         </member>
         <member name="F:PLCS7.ParkingSpaceStru.frontWheelbase">

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


+ 2 - 2
PLCLinker/centralController/serversettings.json

@@ -1,8 +1,8 @@
 {
 
   "ssl": "false",
-  "host": "127.0.0.1",
-  "garageID":"10",
+  "host": "192.168.10.125",
+  "garageID":"2",
   "port": "9000",
   "size": "1024"
 }

BIN
PLCLinker/socketTest/bin/Release/socketTest.exe


BIN
PLCLinker/socketTest/bin/Release/socketTest.pdb


BIN
PLCLinker/socketTest/obj/Release/socketTest.exe


BIN
PLCLinker/socketTest/obj/Release/socketTest.pdb