瀏覽代碼

开模拟plc,业务线程限制功能完善,界面优化

yc_t 6 年之前
父節點
當前提交
3c4d95c3fd

+ 1 - 1
parkMonitor/Database2/ConnectionPoolManager.cs

@@ -98,7 +98,7 @@ namespace parkMonitor.Database2
             connection = (Connection)conn;
             Console.WriteLine("连接出队检测");
             Console.WriteLine("输入参数连接池个数:" + bq.Count());
-            if (!CheckConnection(connection))
+            if (!CheckConnection(connection,bq))
             {
                 CheckConnPooling(2, 10, remoteConf, bq);
                 bq.Dequeue(out conn, millisecondsTimeout);

+ 14 - 1
parkMonitor/controlPanel/ControlPanel.Designer.cs

@@ -35,11 +35,12 @@
             this.btn_localDB = new System.Windows.Forms.Button();
             this.btn_reInit = new System.Windows.Forms.Button();
             this.btn_pause = new System.Windows.Forms.Button();
+            this.btn_recover = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // btn_refresh
             // 
-            this.btn_refresh.Font = new System.Drawing.Font("SimSun", 10F);
+            this.btn_refresh.Font = new System.Drawing.Font("宋体", 10F);
             this.btn_refresh.Location = new System.Drawing.Point(43, 182);
             this.btn_refresh.Name = "btn_refresh";
             this.btn_refresh.Size = new System.Drawing.Size(57, 30);
@@ -104,11 +105,22 @@
             this.btn_pause.UseVisualStyleBackColor = true;
             this.btn_pause.Click += new System.EventHandler(this.btn_pause_Click);
             // 
+            // btn_recover
+            // 
+            this.btn_recover.Location = new System.Drawing.Point(151, 125);
+            this.btn_recover.Name = "btn_recover";
+            this.btn_recover.Size = new System.Drawing.Size(75, 23);
+            this.btn_recover.TabIndex = 10;
+            this.btn_recover.Text = "恢复处理";
+            this.btn_recover.UseVisualStyleBackColor = true;
+            this.btn_recover.Click += new System.EventHandler(this.btn_recover_Click);
+            // 
             // ControlPanel
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(369, 242);
+            this.Controls.Add(this.btn_recover);
             this.Controls.Add(this.btn_pause);
             this.Controls.Add(this.btn_reInit);
             this.Controls.Add(this.btn_localDB);
@@ -131,5 +143,6 @@
         private System.Windows.Forms.Button btn_localDB;
         private System.Windows.Forms.Button btn_reInit;
         private System.Windows.Forms.Button btn_pause;
+        private System.Windows.Forms.Button btn_recover;
     }
 }

+ 8 - 0
parkMonitor/controlPanel/ControlPanel.cs

@@ -1,6 +1,7 @@
 using MySql.Data.MySqlClient;
 using parkMonitor.entity;
 using parkMonitor.server.CoreThread;
+using parkMonitor.server.uiLogServer;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -127,6 +128,13 @@ namespace parkMonitor.controlPanel
         private void btn_pause_Click(object sender, EventArgs e)
         {
             EntityForCore.ins.globalStatus = false;
+            UILogServer.ins.warn("处理流程已暂停");
+        }
+
+        private void btn_recover_Click(object sender, EventArgs e)
+        {
+            EntityForCore.ins.globalStatus = true;
+            UILogServer.ins.warn("处理流程已恢复");
         }
     }
 }

+ 22 - 16
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -209,7 +209,7 @@ namespace parkMonitor.server.CoreThread
             {
                 Robot.robot1.occupied = false;
             }
