Procházet zdrojové kódy

车位分配步骤加锁,自动化测试结构调整

yc_t před 7 roky
rodič
revize
74f050f7cd

+ 2 - 2
parkMonitor/App.config

@@ -16,7 +16,7 @@
   </Equipments>
   <appSettings>
     <!--数据库连接配置文件-->
-    <add key="SqlConnectionLocation" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;pwd=jingwang1995;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
+    <add key="SqlConnectionLocation" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;pwd=yct;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
     <!--<add key="SqlConnectionStr" value="Data Source=52.77.33.102;port=3306;uid=Ubuntu1;pooling=true;pwd=12345678;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->
     <add key="SqlConnectionStr" value="Data Source=59.175.148.85;port=3306;uid=root;pooling=true;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
     <add key="localGarageId" value="1"/>
@@ -66,7 +66,7 @@
     <add key="licenseTime" value="30" />
     <add key="userTime" value="30" />
     <!--上位机(Web线程)IP地址及配置serverScoket的端口-->
-    <add key="WebConfig" value="192.168.111.84:9000" />
+    <add key="WebConfig" value="192.168.111.254:9000" />
     <!--<add key ="WebConfig" value="127.0.0.1:9000"/>-->
 
     <!--车库入口-->

+ 20 - 26
parkMonitor/DataBase/DBOperation.cs

@@ -18,7 +18,7 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 garageFreeSpace = reader.GetInt32("garageFreeSpace");
             }
@@ -39,20 +39,16 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 for (int i = 1; i <= count; i++)
                 {
-                    int parkingSpaceID = reader.GetInt32("parkingSpaceID");
-                    int parkingSpaceX = reader.GetInt32("parkingSpaceX");
-                    int parkingSpaceY = reader.GetInt32("parkingSpaceY");
-                    int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
                     Parking_Space ps = new Parking_Space();
-                    ps.parkingSpaceID = parkingSpaceID;
+                    ps.parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                    ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                    ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                    ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
                     ps.garageID = garageID;
-                    ps.parkingSpaceX = parkingSpaceX;
-                    ps.parkingSpaceY = parkingSpaceY;
-                    ps.parkingSpaceZ = parkingSpaceZ;
                     lps.Add(i, ps);
                 }
             }
@@ -139,7 +135,7 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 int parkingSpaceID = reader.GetInt32("parkingSpaceID");
                 int garageID = reader.GetInt32("garageID");
@@ -159,29 +155,27 @@ namespace parkMonitor.DataBase
         }
 
         //根据车位id获得x,y,z
-        public Fetching_Space GetFetchingSpace(string connectionStr, int parkingSpaceID)
+        public Parking_Space GetFetchingSpace(string connectionStr, int parkingSpaceID)
         {
-            Fetching_Space fs = new Fetching_Space();
+            Parking_Space ps = new Parking_Space();
             MySqlDataReader reader = null;
             string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
-                int parkingSpaceX = reader.GetInt32("parkingSpaceX");
-                int parkingSpaceY = reader.GetInt32("parkingSpaceY");
-                int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
-                fs.parkingSpaceX = parkingSpaceX;
-                fs.parkingSpaceY = parkingSpaceY;
-                fs.parkingSpaceZ = parkingSpaceZ;
+                ps.parkingSpaceID = parkingSpaceID;
+                ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
             }
             else
             {
                 Console.WriteLine("查无结果");
             }
             oper.DBClose();
-            return fs;
+            return ps;
         }
 
         //查询手机号是否被注册
@@ -226,7 +220,7 @@ namespace parkMonitor.DataBase
             int count = 0;
             Operation oper = new Operation(connectionStr, sql);
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 userID = reader.GetInt32("userID");
             }
@@ -247,7 +241,7 @@ namespace parkMonitor.DataBase
             int count = 0;
             Operation oper = new Operation(connectionStr, sql);
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 parkingRecordsID = reader.GetInt32("parkingRecordsID");
             }
@@ -268,7 +262,7 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 isNumberPlate = true;
             }
@@ -319,7 +313,7 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 isNumberPlateFromVehicle = true;
             }
@@ -349,7 +343,7 @@ namespace parkMonitor.DataBase
             Operation oper = new Operation(connectionStr, sql);
             int count = 0;
             reader = oper.getResultSet(ref count);
