Browse Source

PLC掉线判空,号牌机工具取消保存图片功能,以号牌机编号启动激光,给予plc初始化缓冲

yct 6 years ago
parent
commit
ded4dc14fb

+ 1 - 1
parkMonitor/entity/AbstractMessage.cs

@@ -339,7 +339,7 @@ namespace parkMonitor.entity
     {
         public int status { get; set; }
         public string LicenseNum { get; set; }
-        public int laserID { get; set; }//激光地址
+        public int posID { get; set; }//激光地址
         public string parkingSpaceID { get; set; }
         public string parkingSpaceX { get; set; }
         public string parkingSpaceY { get; set; }

+ 2 - 0
parkMonitor/entity/EntityForCore.cs

@@ -10,6 +10,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using parkMonitor.tools;
+using System.Threading;
 
 namespace parkMonitor.entity
 {
@@ -78,6 +79,7 @@ namespace parkMonitor.entity
             //缓冲位初始化
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "初始化缓冲位");
             ParkingBufferManager.ins = new ParkingBufferManager();
+            Thread.Sleep(4000);
             initState = initState && ParkingBufferManager.ins.InitParkingBuffers();
             if (initState)
             {

+ 26 - 4
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -508,7 +508,15 @@ namespace parkMonitor.server.CoreThread
                 if (PLC != null)
                 {
                     PLCMsg = (PLCMessage)PLC.GetMessage();
-                    storeStatus = Convert.ToInt32(PLCMsg.originalPlcList[park_completed_address].Value);
+                    //storeStatus = Convert.ToInt32(PLCMsg.originalPlcList[park_completed_address].Value);
+                    if (PLCMsg.originalPlcList.Count != 0)
+                    {
+                        storeStatus = Convert.ToInt32(PLCMsg.originalPlcList[park_completed_address].Value);
+                    }
+                    else
+                    {
+                        storeStatus = -1;
+                    }
                 }
                 //停车完成信号
                 if (storeStatus == status)
@@ -562,12 +570,17 @@ namespace parkMonitor.server.CoreThread
         private bool WaitWheelbase(ref int frontWheelbase, ref int rearWheelbase)
         {
             PLCMessage PLCMsg = null;
+            int wheelbaseStatus = 0;
             MyTimer mt = new MyTimer();
             mt.StartTiming();
             while (!isClosing)
             {
                 PLCMsg = (PLCMessage)PLC.GetMessage();
-                int wheelbaseStatus = Convert.ToInt32(PLCMsg.originalPlcList[wheelbase_status_address].Value);
+                //wheelbaseStatus = Convert.ToInt32(PLCMsg.originalPlcList[wheelbase_status_address].Value);
+                if (PLCMsg.originalPlcList.Count != 0)
+                {
+                    wheelbaseStatus = Convert.ToInt32(PLCMsg.originalPlcList[wheelbase_status_address].Value);
+                }
                 //停车完成信号
                 if (wheelbaseStatus == 3)
                 {
@@ -617,7 +630,7 @@ namespace parkMonitor.server.CoreThread
             ControlMessage cm = new ControlMessage();
             cm.status = status;
             //根据号牌机id启动对应激光
-            cm.laserID = queueCmd.id / 6 + 1;
+            cm.posID = queueCmd.id;
             cm.LicenseNum = queueCmd.LicenseNum;
             PLC.SetMessage(cm);
             Log.WriteLog(LogType.NOT_DATABASE, "停车流程:车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");
@@ -980,10 +993,19 @@ namespace parkMonitor.server.CoreThread
             PLCMessage PLCMsg = null;
             MyTimer mt = new MyTimer();
             mt.StartTiming();
+            int fetchingStatus = 0;
             while (!isClosing)
             {
                 PLCMsg = (PLCMessage)PLC.GetMessage();
-                int fetchingStatus = Convert.ToInt32(PLCMsg.originalPlcList[fetch_completed_address].Value);
+                //fetchingStatus = Convert.ToInt32(PLCMsg.originalPlcList[fetch_completed_address].Value);
+                if (PLCMsg.originalPlcList.Count != 0)
+                {
+                    fetchingStatus = Convert.ToInt32(PLCMsg.originalPlcList[fetch_completed_address].Value);
+                }
+                else
+                {
+                    fetchingStatus = -1;
+                }
                 //取车完成信号
                 if (fetchingStatus == status)
                 {

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

@@ -342,6 +342,7 @@ namespace parkMonitor.server.CoreThread
                     plc = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
                 }
                 pList = ((PLCMessage)plc.GetMessage()).originalPlcList;
+                //while (pList.Count() == 0) { pList = ((PLCMessage)plc.GetMessage()).originalPlcList; }
                 //根据plc中数据初始化缓冲位
                 for (int i = 0; i < bufferCount; i++)
                 {

+ 32 - 30
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -336,10 +336,12 @@ namespace parkMonitor.server
                     //从哪个地址开始,读取长度
                     PLC_Read((ushort)startAddr, (ushort)addrLength);
                     //LaserMonitor();
+                    plcMsg.originalPlcList = JsonHelper.DeserializeJsonToList<PLCNode>(json);
                 }
                 else
                 {
                     json = "";
+                    plcMsg.originalPlcList = new List<PLCNode>();
                     if (EntityForCore.ins.globalStatus)
                     {
                         Reconnect();
@@ -374,7 +376,6 @@ namespace parkMonitor.server
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "PLC重连中,请稍候。。。。。。");
                     }
                     LinkStart();
-                    Thread.Sleep(6000);
                     if (isConnection)
                     {
                         EntityForCore.ins.globalStatus = true;
@@ -382,6 +383,7 @@ namespace parkMonitor.server
                         exceptionBreak = false;
                         break;
                     }
+                    Thread.Sleep(6000);
                 }
                 if (linkCount <= 0)
                 {
@@ -501,7 +503,7 @@ namespace parkMonitor.server
                         AsyncCmdServer.ins.send(AsyncCmdType.PLCOnline);
                         UILogServer.ins.info("PLC连接成功");
                         isConnection = true;
-                        linkCount = 0;
+                        //linkCount = 0;
                     }
                     else
                     {
@@ -689,14 +691,14 @@ namespace parkMonitor.server
         {
             try
             {
-                if (json != "")
-                {
-                    plcMsg.originalPlcList = JsonHelper.DeserializeJsonToList<PLCNode>(json);
-                }
-                else
-                {
-                    plcMsg.originalPlcList = new List<PLCNode>();
-                }
+                //if (json != "")
+                //{
+                //    plcMsg.originalPlcList = JsonHelper.DeserializeJsonToList<PLCNode>(json);
+                //}
+                //else
+                //{
+                //    plcMsg.originalPlcList = new List<PLCNode>();
+                //}
 
                 if (decompressIndex != null && decompressIndex.Count != 0)
                 {
@@ -748,7 +750,7 @@ namespace parkMonitor.server
                                 string laser_start_addr = "";
                                 foreach (LaserProcessUnit lpu in laserMgmtList)
                                 {
-                                    if (cm.laserID == lpu.id)
+                                    if (cm.posID / 6 + 1 == lpu.id)
                                     {
                                         lpuTemp = lpu;
                                         laser_start_addr = lpu.laser_start_address.ToString();
@@ -763,7 +765,7 @@ namespace parkMonitor.server
                                     SendtoPLC(laser_start_addr, "0");
                                     lpuTemp.laserMsg.licenseNum = cm.LicenseNum;
                                     Thread.Sleep(300);
-                                    SendtoPLC(laser_start_addr, "1");
+                                    SendtoPLC(laser_start_addr, cm.posID.ToString());
                                     Thread.Sleep(100);
                                     //SendtoPLC("1", "1");//停车指令置1
                                     Log.WriteLog(LogType.NOT_DATABASE, "已发送激光" + lpuTemp.id + "启动指令");
@@ -878,11 +880,11 @@ namespace parkMonitor.server
                 addrLength = Int32.Parse(ConfigurationManager.AppSettings.Get("PLC_address_length"));
             }
             catch (Exception) { UILogServer.ins.error("PLC配置文件异常"); Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "PLC配置文件异常"); }
-            for (int i = startAddr; i < startAddr + addrLength; i++)
-            {
-                plcMsg.originalPlcList.Add(new PLCNode(i.ToString(), "0"));
-            }
-
+            //for (int i = startAddr; i < startAddr + addrLength; i++)
+            //{
+            //    plcMsg.originalPlcList.Add(new PLCNode(i.ToString(), "0"));
+            //}
+            plcMsg.originalPlcList = new List<PLCNode>();
             LinkStart();
 
             Task.Factory.StartNew(() =>
@@ -900,19 +902,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>

+ 2 - 2
parkMonitor/view/FormModbus/FormModbus.cs

@@ -985,8 +985,8 @@ namespace PLC_Communication
                 }
 
                 string path = strFilePath + sTime + ".jpg";
-
-                VzClientSDK.VzLPRClient_ImageSaveToJpeg(pImgFull, path, 100);
+                //取消号牌机自动保存图片功能
+                //VzClientSDK.VzLPRClient_ImageSaveToJpeg(pImgFull, path, 100);
                 plateInfo.img_path = path;
 
                 int size = Marshal.SizeOf(plateInfo);