-            Robot.robot1.waitCount -= 1;
+            
             //释放激光
             if (lm != null)
             {
@@ -225,6 +225,7 @@ namespace parkMonitor.server.CoreThread
             {
                 if (isParking)
                 {
+                    Robot.robot1.parkWaitCount -= 1;
                     //释放已分配车位
                     if (!ParkingSpaceManager.ins.SetParkingSpace(parkingSpaceID, 0))
                     {
@@ -233,16 +234,17 @@ namespace parkMonitor.server.CoreThread
                         return;
                     }
                 }
-                //else
-                //{
-                //    //复原已释放的车位
-                //    if (!ParkingSpaceManager.ins.SetParkingSpace(parkingSpaceID, 1))
-                //    {
-                //        EntityForCore.ins.globalStatus = false;
-                //        Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车位分配出现异常,需要重启");
-                //        return;
-                //    }
-                //}
+                else
+                {
+                    Robot.robot1.fetchWaitCount -= 1;
+                    ////复原已释放的车位
+                    //if (!ParkingSpaceManager.ins.SetParkingSpace(parkingSpaceID, 1))
+                    //{
+                    //    EntityForCore.ins.globalStatus = false;
+                    //    Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车位分配出现异常,需要重启");
+                    //    return;
+                    //}
+                }
             }
             else
             {
@@ -794,7 +796,7 @@ namespace parkMonitor.server.CoreThread
                 lmToBeReleased.occupied = false;
             }
             Robot.robot1.occupied = false;
-            Robot.robot1.waitCount -= 1;
+            Robot.robot1.parkWaitCount -= 1;
             //自动化测试用
             //ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
             //ParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
@@ -1119,14 +1121,18 @@ namespace parkMonitor.server.CoreThread
             }
             //释放机械手
             Robot.robot1.occupied = false;
-            Robot.robot1.waitCount -= 1;
+            Robot.robot1.fetchWaitCount -= 1;
 
             //释放缓冲位与车位,缓冲位ID暂用车位X代替
-            if (ParkingSpaceManager.ins == null || !ParkingSpaceManager.ins.SetParkingSpace(ps.parkingSpaceID, 0) || ParkingBufferManager.ins == null || !ParkingBufferManager.ins.ReleaseParkingBuffer(ps.parkingSpaceX))
+            if (ParkingSpaceManager.ins == null || !ParkingSpaceManager.ins.SetParkingSpace(ps.parkingSpaceID, 0))
+            {
+                Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车位重复释放,请检查"); UILogServer.ins.error("车位重复释放,请检查");
+            }
+            if (ParkingBufferManager.ins == null || !ParkingBufferManager.ins.ReleaseParkingBuffer(ps.parkingSpaceX))
             {
-                Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车位异常,请检查"); UILogServer.ins.error("车位异常,请检查");
+                Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "缓冲位编号"+ ps.parkingSpaceX + "未找到,请检查"); UILogServer.ins.error("缓冲位编号" + ps.parkingSpaceX + "未找到,请检查");
             }