-            if (count > 0)
+            if (count > 0 && reader.Read())
             {
                 int parkingSpaceID = reader.GetInt32("parkingSpaceID");
                 int frontwheelbase = reader.GetInt32("frontwheelbase");

+ 1 - 7
parkMonitor/DataBase/Parking_Space.cs

@@ -8,6 +8,7 @@ namespace parkMonitor.DataBase
 {
     public class Parking_Space
     {
+        public static Object spaceLock = new Object();
         public int parkingSpaceID { get; set; }
         //public float parkingSpaceWeight { get; set; }
         public int garageID { get; set; }
@@ -16,11 +17,4 @@ namespace parkMonitor.DataBase
         public int parkingSpaceY { get; set; }
         public int parkingSpaceZ { get; set; }
     }
-
-    public class Fetching_Space
-    {
-        public int parkingSpaceX { get; set; }
-        public int parkingSpaceY { get; set; }
-        public int parkingSpaceZ { get; set; }
-    }
 }

+ 34 - 28
parkMonitor/manualParking/ManualParkingSimul.cs

@@ -17,10 +17,10 @@ namespace parkMonitor
         private const string userId = "18202736439";
         private const string garageId = "1";
         private const string header = "鄂A";
-        private const int licInterval = 60000;//90秒
+        private const int licInterval = 30000;//90秒
         private Random rnd;
         private Dictionary<int, CarStatusStru> numStatusMap = new Dictionary<int, CarStatusStru>();
-        Command storeCmd = new Command();
+        Command executableCmd = new Command();
         IEquipments queue;
         DBOperation oper = new DBOperation();
 
@@ -46,29 +46,30 @@ namespace parkMonitor
         public void Store(string lic)
         {
             string connectionStr = "SqlConnectionLocation";
-            storeCmd.manual = true;
-            storeCmd.commandType = 's';
-            storeCmd.userID = oper.GetUserID(connectionStr,userId).ToString();
-            storeCmd.LicenseNum = lic;
+            executableCmd.manual = true;
+            executableCmd.commandType = 's';
+            executableCmd.userID = oper.GetUserID(connectionStr, userId).ToString();
+            executableCmd.LicenseNum = lic;
+            executableCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             try
             {
-                storeCmd.garageID = Convert.ToInt32(garageId);
+                executableCmd.garageID = Convert.ToInt32(garageId);
             }
             catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
             int garageFreeSpace = 0;
-            bool isTelRegister = oper.IsTelRegister(connectionStr,userId);
+            bool isTelRegister = oper.IsTelRegister(connectionStr, userId);
             if (isTelRegister == false)
             {
                 UILogServer.ins.error("该号码未被注册,请先注册");
             }
-            else if (storeCmd.garageID != 0)
+            else if (executableCmd.garageID != 0)
             {
-                garageFreeSpace = oper.getGarageFreeSpace(connectionStr,storeCmd.garageID);
+                garageFreeSpace = oper.getGarageFreeSpace(connectionStr, executableCmd.garageID);
                 if (garageFreeSpace > 0)
                 {
-                    if (storeCmd.userID != "" && storeCmd.LicenseNum != "")
+                    if (executableCmd.userID != "" && executableCmd.LicenseNum != "")
                     {
-                        queue.SetMessage((Command)storeCmd.Clone());
+                        queue.SetMessage((Command)executableCmd.Clone());
                         UILogServer.ins.info("发送成功");
                     }
                 }
@@ -82,18 +83,18 @@ namespace parkMonitor
         public void Fetch(string lic)
         {
             string connectionStr = "SqlConnectionLocation";
-            storeCmd.manual = true;
-            storeCmd.commandType = 'f';
-            storeCmd.userID = oper.GetUserID(connectionStr,userId).ToString();
-            storeCmd.LicenseNum = lic;
-            storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            executableCmd.manual = true;
+            executableCmd.commandType = 'f';
+            executableCmd.userID = oper.GetUserID(connectionStr, userId).ToString();
+            executableCmd.LicenseNum = lic;
+            executableCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             try
             {
-                storeCmd.garageID = Convert.ToInt32(garageId);
+                executableCmd.garageID = Convert.ToInt32(garageId);
             }
             catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
-            bool isTelRegister = oper.IsTelRegister(connectionStr,userId);
-            bool isNumberPlate = oper.IsNumberPlate(connectionStr,storeCmd.LicenseNum, storeCmd.garageID);
+            bool isTelRegister = oper.IsTelRegister(connectionStr, userId);
+            bool isNumberPlate = oper.IsNumberPlate(connectionStr, executableCmd.LicenseNum, executableCmd.garageID);
             if (isTelRegister == false)
             {
                 UILogServer.ins.error("该号码未被注册,请先注册");
@@ -104,10 +105,10 @@ namespace parkMonitor
             }
             else
             {
-                storeCmd.parkingRecordsID = oper.GetParkingRecordsID(connectionStr,storeCmd.LicenseNum);
-                if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
+                executableCmd.parkingRecordsID = oper.GetParkingRecordsID(connectionStr, executableCmd.LicenseNum);
+                if (executableCmd.userID != "" && executableCmd.LicenseNum != "" && executableCmd.parkingRecordsID != 0)
                 {
-                    queue.SetMessage((Command)storeCmd.Clone());
+                    queue.SetMessage((Command)executableCmd.Clone());
                     UILogServer.ins.info("发送成功");
                 }
                 else
@@ -125,18 +126,23 @@ namespace parkMonitor
                 rnd = new Random(DateTime.Now.Millisecond);
                 if (numStatusMap.Count > 0)
                 {
-                    int index = rnd.Next(0, numStatusMap.Count);
-                    int status = numStatusMap[index].status;
-                    if(status == 0)
+                    int index = -1, status = -1, count = numStatusMap.Count;
+                    do
+                    {
+                        index = rnd.Next(0, numStatusMap.Count);
+                        status = numStatusMap[index].status;
+                    } while (count-- > 0 && status != 0 && status != 1);
+                    if (status == 0)
                     {
                         Store(numStatusMap[index].licNum);
                         numStatusMap[index].status = 2;
                     }
-                    else if(status == 1)
+                    else if (status == 1)
                     {
                         Fetch(numStatusMap[index].licNum);
                         numStatusMap[index].status = 3;
                     }
+
                 }
                 Thread.Sleep(licInterval);
             }
@@ -149,7 +155,7 @@ namespace parkMonitor
             {
                 numStatusMap[index].status = 1;
             }
-            else if(status == 3)
+            else if (status == 3)
             {
                 numStatusMap[index].status = 0;
             }

+ 156 - 157
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -155,25 +155,25 @@ namespace parkMonitor.server.CoreThread
             if (!queueCmd.manual)
             {
                 connectionStr = "SqlConnectionStr";
-                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,queueCmd.garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, queueCmd.garageID);
                 if (isParking)
                 {
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                    oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
                     if (parkingSpaceUpdated)
                     {
                         freeSpaceCount = freeSpaceCount + 1;
-                        oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, queueCmd.garageID);
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, queueCmd.garageID);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                 }
                 else
-                {                   
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 1);
+                {
+                    oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 1);
                     if (parkingSpaceUpdated)
                     {
                         freeSpaceCount = freeSpaceCount - 1;
-                        oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, queueCmd.garageID);
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
+                        oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, queueCmd.garageID);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 1);
                     }
                 }
             }
