Parcourir la source

Merge remote-tracking branch 'yct/dev' into dev

liuxin il y a 7 ans
Parent
commit
dc1fb75786

+ 1 - 1
parkMonitor/App.config

@@ -30,7 +30,7 @@
     <!--PLC基本配置-->
     <!--<add key="PLC_ip_address" value="192.168.0.10" />-->
     <add key="PLC_ip_address" value="127.0.0.1" />
-    <add key="PLC_port" value="502" />
+    <add key="PLC_port" value="30000" />
     <add key="PLC_station" value="1" />
     <add key="PLC_start_address" value="0" />
     <add key="PLC_address_length" value="104" />

+ 3 - 0
parkMonitor/entity/AbstractMessage.cs

@@ -198,6 +198,7 @@ namespace parkMonitor.entity
         public int id { get; set; }
         public int status { get; set; }
         public bool recorded { get; set; }
+        public bool abort_rescan { get; set; }
         public Data data;
         public LaserMessage()
         {
@@ -207,6 +208,7 @@ namespace parkMonitor.entity
         {
             this.id = id;
             this.status = status;
+            abort_rescan = false;
             data = new Data();
         }
 
@@ -217,6 +219,7 @@ namespace parkMonitor.entity
             lm.status = status;
             lm.data = (Data)data.Clone();
             lm.recorded = recorded;
+            lm.abort_rescan = abort_rescan;
             return lm;
         }
     }

+ 55 - 109
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -16,6 +16,7 @@ namespace parkMonitor.server.CoreThread
 {
     public abstract class AbstractCmd
     {
+        public static bool isClosing { get; set; }
         public int equipmentStatus_address { set; get; }
         public int park_completed_address { set; get; }
         public int parkingEntX { set; get; }
@@ -63,10 +64,55 @@ namespace parkMonitor.server.CoreThread
             //车位分配
             c = new CEntrance();
             aps = new AllotParkingSpace();
-            robot = new Robot();
+            robot = new Robot()
+            {
+                id = 1,
+                parking_start_addr = parking_startRobot_address,
+                fetching_start_addr = fetching_startRobot_address
+            };
             locationOper = new DBLocationOperator();
         }
 
+        public void WaitForRobotResource(PLCMessage PLCMsg, int robotID)
+        {
+            while (true)
+            {
+                lock (robot)
+                {
+                    PLCMsg = (PLCMessage)PLC.GetMessage();
+                    bool occupied = false;
+                    if (PLCMsg != null)
+                    {
+                        if (robotID == 1)
+                        {
+                            try
+                            {
+                                robot.parking_start_value = Convert.ToInt32(PLCMsg.originalPlcList[parking_startRobot_address].Value);
+                                robot.fetching_start_value = Convert.ToInt32(PLCMsg.originalPlcList[fetching_startRobot_address].Value);
+                                //刷新机械手资源状态值
+                                if (robot.parking_start_value == 0 && robot.fetching_start_value == 0)
+                                {
+                                    occupied = false;
+                                }
+                                else
+                                {
+                                    occupied = true;
+                                }
+                            }
+                            catch { }
+                        }
+                    }
+                    if (occupied)
+                    {
+                        Thread.Sleep(3000);
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+        }
     }
 
     public class StopCmd : AbstractCmd
@@ -148,6 +194,7 @@ namespace parkMonitor.server.CoreThread
                     {
                         break;
                     }
+                    if (isClosing) { return; }
                     Thread.Sleep(200);
                 }
             });
@@ -216,7 +263,7 @@ namespace parkMonitor.server.CoreThread
                                     //判断车辆检测结果,
                                     if (disappeared)
                                     {
-                                        lm.status = 7;
+                                        lm.abort_rescan = true;
                                         jumpOut = true;
                                         break;
                                     }
@@ -248,7 +295,7 @@ namespace parkMonitor.server.CoreThread
                             break;
                         }
                     }
-                    Thread.Sleep(100 + (new Random()).Next(2, 10) * 300);
+                    Thread.Sleep(1000);
                 }
             });
 