-            Log.WriteLog(LogType.NOT_DATABASE, "取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
+            Log.WriteLog(LogType.NOT_DATABASE,LogFile.INFO ,"取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
             UILogServer.ins.info("取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
 
             //自动化测试用

+ 55 - 50
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -112,36 +112,11 @@ namespace parkMonitor.server.CoreThread
             Timer killTimeoutConnection = new System.Threading.Timer(KillTimeoutConnection, null, 3600000, 3600000);
             //Timer checkLocalTimer = new System.Threading.Timer(CheckLocalPool, null, 10000, 300000);
             //Timer logTimer = new System.Threading.Timer(displayLog, null, 1000, 30000);
-            Object lockObj = new object();
-            Command queueCmdRecord = null;
             while (!isClosing)
             {
-                lock (lockObj)
-                {
-                    //判断当前计数是否允许线程创建
-                    if (queueCmdRecord != null)
-                    {
-                        if (queueCmdRecord.id / 6 == Robot.robot1.id && Robot.robot1.waitCount >= 2)
-                        {
-                            Thread.Sleep(10000);
-                            continue;
-                        }
-                        if (queueCmdRecord.id / 6 == Robot.robot2.id && Robot.robot2.waitCount >= 2)
-                        {
-                            Thread.Sleep(10000);
-                            continue;
-                        }
-                    }
-                }
-
                 if (initialized && EntityForCore.ins.globalStatus)
                 {
                     Command queueCmd = null;
-                    //等待系统总状态
-                    Task getSysStatus = Task.Factory.StartNew(() =>
-                    {
-                        GetTotalStatus();
-                    });
                     //等待号牌资源
                     Task getCmd = Task.Factory.StartNew(() =>
                     {
@@ -157,49 +132,79 @@ namespace parkMonitor.server.CoreThread
                                     queuingThread.SetMessage((Command)queueCmd.Clone());
                                     Thread.Sleep(5000);
                                 }
-                                else
+                                //判断当前计数是否允许线程创建,机械手资源争抢严重则将指令丢回队列
+                                else if (queueCmd.id / 6 + 1 == Robot.robot1.id)
                                 {
-                                    break;
+                                    if ((queueCmd.commandType=='s' && Robot.robot1.parkWaitCount >= 1) || (queueCmd.commandType=='f' && Robot.robot1.fetchWaitCount >= 1))
+                                    {
+                                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "等待机械手1资源线程过多:" + Robot.robot1.parkWaitCount + "," + Robot.robot1.fetchWaitCount);
+                                        queueCmd.returnedCount = 10000;
+                                        queuingThread.SetMessage((Command)queueCmd.Clone());
+                                        Thread.Sleep(15000);
+                                        continue;
+                                    }
                                 }
+                                else if (queueCmd.id / 6 + 1 == Robot.robot2.id)
+                                {
+                                    if ((queueCmd.commandType == 's' && Robot.robot2.parkWaitCount >= 1) || (queueCmd.commandType == 'f' && Robot.robot2.fetchWaitCount >= 1))
+                                    {
+                                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "等待机械手2资源线程过多:" + Robot.robot2.parkWaitCount + "," + Robot.robot2.fetchWaitCount);
+                                        queueCmd.returnedCount = 10000;
+                                        queuingThread.SetMessage((Command)queueCmd.Clone());
+                                        Thread.Sleep(15000);
+                                        continue;
+                                    }
+                                }
+                                break;
                             }
                         }
                     });
-                    Task.WaitAll(getSysStatus, getCmd);
-
-
-                    lock (lockObj)
+                    Task.WaitAll(getCmd);
+                    //等待系统总状态
+                    Task getSysStatus = Task.Factory.StartNew(() =>
+                    {
+                        GetTotalStatus();
+                    });
+                    Task.WaitAll(getSysStatus);
+                    //对依赖同一机械手的线程计数
+                    if (queueCmd.id / 6 + 1 == Robot.robot1.id)
                     {
-                        if (queueCmdRecord != null)
+                        if (queueCmd.commandType == 's')
                         {
-                            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "等待机械手1资源线程计数:" + Robot.robot1.waitCount);
-                            //对依赖同一机械手的线程计数
-                            if (queueCmdRecord.id == Robot.robot1.id)
-                            {
-                                Robot.robot1.waitCount += 1;
-                            }
-                            else if (queueCmdRecord.id == Robot.robot2.id)
-                            {
-                                Robot.robot2.waitCount += 1;
-                            }
+                            Robot.robot1.parkWaitCount += 1;
+                        }
+                        else if (queueCmd.commandType == 'f')
+                        {
+                            Robot.robot1.fetchWaitCount += 1;
+                        }
+                    }
+                    else if (queueCmd.id / 6 + 1 == Robot.robot2.id)
+                    {
+                        if (queueCmd.commandType == 's')
+                        {
+                            Robot.robot2.parkWaitCount += 1;
+                        }
+                        else if (queueCmd.commandType == 'f')
+                        {
+                            Robot.robot2.fetchWaitCount += 1;
                         }
-                        queueCmdRecord = (Command)queueCmd.Clone();
                     }
-                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "线程创建:" + queueCmd.LicenseNum + "准备,等待机械手1线程个数:" + Robot.robot1.waitCount);
+                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "---线程创建:" + queueCmd.LicenseNum + "准备,等待机械手1资源停取线程计数:" + Robot.robot1.parkWaitCount + "," + Robot.robot1.fetchWaitCount);
                     Task t = Task.Factory.StartNew(() =>
                     {
-                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "线程创建:" + queueCmd.LicenseNum + "开始");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "---线程创建:" + queueCmd.LicenseNum + "开始");
                         SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
                         AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
                         abstractCmd.executeCmd(queueCmd);