@@ -182,18 +182,18 @@ namespace parkMonitor.server.CoreThread
                 connectionStr = "SqlConnectionLocation";
                 if (isParking)
                 {
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                    oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
                     if (parkingSpaceUpdated)
                     {
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                 }
                 else
                 {
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 1);
+                    oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 1);
                     if (parkingSpaceUpdated)
                     {
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 1);
                     }
                 }
             }
@@ -393,7 +393,7 @@ namespace parkMonitor.server.CoreThread
         /// <summary>
         /// 停车完成
         /// </summary>
-        private bool WaitForStoreCompletionSignal(Command queueCmd, ref int parkingSpaceID, ref bool robotError, int status)
+        private bool WaitForStoreCompletionSignal(Command queueCmd, int parkingSpaceID, ref bool robotError, int status)
         {
             string connectionStr = null;
             PLCMessage PLCMsg = null;
@@ -418,12 +418,12 @@ namespace parkMonitor.server.CoreThread
                     if (!queueCmd.manual)
                     {
                         connectionStr = "SqlConnectionStr";
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                     else
                     {
                         connectionStr = "SqlConnectionLocation";
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                     break;
                 }
@@ -510,95 +510,102 @@ namespace parkMonitor.server.CoreThread
             Log.WriteLog("停车流程,车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");
             UILogServer.ins.info("停车流程,车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");
 
-            //获取车位资源
+            //车位分配数据库操作加锁,直到启动机械手
             Parking_Space ppp = new Parking_Space();
-            ppp = WaitForParkingSpaceResource(queueCmd);
-
-            //过期号牌判断
-            if (queueCmd.userID != "")
+            Data dataReal = new Data();
+            int garageID;
+            string realParkTime;
+            lock (Parking_Space.spaceLock)
             {
-                userID = Convert.ToInt32(queueCmd.userID);
-            }
-            int garageID = queueCmd.garageID;
-            string realParkTime = queueCmd.TimeRecord;
-            //定义号牌验证与机械手异常标志
-            //Task checkNum = Task.Factory.StartNew(() =>
-            //{
-            //    DateTime startTime = DateTime.Now;
-            //    DateTime endTime = DateTime.Now;
-            //    TimeSpan t = startTime - endTime;
-            //    while (!stopChecking && t.TotalSeconds <= 600)
-            //    {
-            //        //号牌验证,异常则退回队列
-            //        Func<Command, int, float, bool> numValidationResult = new Func<Command, int, float, bool>(NumValidation);
-            //        IAsyncResult result = numValidationResult.BeginInvoke(queueCmd, 10, 0.7f, null, null);
-            //        bool checkResult = numValidationResult.EndInvoke(result);
-            //        if (stopChecking)
-            //        {
-            //            return;
-            //        }
-            //        if (!checkResult)
-            //        {
-            //            UILogServer.ins.info("停车命令" + queueCmd.LicenseNum + " 与当前车辆不一致");
-            //            disappeared = true;
-            //            return;
-            //            //未能停车,将车辆状态复位
-            //            //oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
-            //        }
-            //        endTime = DateTime.Now;
-            //        t = startTime - endTime;
-            //    }
-            //});
+                //获取车位资源
+                ppp = WaitForParkingSpaceResource(queueCmd);
 
-            Data dataReal = new Data();
-            dataReal = WaitForLaserResource(queueCmd, disappeared);
+                //过期号牌判断
+                if (queueCmd.userID != "")
+                {
+                    userID = Convert.ToInt32(queueCmd.userID);
+                }
+                garageID = queueCmd.garageID;
+                realParkTime = queueCmd.TimeRecord;
+                //定义号牌验证与机械手异常标志
+                //Task checkNum = Task.Factory.StartNew(() =>
+                //{
+                //    DateTime startTime = DateTime.Now;
+                //    DateTime endTime = DateTime.Now;
+                //    TimeSpan t = startTime - endTime;
+                //    while (!stopChecking && t.TotalSeconds <= 600)
+                //    {
+                //        //号牌验证,异常则退回队列
+                //        Func<Command, int, float, bool> numValidationResult = new Func<Command, int, float, bool>(NumValidation);
+                //        IAsyncResult result = numValidationResult.BeginInvoke(queueCmd, 10, 0.7f, null, null);
+                //        bool checkResult = numValidationResult.EndInvoke(result);
+                //        if (stopChecking)
+                //        {
+                //            return;
+                //        }
+                //        if (!checkResult)
+                //        {
+                //            UILogServer.ins.info("停车命令" + queueCmd.LicenseNum + " 与当前车辆不一致");
+                //            disappeared = true;
+                //            return;
+                //            //未能停车,将车辆状态复位
+                //            //oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                //        }
+                //        endTime = DateTime.Now;
+                //        t = startTime - endTime;
+                //    }
+                //});
 
-            //判断车位与激光资源有效性,无效则回滚
-            if (ppp == null || dataReal == null)
-            {
-                Rollback(queueCmd, ppp.parkingSpaceID, false, true);
-                return;
-            }
-            //车位赋值与写数据库
-            int parkingSpaceID = ppp.parkingSpaceID;
-            int parkingSpaceX = ppp.parkingSpaceX;
-            int parkingSpaceY = ppp.parkingSpaceY;
-            int parkingSpaceZ = ppp.parkingSpaceZ;
-            if (!queueCmd.manual)
-            {
-                connectionStr = "SqlConnectionStr";
-                //更新云端车位表车位状态
-                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
-                //更新车库表剩余车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
-                freeSpaceCount = freeSpaceCount - 1;
-                oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
-            }
-            else
-            {
-                connectionStr = "SqlConnectionLocation";
-                //更新本地车位表车位状态
-                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
-                //更新车库表剩余车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
-                freeSpaceCount = freeSpaceCount - 1;
-                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
-            }
-            //号牌失效,数据库回滚
-            if (disappeared)
-            {
-                NumReset(queueCmd);
+                dataReal = WaitForLaserResource(queueCmd, disappeared);
+
+                //判断车位与激光资源有效性,无效则回滚
+                if (ppp == null || dataReal == null)
+                {
+                    Rollback(queueCmd, ppp.parkingSpaceID, false, true);
+                    return;
+                }
+
+                //车位赋值与写数据库
+                int parkingSpaceID = ppp.parkingSpaceID;
+                int parkingSpaceX = ppp.parkingSpaceX;
+                int parkingSpaceY = ppp.parkingSpaceY;
+                int parkingSpaceZ = ppp.parkingSpaceZ;
                 if (!queueCmd.manual)
                 {
                     connectionStr = "SqlConnectionStr";
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                    //更新云端车位表车位状态
+                    oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 1);
+                    //更新车库表剩余车位数
+                    int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
+                    freeSpaceCount = freeSpaceCount - 1;
+                    oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
                 }
                 else
                 {
                     connectionStr = "SqlConnectionLocation";
-                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                    //更新本地车位表车位状态
+                    oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 1);
+                    //更新车库表剩余车位数
+                    int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
+                    freeSpaceCount = freeSpaceCount - 1;
+                    oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
+                }
+                //号牌失效,数据库回滚
+                if (disappeared)
+                {
+                    NumReset(queueCmd);
+                    if (!queueCmd.manual)
+                    {
+                        connectionStr = "SqlConnectionStr";
+                        oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
+                    }
+                    else
+                    {
+                        connectionStr = "SqlConnectionLocation";
+                        oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
+                    }
+                    return;
                 }
-                return;
             }
             //开始启动机械手,停止检测号牌
             stopChecking = true;