@@ -265,68 +312,8 @@ namespace parkMonitor.server.CoreThread
             robotID = queueCmd.id / 3 + 1;
             Task robotFree = Task.Factory.StartNew(() =>
             {
-                while (true)
-                {
-                    lock (robot)
-                    {
-                        Thread.Sleep(1000 + (new Random()).Next(2, 10) * 300);//加入随机数,避免同时读写
-                        PLCMsg = (PLCMessage)PLC.GetMessage();
-                        bool occupied = false;
-                        if (PLCMsg != null)
-                        {
-                            if (robotID == 1)
-                            {
-                                try
-                                {
-                                    if (Convert.ToInt32(PLCMsg.originalPlcList[parking_startRobot_address].Value) == 0 && Convert.ToInt32(PLCMsg.originalPlcList[fetching_startRobot_address].Value) == 0)
-                                    {
-                                        occupied = false;
-                                    }
-                                    else
-                                    {
-                                        occupied = true;
-                                    }
-                                }
-                                catch
-                                {
-
-                                }
-                            }
-                            //foreach (PLCNode p in PLCMsg.plcList)
-                            //{
-                            //    int addr = Convert.ToInt32(p.Address);
-                            //    int value = Convert.ToInt32(p.Value);
-                            //    //if (addr == parking_startRobot_address||addr == fetching_startRobot_address)
-                            //    //{
-                            //    //    robot.Address = addr;
-                            //    //    robot.Value = value;
-                            //    //}
-                            //    if (addr == parking_startRobot_address && value == 1)
-                            //    {
-                            //        occupied = true;
-                            //    }
-                            //    if (addr == fetching_startRobot_address && value == 1)
-                            //    {
-                            //        occupied = true;
-                            //    }
-                            //}
-                        }
-                        //if (robot.Value == 1)
-                        //{
-                        //    Thread.Sleep(6000);
-                        //    //break;
-                        //}
-                        if (occupied)
-                        {
-                            Thread.Sleep(500+(new Random()).Next(0,10) * 150);//加入随机数,避免同时读写
-                        }
-                        else
-                        {
-                            //Thread.Sleep(6000);
-                            break;
-                        }
-                    }
-                }
+                //需要先遍历robot数组,根据id找到对应机械手
+                WaitForRobotResource(PLCMsg, robotID);
             });
             robotFree.Wait();
             status = 2;
@@ -487,52 +474,11 @@ namespace parkMonitor.server.CoreThread
             int status = 4;//取车
 
             ParkingMessage pm = new ParkingMessage();
+            int robotID = 0;
+            robotID = parkingSpaceID / 15 + 1;
             Task robotFree = Task.Factory.StartNew(() =>
             {
-                lock (robot)
-                {
-                    while (true)
-                    {
-                        PLCMsg = (PLCMessage)PLC.GetMessage();
-                        bool occupied = false;
-                        if (PLCMsg != null)
-                        {
-                            foreach (PLCNode p in PLCMsg.originalPlcList)
-                            {
-                                int addr = Convert.ToInt32(p.Address);
-                                int value = Convert.ToInt32(p.Value);
-                                if (addr == parking_startRobot_address && value == 1)
-                                {
-                                    occupied = true;
-                                }
-                                if (addr == fetching_startRobot_address && value == 1)
-                                {
-                                    occupied = true;
-                                }
-                            }
-                        }
-                        if (occupied)
-                        {
-                            Thread.Sleep(5000);
-                        }
-                        else
-                        {
-                            //Thread.Sleep(6000);
-                            break;
-                        }
-                        //        if (addr == fetching_startRobot_address)
-                        //        {
-                        //            robot.Address = addr;
-                        //            robot.Value = value;
-                        //        }
-                        //    }
-                        //}
-                        //if (robot.Value == 0)
-                        //{
-                        //    break;
-                        //}
-                    }
-                }
+                WaitForRobotResource(PLCMsg, robotID);
             });
             robotFree.Wait();
 

+ 1 - 0
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -83,6 +83,7 @@ namespace parkMonitor.server.CoreThread
                     equip.Stop();
                 }
             }
+            AbstractCmd.isClosing = true;//停止运行中指令
         }
 
         public void BeginWorking()

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

@@ -8,7 +8,10 @@ namespace parkMonitor.server.CoreThread
 {
     public class Robot
     {
-        public int Address { get; set; }
-        public int Value { get; set; }
+        public int id { get; set; }
+        public int parking_start_addr { get; set; }
+        public int parking_start_value { get; set; }
+        public int fetching_start_addr { get; set; }
+        public int fetching_start_value { get; set; }
     }
 }

+ 5 - 4
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -745,6 +745,7 @@ namespace parkMonitor.server
                     //after status 0, start to check laser heartbeat
                     if (value == 0)
                     {
+                        laserMsg.abort_rescan = false;//就绪状态设置允许重测
                         laser_heartbeat_test = true;
                     }
 
@@ -766,7 +767,7 @@ namespace parkMonitor.server
                             enable_status_check = false;
                             Task t = Task.Factory.StartNew(() =>
                             {
-                                Thread.Sleep(3000);
+                                Thread.Sleep(500);
                                 if (plc == null)
                                 {
                                     plc = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
@@ -780,8 +781,8 @@ namespace parkMonitor.server
                                         PLCNode pn = new PLCNode(laser_start_address.ToString(), "0");
                                         plc.SetMessage(pn);
                                         Thread.Sleep(1000);
-                                        //非7状态,车未开走,停车指令归零后置1
-                                        if (laserMsg.status != 7)
+                                        //未终止重测,车未开走,停车指令归零后置1
+                                        if (!laserMsg.abort_rescan)
                                         {
                                             UILogServer.ins.error("激光" + laserMsg.id + "计算异常,重新测量");
                                             pn = new PLCNode(laser_start_address.ToString(), "1");
@@ -793,7 +794,7 @@ namespace parkMonitor.server
                                             laserMsg.status = 6;
                                         }
                                     }
-                                    Thread.Sleep(3000);
+                                    Thread.Sleep(500);
                                 }
                                 enable_status_check = true;
                             });