-                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "线程创建:" + queueCmd.LicenseNum + "完成");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "---线程创建:" + queueCmd.LicenseNum + "完成");
                     });
                     if (t != null)
                     {
-                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "线程创建:" + queueCmd.LicenseNum + "状态:"+ t.Status);
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "---线程创建:" + queueCmd.LicenseNum + "状态:" + t.Status);
                     }
                     else
                     {
-                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "线程创建:" + queueCmd.LicenseNum + "为空");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "---线程创建:" + queueCmd.LicenseNum + "为空");
                     }
 
                 }
@@ -227,7 +232,7 @@ namespace parkMonitor.server.CoreThread
                     normalStatus = Convert.ToInt32(PLCMsg.originalPlcList[equipmentStatus_address].Value);
                 }
                 //设备总控状态
-                if (normalStatus == 1 && EntityForCore.ins.globalStatus && ParkingBufferManager.ins.checkedAuto)
+                if (normalStatus == 1 && EntityForCore.ins.globalStatus)
                 {
                     UILogServer.ins.log("设备总状态正常");
                     Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "设备总状态正常");
@@ -299,7 +304,7 @@ namespace parkMonitor.server.CoreThread
         }
         private void CheckRemotePool(object o)
         {
-            ConnectionPoolManager.CheckConnPooling(3, 10, ConnectionPoolManager.remoteConf, EntityForCore.remoteBQ);            
+            ConnectionPoolManager.CheckConnPooling(3, 10, ConnectionPoolManager.remoteConf, EntityForCore.remoteBQ);
         }
         private void CheckLocalPool(object o)
         {

+ 5 - 5
parkMonitor/server/CoreThread/QueuingThread.cs

@@ -256,7 +256,7 @@ namespace parkMonitor.server.CoreThread
                     if (ts.TotalMinutes >= bookTime)
                     {
                         //超时则释放车位,丢出指令
-                        UILogServer.ins.warn("预约指令 " + cmd.LicenseNum + " 已存在超过" + bookTime + "分钟 ,强制出队");
+                        UILogServer.ins.log("预约指令 " + cmd.LicenseNum + " 已存在超过" + bookTime + "分钟 ,强制出队");
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "预约指令 " + cmd.LicenseNum + " 已存在超过" + bookTime + "分钟 ,强制出队");
                         ParkingSpaceManager.ins.CancleBooking(cmd.LicenseNum);
                     }
@@ -283,7 +283,7 @@ namespace parkMonitor.server.CoreThread
                 //Console.WriteLine("指令已扫描时间:" + userTimeSpan.TotalSeconds);
                 if (userTimeSpan.TotalMinutes >= userTime)
                 {
-                    UILogServer.ins.warn("用户" + cmd.userID + "指令 " + cmd.LicenseNum + " 已存在超过" + String.Format("{0:F1}", userTimeSpan.TotalMinutes) + "分钟 ,强制出队");
+                    UILogServer.ins.log("用户" + cmd.userID + "指令 " + cmd.LicenseNum + " 已存在超过" + String.Format("{0:F1}", userTimeSpan.TotalMinutes) + "分钟 ,强制出队");
                     Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "用户指令 " + cmd.LicenseNum + " 已存在超过" + String.Format("{0:F1}", userTimeSpan.TotalMinutes) + "分钟 ,强制出队");
                     //cmd.LicenseNum = "";
                     cmd.commandType = 'e';