@@ -611,7 +618,7 @@ namespace parkMonitor.server.CoreThread
 
             if (!WaitForRobotResource(robotID))
             {
-                Rollback(queueCmd, parkingSpaceID, true, true);
+                Rollback(queueCmd, ppp.parkingSpaceID, true, true);
                 return;
             }
 
@@ -627,22 +634,22 @@ namespace parkMonitor.server.CoreThread
             cm.length = Convert.ToString(dataReal.length);
             cm.width = Convert.ToString(dataReal.width);
             cm.height = Convert.ToString(dataReal.height);
-            cm.parkingSpaceID = Convert.ToString(parkingSpaceID);
-            cm.parkingSpaceX = Convert.ToString(parkingSpaceX);
-            cm.parkingSpaceY = Convert.ToString(parkingSpaceY);
-            cm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
+            cm.parkingSpaceID = Convert.ToString(ppp.parkingSpaceID);
+            cm.parkingSpaceX = Convert.ToString(ppp.parkingSpaceX);
+            cm.parkingSpaceY = Convert.ToString(ppp.parkingSpaceY);
+            cm.parkingSpaceZ = Convert.ToString(ppp.parkingSpaceZ);
             PLC.SetMessage(cm);
             Log.WriteLog("停车流程,抓车:" + queueCmd.LicenseNum);
             UILogServer.ins.info("停车流程,抓车:" + queueCmd.LicenseNum);
 
             if (!WaitWheelbase(ref frontWheelbase, ref rearWheelbase))
             {
-                Rollback(queueCmd, parkingSpaceID, true, true);
+                Rollback(queueCmd, ppp.parkingSpaceID, true, true);
                 return;
             }
-            if (!WaitForStoreCompletionSignal(queueCmd, ref parkingSpaceID, ref robotError, 1))
+            if (!WaitForStoreCompletionSignal(queueCmd, ppp.parkingSpaceID, ref robotError, 1))
             {
-                Rollback(queueCmd, parkingSpaceID, true, true);
+                Rollback(queueCmd, ppp.parkingSpaceID, true, true);
                 return;
             }
 
@@ -651,9 +658,9 @@ namespace parkMonitor.server.CoreThread
             cm.status = status;
             PLC.SetMessage(cm);
             //机械手异常则回滚
-            if (!WaitForStoreCompletionSignal(queueCmd, ref parkingSpaceID, ref robotError, 0))
+            if (!WaitForStoreCompletionSignal(queueCmd, ppp.parkingSpaceID, ref robotError, 0))
             {
-                Rollback(queueCmd, parkingSpaceID, true, true);
+                Rollback(queueCmd, ppp.parkingSpaceID, true, true);
                 return;
             }
 
@@ -677,17 +684,17 @@ namespace parkMonitor.server.CoreThread
                     connectionStr = "SqlConnectionStr";
                     //更新云端数据库
                     //插入停车记录表
-                    int parkingRecordsID = oper.InsertToParkingRecords(connectionStr,userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
+                    int parkingRecordsID = oper.InsertToParkingRecords(connectionStr, userID, numberPlate, ppp.parkingSpaceID, ppp.garageID, 3, realParkTime);
                     //车辆表更新车辆信息
-                    oper.UpdateVehicle(connectionStr,numberPlate, 1, realParkTime, parkingRecordsID, parkingSpaceID, 1, frontWheelbase, rearWheelbase);
+                    oper.UpdateVehicle(connectionStr, numberPlate, 1, realParkTime, parkingRecordsID, ppp.parkingSpaceID, 1, frontWheelbase, rearWheelbase);
                     //插入消息队列表
-                    oper.InsertToMessageQueue(connectionStr,userID, "停车成功", 1);
+                    oper.InsertToMessageQueue(connectionStr, userID, "停车成功", 1);
                 }
                 else
                 {
                     connectionStr = "SqlConnectionLocation";
                     //插入停车记录表
-                    int parkingRecordsID = oper.InsertToLocalParkingRecords(connectionStr,1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
+                    int parkingRecordsID = oper.InsertToLocalParkingRecords(connectionStr, 1, userID, numberPlate, ppp.parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
                 }
             }
             //异常写入日志文件
@@ -696,10 +703,10 @@ namespace parkMonitor.server.CoreThread
                 LogFile logFile = LogFile.ERROR_NUMBERPLATE;
                 Log.WriteLog(logFile, "号牌:" + numberPlate);
                 Log.WriteLog(logFile, "入库时间:" + realParkTime);
-                Log.WriteLog(logFile, "车位id:" + parkingSpaceID);
-                Log.WriteLog(logFile, "车位x:" + parkingSpaceX);
-                Log.WriteLog(logFile, "车位y:" + parkingSpaceY);
-                Log.WriteLog(logFile, "车位z:" + parkingSpaceZ);
+                Log.WriteLog(logFile, "车位id:" + ppp.parkingSpaceID);
+                Log.WriteLog(logFile, "车位x:" + ppp.parkingSpaceX);
+                Log.WriteLog(logFile, "车位y:" + ppp.parkingSpaceY);
+                Log.WriteLog(logFile, "车位z:" + ppp.parkingSpaceZ);
                 //异常情况处理有待讨论
             }
         }