@@ -319,7 +319,7 @@ namespace parkMonitor.server.CoreThread
                     if (licTimeSpan.TotalMinutes >= licenseTime)
                     {
                         //异常号牌不再入队,而是界面提示管理员,并让号牌机线程
-                        UILogServer.ins.warn("号牌 " + node.LicenseNum + " 已扫描超过" + String.Format("{0:F1}", licTimeSpan.TotalMinutes) + "分钟 ,强制出队");
+                        UILogServer.ins.log("号牌 " + node.LicenseNum + " 已扫描超过" + String.Format("{0:F1}", licTimeSpan.TotalMinutes) + "分钟 ,强制出队");
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "号牌 " + node.LicenseNum + " 已扫描超过" + String.Format("{0:F1}", licTimeSpan.TotalMinutes) + "分钟 ,强制出队");
                         //停车完成,将相应车牌复位
                         NumberMachineMessage numberMachineMessage = new NumberMachineMessage();
@@ -430,7 +430,7 @@ namespace parkMonitor.server.CoreThread
                     else
                     {
                         UILogServer.ins.info("任务:取出号牌为 " + cmd.LicenseNum + " 的车辆,开始排队");
-                        Log.WriteLog(LogType.NOT_DATABASE, "取车命令:" + cmd.LicenseNum + "已进入可执行队列");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "取车命令:" + cmd.LicenseNum + "已进入可执行队列");
                         ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                     }
                 }
@@ -447,7 +447,7 @@ namespace parkMonitor.server.CoreThread
                     else
                     {
                         UILogServer.ins.info("任务:存入号牌为 " + cmd.LicenseNum + " 的车辆,开始排队");
-                        Log.WriteLog(LogType.NOT_DATABASE, "停车命令:" + cmd.LicenseNum + "已进入可执行队列");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "停车命令:" + cmd.LicenseNum + "已进入可执行队列");
                         ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                     }
                 }

+ 4 - 2
parkMonitor/server/CoreThread/Robot.cs

@@ -17,13 +17,15 @@ namespace parkMonitor.server.CoreThread
         public int fetching_start_addr { get; set; }
         public int fetching_start_value { get; set; }
         public bool occupied { get; set; }
-        public int waitCount { get; set; }
+        public int parkWaitCount { get; set; }
+        public int fetchWaitCount { get; set; }
         public static Robot robot1 = new Robot(1);
         public static Robot robot2 = new Robot(2);
         public Robot(int id)
         {
             this.id = id;
-            waitCount = 0;
+            parkWaitCount = 0;
+            fetchWaitCount = 0;
             occupied = false;
         }
     }

+ 18 - 15
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -339,6 +339,8 @@ namespace parkMonitor.server
                 }
                 else
                 {
+                    //plc掉线则将系统暂停
+                    EntityForCore.ins.globalStatus = false;
                     if (linkCount-- >= 0)
                     {
                         Task.Factory.StartNew(() =>
@@ -359,6 +361,7 @@ namespace parkMonitor.server
                                 Thread.Sleep(10000);
                                 if (isConnection)
                                 {
+                                    EntityForCore.ins.globalStatus = true;
                                     linkCount = 0;
                                     break;
                                 }
@@ -475,7 +478,7 @@ namespace parkMonitor.server
             busTcpClient = new ModBusTcpClient(ipString, port, station);
             try
             {
-                if(busTcpClient != null)
+                if (busTcpClient != null)
                 {
                     OperateResult connect = busTcpClient.ConnectServer();
                     if (connect.IsSuccess)
@@ -492,7 +495,7 @@ namespace parkMonitor.server
                         isConnection = false;
                     }
                 }
-              
+
             }
             catch (Exception ex)
             {
@@ -851,19 +854,19 @@ namespace parkMonitor.server
                 }
             });
 
-            ////模拟plc与激光自动操作
-            //Task.Factory.StartNew(() =>
-            //{
-            //    laserAnim();
-            //});
-            //Task.Factory.StartNew(() =>
-            //{
-            //    wheelbaseAnim();
-            //});
-            //Task.Factory.StartNew(() =>
-            //{
-            //    autoCycling();
-            //});
+            //模拟plc与激光自动操作
+            Task.Factory.StartNew(() =>
+            {
+                laserAnim();
+            });
+            Task.Factory.StartNew(() =>
+            {
+                wheelbaseAnim();
+            });
+            Task.Factory.StartNew(() =>
+            {
+                autoCycling();
+            });
         }
 
         /// <summary>