@@ -710,7 +717,7 @@ namespace parkMonitor.server.CoreThread
     /// </summary>
     public class FetchCmd : AbstractCmd
     {
-        private bool waitForFetchCompletionSignal(Command queueCmd, ref int parkingSpaceID, ref bool robotError, int status)
+        private bool waitForFetchCompletionSignal(Command queueCmd, int parkingSpaceID, ref bool robotError, int status)
         {
             string connectionStr = null;
             PLCMessage PLCMsg = null;
@@ -736,12 +743,12 @@ namespace parkMonitor.server.CoreThread
                     if (!queueCmd.manual)
                     {
                         connectionStr = "SqlConnectionStr";
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                     else
                     {
                         connectionStr = "SqlConnectionLocation";
-                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr, parkingSpaceID, 0);
                     }
                     break;
                 }
@@ -769,36 +776,38 @@ namespace parkMonitor.server.CoreThread
             string connectionStr = null;
             PLCMessage PLCMsg = null;
             Vehicle vehiclelist = null;
+            ControlMessage cm = null;
+            Parking_Space ps = null;
+            int frontwheelbase;
+            int rearwheelbase;
+            int garageID;
+            bool robotError = false;
+            //车位更新数据库操作加锁,直到启动机械手
             if (queueCmd.manual)
             {
                 connectionStr = "SqlConnectionLocation";
-                vehiclelist = oper.GetLocalVehicle(connectionStr,queueCmd.LicenseNum, queueCmd.garageID);
+                vehiclelist = oper.GetLocalVehicle(connectionStr, queueCmd.LicenseNum, queueCmd.garageID);
             }
             else
-            {             
+            {
                 connectionStr = "SqlConnectionStr";
-                vehiclelist = oper.GetVehicle(connectionStr,queueCmd.LicenseNum);
+                vehiclelist = oper.GetVehicle(connectionStr, queueCmd.LicenseNum);
             }
             int parkingSpaceID = vehiclelist.parkingSpaceID;
-            int garageID = vehiclelist.garageID;
-            int frontwheelbase = vehiclelist.frontwheelbase;
-            int rearwheelbase = vehiclelist.rearwheelbase;
-            bool robotError = false;
-            Fetching_Space fslist = null;
+            garageID = vehiclelist.garageID;
+            frontwheelbase = vehiclelist.frontwheelbase;
+            rearwheelbase = vehiclelist.rearwheelbase;
             if (queueCmd.manual)
             {
                 connectionStr = "SqlConnectionLocation";
-                fslist = oper.GetFetchingSpace(connectionStr,parkingSpaceID);
+                ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
             }
             else
             {
                 connectionStr = "SqlConnectionStr";
-                fslist = oper.GetFetchingSpace(connectionStr,parkingSpaceID);
+                ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
             }
-            int parkingSpaceX = fslist.parkingSpaceX;
-            int parkingSpaceY = fslist.parkingSpaceY;
-            int parkingSpaceZ = fslist.parkingSpaceZ;
-            ControlMessage cm = new ControlMessage();
+            cm = new ControlMessage();
 
             int robotID = 0;
             robotID = parkingSpaceID / 15 + 1;
@@ -807,17 +816,16 @@ namespace parkMonitor.server.CoreThread
                 Rollback(queueCmd, parkingSpaceID, true, false);
                 return;
             }
-
             //取车
             int status = 4;
             cm.status = status;
             //先手动赋值
             cm.RobotID = 1;
             cm.fetchPosition = 1;//放置地址
-            cm.parkingSpaceID = Convert.ToString(parkingSpaceID);
-            cm.parkingSpaceX = Convert.ToString(parkingSpaceX);
-            cm.parkingSpaceY = Convert.ToString(parkingSpaceY);
-            cm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
+            cm.parkingSpaceID = Convert.ToString(ps.parkingSpaceID);
+            cm.parkingSpaceX = Convert.ToString(ps.parkingSpaceX);
+            cm.parkingSpaceY = Convert.ToString(ps.parkingSpaceY);
+            cm.parkingSpaceZ = Convert.ToString(ps.parkingSpaceZ);
             cm.frontWheelbase = frontwheelbase;
             cm.rearWheelbase = rearwheelbase;
             PLC.SetMessage(cm);
@@ -826,9 +834,9 @@ namespace parkMonitor.server.CoreThread
             Log.WriteLog("取车:" + queueCmd.LicenseNum);
             UILogServer.ins.info("取车:" + queueCmd.LicenseNum);
             //等待PLC取车完成信号
-            if (!waitForFetchCompletionSignal(queueCmd, ref parkingSpaceID, ref robotError, 1))
+            if (!waitForFetchCompletionSignal(queueCmd, ps.parkingSpaceID, ref robotError, 1))
             {
-                Rollback(queueCmd, parkingSpaceID, true, false);
+                Rollback(queueCmd, ps.parkingSpaceID, true, false);
                 return;
             }
             //取车完成
@@ -838,16 +846,16 @@ namespace parkMonitor.server.CoreThread
             //先手动赋值
             cm2.RobotID = 1;
             PLC.SetMessage(cm2);
-            if (!waitForFetchCompletionSignal(queueCmd, ref parkingSpaceID, ref robotError, 0))
+            if (!waitForFetchCompletionSignal(queueCmd, ps.parkingSpaceID, ref robotError, 0))
             {
-                Rollback(queueCmd, parkingSpaceID, true, false);
+                Rollback(queueCmd, ps.parkingSpaceID, true, false);
                 return;
             }
             Robot.robot1.occupied = false;
             Log.WriteLog("号牌:" + queueCmd.LicenseNum + "取车完成");
             UILogServer.ins.info("号牌:" + queueCmd.LicenseNum + "取车完成");
             //自动化测试用
-            ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2,1)));
+            ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
 
             //数据库更新
             if (!queueCmd.manual)
@@ -855,38 +863,29 @@ namespace parkMonitor.server.CoreThread
                 connectionStr = "SqlConnectionStr";
                 //云端数据库更新
                 //更新车库表车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
                 freeSpaceCount = freeSpaceCount + 1;
-                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
                 //更新车位表车位状态
-                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                oper.UpdateParkingSpaceState(connectionStr, ps.parkingSpaceID, 0);
                 //更新车辆表车辆停车状态
-                oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
                 //更新停车记录表
-                oper.UpdateParkingRecords(connectionStr,6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
-
-                ////本地数据库更新
-                //locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
-                ////更新车位表车位状态
-                //locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
-                ////更新车辆表车辆停车状态
-                //locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
-                ////更新停车记录表
-                //locationOper.UpdateParkingRecords(0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
+                oper.UpdateParkingRecords(connectionStr, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
             }
             else
             {
                 connectionStr = "SqlConnectionLocation";
                 //更新车库表车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
                 freeSpaceCount = freeSpaceCount + 1;
-                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
                 //更新车位表车位状态
-                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
+                oper.UpdateParkingSpaceState(connectionStr, ps.parkingSpaceID, 0);
                 ////更新车辆表车辆停车状态
                 //locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
                 //更新停车记录表
-                oper.UpdateParkingRecords(connectionStr,0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
+                oper.UpdateParkingRecords(connectionStr, 0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
             }
         }
     }
@@ -903,9 +902,9 @@ namespace parkMonitor.server.CoreThread
             {
                 int userId = Convert.ToInt32(queueCmd.userID);
                 //过期用户指令
-                oper.InsertToMessageQueue(connectionStr,userId, "停车异常,请联系管理员!", 2);
+                oper.InsertToMessageQueue(connectionStr, userId, "停车异常,请联系管理员!", 2);
                 //未能停车,将车辆状态复位
-                oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
+                oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
                 LogFile logFile = LogFile.ERROR_NUMBERPLATE;
                 Log.WriteLog(logFile, "过期用户指令,车牌号:" + queueCmd.LicenseNum);
                 UILogServer.ins.error("过期用户指令,车牌号:" + queueCmd.LicenseNum);

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

@@ -207,7 +207,7 @@ namespace parkMonitor.server.CoreThread
                 NumberMachineNode node = LicenseQueue.Dequeue();
                 if (NumMachineNodeValidation(node))
                 {
-                    //计算时间差,超过5分钟自动出队(?处理方式待讨论),并将该Node标记为已使用,等待统一处理
+                    //计算时间差,超过时间输出提示,并将该Node标记为已使用
                     TimeSpan licTimeSpan = DateTime.Now - DateTime.Parse(node.TimeRecord);
                     if (licTimeSpan.TotalMinutes >= licenseTime)
                     {

+ 3 - 2
parkMonitor/server/NumMachine/NumMachineSimul.cs

@@ -10,7 +10,7 @@ namespace parkMonitor.server
 {
     class NumMachineSimul : IEquipments
     {
-        private const int licInterval = 60000;//90秒
+        private const int licInterval = 30000;//90秒
         ///<summary>号牌队列</summary>
         private Queue<NumberMachineNode> LicBuffer = new Queue<NumberMachineNode>();
         /// <summary>
@@ -43,6 +43,7 @@ namespace parkMonitor.server
                         {
                             if (!LicBuffer.Contains(n) && (nmMsg.aNode==null || nmMsg.aNode.LicenseNum!=n.LicenseNum))
                             {
+                                n.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                 LicBuffer.Enqueue((NumberMachineNode)n.Clone());
                             }
                             //除去已停车完成的号牌
@@ -165,7 +166,7 @@ namespace parkMonitor.server
             });
             Task.Factory.StartNew(() =>
             {
-                //ManualParkingSimul.ins = new ManualParkingSimul();
+                ManualParkingSimul.ins = new ManualParkingSimul();
             });
            
         }

+ 93 - 84
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -717,44 +717,47 @@ namespace parkMonitor.server
             bool laserWorking = false;
             while (!isClosing)
             {
-                //模拟plc与激光操作
-                foreach (PLCNode p in plcMsg.originalPlcList)
+                if (plcMsg.originalPlcList != null)
                 {
-                    int addr = Int32.Parse(p.Address);
-                    int value = Int32.Parse(p.Value);
-                    //模拟摆扫激光
-                    if (laserMgmtList.Count != 0)
+                    //模拟plc与激光操作
+                    foreach (PLCNode p in plcMsg.originalPlcList)
                     {
-                        if (addr == laser_start_address)
+                        int addr = Int32.Parse(p.Address);
+                        int value = Int32.Parse(p.Value);
+                        //模拟摆扫激光
+                        if (laserMgmtList.Count != 0)
                         {
-                            //心跳
-                            if (value == 0)
-                            {
-                                laserWorking = false;
-                                SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "254");
-                                Thread.Sleep(1000);
-                                SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "255");
-                                Thread.Sleep(1000);
-                            }
-                            //模拟测量
-                            else
+                            if (addr == laser_start_address)
                             {
-                                if (!laserWorking)
+                                //心跳
+                                if (value == 0)
                                 {
-                                    SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "1");
-                                    Thread.Sleep(500);
-                                    SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "2");
-                                    Thread.Sleep(5000);
-                                    SendtoPLC((laserMgmtList[0].laser_status_address + 1).ToString(), (new Random(DateTime.Now.Millisecond).Next(4000, 7000)).ToString());
-                                    Thread.Sleep(1);
-                                    SendtoPLC((laserMgmtList[0].laser_status_address + 2).ToString(), (new Random(DateTime.Now.Millisecond).Next(4000, 7000)).ToString());
-                                    Thread.Sleep(1);
-                                    SendtoPLC((laserMgmtList[0].laser_status_address + 3).ToString(), (new Random(DateTime.Now.Millisecond).Next(90, 150)).ToString());
-                                    Thread.Sleep(1);
-                                    SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "3");
-                                    Thread.Sleep(2000);
+                                    laserWorking = false;
+                                    SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "254");
+                                    Thread.Sleep(1000);
+                                    SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "255");
+                                    Thread.Sleep(1000);
+                                }
+                                //模拟测量
+                                else
+                                {
+                                    if (!laserWorking)
+                                    {
+                                        SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "1");
+                                        Thread.Sleep(500);
+                                        SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "2");
+                                        Thread.Sleep(5000);
+                                        SendtoPLC((laserMgmtList[0].laser_status_address + 1).ToString(), (new Random(DateTime.Now.Millisecond).Next(4000, 7000)).ToString());
+                                        Thread.Sleep(1);
+                                        SendtoPLC((laserMgmtList[0].laser_status_address + 2).ToString(), (new Random(DateTime.Now.Millisecond).Next(4000, 7000)).ToString());
+                                        Thread.Sleep(1);
+                                        SendtoPLC((laserMgmtList[0].laser_status_address + 3).ToString(), (new Random(DateTime.Now.Millisecond).Next(90, 150)).ToString());
+                                        Thread.Sleep(1);
+                                        SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "3");
+                                        Thread.Sleep(2000);
+                                    }
+                                    laserWorking = true;
                                 }
-                                laserWorking = true;
                             }
                         }
                     }
@@ -767,34 +770,37 @@ namespace parkMonitor.server
             bool working = false;
             while (!isClosing)
             {
-                //模拟plc与激光操作
-                foreach (PLCNode p in plcMsg.originalPlcList)
+                if (plcMsg.originalPlcList != null)
                 {
-                    int addr = Int32.Parse(p.Address);
-                    int value = Int32.Parse(p.Value);
-                    //模拟轮距激光
-                    if (addr == parking_startRobot_address)
+                    //模拟plc与激光操作
+                    foreach (PLCNode p in plcMsg.originalPlcList)
                     {
-                        if (value == 1)
+                        int addr = Int32.Parse(p.Address);
+                        int value = Int32.Parse(p.Value);
+                        //模拟轮距激光
+                        if (addr == parking_startRobot_address)
                         {
-                            if (!working)
+                            if (value == 1)
                             {
-                                working = true;
-                                Thread.Sleep(3000);
-                                SendtoPLC(frontWheelbase_address.ToString(), (new Random(DateTime.Now.Millisecond).Next(100, 300)).ToString());
-                                Thread.Sleep(1);
-                                SendtoPLC(rearWheelbase_address.ToString(), (new Random(DateTime.Now.Millisecond).Next(100, 300)).ToString());
-                                SendtoPLC("81", "3");
-                                Thread.Sleep(5000);
+                                if (!working)
+                                {
+                                    working = true;
+                                    Thread.Sleep(3000);
+                                    SendtoPLC(frontWheelbase_address.ToString(), (new Random(DateTime.Now.Millisecond).Next(100, 300)).ToString());
+                                    Thread.Sleep(1);
+                                    SendtoPLC(rearWheelbase_address.ToString(), (new Random(DateTime.Now.Millisecond).Next(100, 300)).ToString());
+                                    SendtoPLC("81", "3");
+                                    Thread.Sleep(5000);
+                                }
+                            }
+                            else
+                            {
+                                working = false;
+                                SendtoPLC("81", "254");
+                                Thread.Sleep(1000);
+                                SendtoPLC("81", "255");
+                                Thread.Sleep(1000);
                             }
-                        }
-                        else
-                        {
-                            working = false;
-                            SendtoPLC("81", "254");
-                            Thread.Sleep(1000);
-                            SendtoPLC("81", "255");
-                            Thread.Sleep(1000);
                         }
                     }
                 }
@@ -805,37 +811,40 @@ namespace parkMonitor.server
         {
             while (!isClosing)
             {
-                //模拟plc与激光操作
-                foreach (PLCNode p in plcMsg.originalPlcList)
+                if (plcMsg.originalPlcList != null)
                 {
-                    int addr = Int32.Parse(p.Address);
-                    int value = Int32.Parse(p.Value);
-                    //停取车复位
-                    if (addr == park_completed_acknowledge_address && value == 0)
-                    {
-                        Thread.Sleep(2000);
-                        SendtoPLC(park_completed_address.ToString(), "0");
-                        SendtoPLC(park_completed_acknowledge_address.ToString(), "1");
-                    }
-                    if (addr == fetch_completed_acknowledge_address && value == 0)
-                    {
-                        Thread.Sleep(2000);
-                        SendtoPLC(fetch_completed_address.ToString(), "0");
-                        SendtoPLC(fetch_completed_acknowledge_address.ToString(), "1");
-                    }
-                    //停车完成
-                    if (addr == parking_startRobot_address && value == 1)
+                    //模拟plc与激光操作
+                    foreach (PLCNode p in plcMsg.originalPlcList)
                     {
-                        Thread.Sleep(10000);
-                        SendtoPLC(park_completed_address.ToString(), "1");
-                        SendtoPLC(addr.ToString(), "0");
-                    }
-                    //取车完成
-                    if (addr == fetching_startRobot_address && value == 1)
-                    {
-                        Thread.Sleep(10000);
-                        SendtoPLC(fetch_completed_address.ToString(), "1");
-                        SendtoPLC(addr.ToString(), "0");
+                        int addr = Int32.Parse(p.Address);
+                        int value = Int32.Parse(p.Value);
+                        //停取车复位
+                        if (addr == park_completed_acknowledge_address && value == 0)
+                        {
+                            Thread.Sleep(2000);
+                            SendtoPLC(park_completed_address.ToString(), "0");
+                            SendtoPLC(park_completed_acknowledge_address.ToString(), "1");
+                        }
+                        if (addr == fetch_completed_acknowledge_address && value == 0)
+                        {
+                            Thread.Sleep(2000);
+                            SendtoPLC(fetch_completed_address.ToString(), "0");
+                            SendtoPLC(fetch_completed_acknowledge_address.ToString(), "1");
+                        }
+                        //停车完成
+                        if (addr == parking_startRobot_address && value == 1)
+                        {
+                            Thread.Sleep(10000);
+                            SendtoPLC(park_completed_address.ToString(), "1");
+                            SendtoPLC(addr.ToString(), "0");
+                        }
+                        //取车完成
+                        if (addr == fetching_startRobot_address && value == 1)
+                        {
+                            Thread.Sleep(10000);
+                            SendtoPLC(fetch_completed_address.ToString(), "1");
+                            SendtoPLC(addr.ToString(), "0");
+                        }
                     }
                 }
                 Thread.Sleep(200);