Browse Source

模拟激光plc自动化测试,核心指令处理结构优化。数据库写入会使用同一车位,需加锁,优化数据库读写机制。

yc_t 7 years ago
parent
commit
a50e55967f

BIN
modbus_PLC_laser_test/新plc模拟.mbs


+ 2 - 6
parkMonitor/App.config

@@ -80,16 +80,12 @@
     <!--ip位置映射表-->
     <!--位置编号;基点横坐标;车位宽度;宽度补偿-->
     <add key="192.168.0.20" value="1" />
-    <add key="192.168.0.21" value="1" />
+    <add key="192.168.0.21" value="2" />
     <add key="parkingEntZ" value="0" />
     <add key="parkingEntZ" value="0" />
     <add key="parkingEntZ" value="0" />
     <add key="parkingEntZ" value="0" />
-
-    <!-- 临时-->
-    <add key="cx" value="" />
-    <add key="cy" value="" />
-    <add key="aa" value="" />
+    
   </appSettings>
   
   <system.web>

+ 41 - 0
parkMonitor/entity/AddressesForCore.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace parkMonitor.entity
+{
+    class AddressesForCore
+    {
+        public int equipmentStatus_address { set; get; }
+        public int park_completed_address { set; get; }
+        public int parkingEntX { set; get; }
+        public int parkingEntY { set; get; }
+        public int parkingEntZ { set; get; }
+        public int fetch_completed_address { set; get; }
+        public int wheelbase_status_address { get; set; }
+        public int parking_startRobot_address { get; set; }
+        public int fetching_startRobot_address { get; set; }
+        public int frontWheelbase_address { get; set; }
+        public int rearWheelbase_address { get; set; }
+        public static AddressesForCore ins = new AddressesForCore();
+        public AddressesForCore()
+        {
+            parking_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["parking_startRobot_address"]);
+            fetching_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetching_startRobot_address"]);
+            equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
+            park_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["park_completed_address"]);
+            parkingEntX = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntX"]);
+            parkingEntY = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntY"]);
+            parkingEntZ = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntZ"]);
+            //轮距
+            frontWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["frontWheelbase_address"]);
+            rearWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["rearWheelbase_address"]);
+            wheelbase_status_address = Convert.ToInt32(ConfigurationManager.AppSettings["wheelbase_status_address"]);
+            //取车完成
+            fetch_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetch_completed_address"]);
+        }
+    }
+}

+ 1 - 0
parkMonitor/parkMonitor.csproj

@@ -96,6 +96,7 @@
     <Compile Include="DB\Parking_Space.cs" />
     <Compile Include="DB\Vehicle.cs" />
     <Compile Include="entity\AbstractMessage.cs" />
+    <Compile Include="entity\AddressesForCore.cs" />
     <Compile Include="entity\Equipments.cs" />
     <Compile Include="entity\EquipmentSimpleFactory.cs" />
     <Compile Include="entity\ICoreThreadDoWorking.cs" />

+ 25 - 20
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -21,13 +21,23 @@ namespace parkMonitor.server.CoreThread
     public abstract class AbstractCmd
     {
         public static bool isClosing { get; set; }
+        //addresses
         public int equipmentStatus_address { set; get; }
         public int park_completed_address { set; get; }
         public int parkingEntX { set; get; }
         public int parkingEntY { set; get; }
         public int parkingEntZ { set; get; }
+
         public int fetch_completed_address { set; get; }
         public int wheelbase_status_address { get; set; }
+        public int parking_startRobot_address { get; set; }
+        public int fetching_startRobot_address { get; set; }
+
+        public int frontWheelbase_address { get; set; }
+        public int rearWheelbase_address { get; set; }
+
+        //instances
+        public DBLocationOperator locationOper { get; set; }
         public IEquipments PLC { set; get; }
         public IEquipments queuingThread { set; get; }
         public DBOperation oper { set; get; }
@@ -35,28 +45,21 @@ namespace parkMonitor.server.CoreThread
         public CEntrance cEntrance { set; get; }
         public AllotParkingSpace aps { set; get; }
 
-        public int parking_startRobot_address { get; set; }
-        public int fetching_startRobot_address { get; set; }
-        public DBLocationOperator locationOper { get; set; }
-
-        public int frontWheelbase_address { get; set; }
-        public int rearWheelbase_address { get; set; }
-
         public AbstractCmd()
         {
-            parking_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["parking_startRobot_address"]);
-            fetching_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetching_startRobot_address"]);
-            equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
-            park_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["park_completed_address"]);
-            parkingEntX = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntX"]);
-            parkingEntY = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntY"]);
-            parkingEntZ = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntZ"]);
+            parking_startRobot_address = AddressesForCore.ins.parking_startRobot_address;
+            fetching_startRobot_address = AddressesForCore.ins.fetching_startRobot_address;
+            equipmentStatus_address = AddressesForCore.ins.equipmentStatus_address;
+            park_completed_address = AddressesForCore.ins.park_completed_address;
+            parkingEntX = AddressesForCore.ins.parkingEntX;
+            parkingEntY = AddressesForCore.ins.parkingEntY;
+            parkingEntZ = AddressesForCore.ins.parkingEntZ;
             //轮距
-            frontWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["frontWheelbase_address"]);
-            rearWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["rearWheelbase_address"]);
-            wheelbase_status_address = Convert.ToInt32(ConfigurationManager.AppSettings["wheelbase_status_address"]);
+            frontWheelbase_address = AddressesForCore.ins.frontWheelbase_address;
+            rearWheelbase_address = AddressesForCore.ins.rearWheelbase_address;
+            wheelbase_status_address = AddressesForCore.ins.wheelbase_status_address;
             //取车完成
-            fetch_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetch_completed_address"]);
+            fetch_completed_address = AddressesForCore.ins.fetch_completed_address;
             //获取PLC句柄
             PLC = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
             //获取队列句柄
@@ -304,6 +307,7 @@ namespace parkMonitor.server.CoreThread
             Data data = new Data();
             bool jumpOut = false;
             int disconnectionCount = 0;
+            int laserID = queueCmd.id / 6 + 1;
             PLCMessage PLCMsg = null;
             jumpOut = false;
             MyTimer mt = new MyTimer();
@@ -315,7 +319,7 @@ namespace parkMonitor.server.CoreThread
                 {
                     foreach (LaserMessage lm in PLCMsg.laserMsgList)
                     {
-                        if (lm.id == queueCmd.id && lm.data != null)
+                        if (lm.id == laserID && lm.data != null)
                         {
                             lock (lm)
                             {
@@ -490,7 +494,8 @@ namespace parkMonitor.server.CoreThread
             int status = 1;//停车
             ControlMessage cm = new ControlMessage();
             cm.status = status;
-            cm.laserID = queueCmd.id;//启动对应激光
+            //根据号牌机id启动对应激光
+            cm.laserID = queueCmd.id / 6 + 1;
             cm.LicenseNum = queueCmd.LicenseNum;
             PLC.SetMessage(cm);
             Log.WriteLog("停车流程,车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");

+ 1 - 1
parkMonitor/server/NumMachine/NumMachine.cs

@@ -472,7 +472,7 @@ namespace parkMonitor.server
                         id = Int32.Parse(ConfigurationManager.AppSettings.Get(strIP));
                         ipIdMap.Add(strIP, id);
                     }
-                    catch (Exception) { UILogServer.ins.log("读取号牌机编号映射失败,配置文件填写有误"); }
+                    catch (Exception) { UILogServer.ins.error("读取号牌机编号映射失败,配置文件填写有误"); }
                 }
             }
             //检查设备是否存在

+ 33 - 56
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -69,8 +69,6 @@ namespace parkMonitor.server
         private RobotProcessUnit rpu1;
         private List<string> decompressIndex;
 
-        private int cx, cy, aa;
-
         /// <summary>
         /// plc构造函数
         /// </summary>
@@ -130,11 +128,6 @@ namespace parkMonitor.server
                 {
                     decompressIndex.Add((70 + i).ToString());
                 }
-
-                //临时
-                cx = Int32.Parse(ConfigurationManager.AppSettings.Get("cx"));
-                cy = Int32.Parse(ConfigurationManager.AppSettings.Get("cy"));
-                aa = Int32.Parse(ConfigurationManager.AppSettings.Get("aa"));
             }
             catch (Exception)
             {
@@ -589,14 +582,6 @@ namespace parkMonitor.server
                                     WaitForLaserReady(lpuTemp);
                                     SendtoPLC(laser_start_addr, "0");
                                     lpuTemp.laserMsg.licenseNum = cm.LicenseNum;
-                                    //foreach (LaserMessage lm in plcMsg.laserMsgList)
-                                    //{
-                                    //    if (lm.id == lpuTemp.id)
-                                    //    {
-                                    //        lm.licenseNum = cm.LicenseNum;
-                                    //        break;
-                                    //    }
-                                    //}
                                     Thread.Sleep(300);
                                     SendtoPLC(laser_start_addr, "1");
                                     Thread.Sleep(100);
@@ -611,22 +596,12 @@ namespace parkMonitor.server
                         case 2:
                             if (cm.RobotID == 1)
                             {
-
                                 //停车启动机械手
                                 SendtoPLC(rpu1.parking_startRobot_address.ToString(), "1");
                                 //自动或手动输入激光雷达数据
-                                if (cx == 0 && cy == 0 && aa == 0)
-                                {
-                                    SendtoPLC(rpu1.parking_laserCenterX_address.ToString(), cm.centerX);
-                                    SendtoPLC((rpu1.parking_laserCenterX_address + 1).ToString(), cm.centerY);
-                                    SendtoPLC((rpu1.parking_laserCenterX_address + 2).ToString(), cm.angleA);
-                                }
-                                else
-                                {
-                                    SendtoPLC(rpu1.parking_laserCenterX_address.ToString(), cx.ToString());
-                                    SendtoPLC((rpu1.parking_laserCenterX_address + 1).ToString(), cy.ToString());
-                                    SendtoPLC((rpu1.parking_laserCenterX_address + 2).ToString(), aa.ToString());
-                                }
+                                SendtoPLC(rpu1.parking_laserCenterX_address.ToString(), cm.centerX);
+                                SendtoPLC((rpu1.parking_laserCenterX_address + 1).ToString(), cm.centerY);
+                                SendtoPLC((rpu1.parking_laserCenterX_address + 2).ToString(), cm.angleA);
                                 //车位信息
                                 SendtoPLC(rpu1.parkingSpaceID_address.ToString(), cm.parkingSpaceID);
                                 SendtoPLC((rpu1.parkingSpaceID_address + 1).ToString(), cm.parkingSpaceX);
@@ -659,7 +634,6 @@ namespace parkMonitor.server
                                 SendtoPLC((rpu1.parkingSpaceID_address + 1).ToString(), cm.parkingSpaceX);
                                 SendtoPLC((rpu1.parkingSpaceID_address + 2).ToString(), cm.parkingSpaceY);
                                 SendtoPLC((rpu1.parkingSpaceID_address + 3).ToString(), cm.parkingSpaceZ);
-                                //Console.WriteLine("取车中,开始抓车");
                                 SendtoPLC(rpu1.fetching_startRobot_address.ToString(), "1");
                             }
                             break;
@@ -771,7 +745,7 @@ namespace parkMonitor.server
                                     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());
+                                    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);
@@ -785,6 +759,7 @@ namespace parkMonitor.server
                         }
                     }
                 }
+                Thread.Sleep(200);
             }
         }
         private void wheelbaseAnim()
@@ -817,12 +792,13 @@ namespace parkMonitor.server
                         {
                             working = false;
                             SendtoPLC("81", "254");
-                            Thread.Sleep(2000);
+                            Thread.Sleep(1000);
                             SendtoPLC("81", "255");
-                            Thread.Sleep(2000);
+                            Thread.Sleep(1000);
                         }
                     }
                 }
+                Thread.Sleep(200);
             }
         }
         private void autoCycling()
@@ -835,7 +811,7 @@ namespace parkMonitor.server
                     int addr = Int32.Parse(p.Address);
                     int value = Int32.Parse(p.Value);
                     //停取车复位
-                    if(addr==park_completed_acknowledge_address && value == 0)
+                    if (addr == park_completed_acknowledge_address && value == 0)
                     {
                         Thread.Sleep(2000);
                         SendtoPLC(park_completed_address.ToString(), "0");
@@ -862,6 +838,7 @@ namespace parkMonitor.server
                         SendtoPLC(addr.ToString(), "0");
                     }
                 }
+                Thread.Sleep(200);
             }
         }
     }
@@ -991,37 +968,37 @@ namespace parkMonitor.server
                                     lock (laserMsg)
                                     {
                                         laser_rescan_countdown--;
-                                            //停车指令置0
-                                            PLCNode pn = new PLCNode(laser_start_address.ToString(), "0");
+                                        //停车指令置0
+                                        PLCNode pn = new PLCNode(laser_start_address.ToString(), "0");
                                         plc.SetMessage(pn);
-                                            //未终止重测,车未开走,停车指令归零后置1
-                                            if (!laserMsg.abort_rescan)
+                                        //未终止重测,车未开走,停车指令归零后置1
+                                        if (!laserMsg.abort_rescan)
                                         {
                                             UILogServer.ins.error("激光" + laserMsg.id + "计算异常,重新测量");
-                                                //重测检测心跳
-                                                Task rescan_wait_heartbeat = Task.Factory.StartNew(() =>
+                                            //重测检测心跳
+                                            Task rescan_wait_heartbeat = Task.Factory.StartNew(() =>
+                                            {
+                                                MyTimer mt = new MyTimer();
+                                                mt.StartTiming();
+                                                while (laserMsg.status != 254 && laserMsg.status != 255)
                                                 {
-                                                    MyTimer mt = new MyTimer();
-                                                    mt.StartTiming();
-                                                    while (laserMsg.status != 254 && laserMsg.status != 255)
+                                                    Thread.Sleep(1000);
+                                                    mt.EndTiming();
+                                                    int activationCount = 0;
+                                                    if (mt.IsLonger(15, 1, false, out activationCount))
                                                     {
-                                                        Thread.Sleep(1000);
-                                                        mt.EndTiming();
-                                                        int activationCount = 0;
-                                                        if (mt.IsLonger(15, 1, false, out activationCount))
+                                                        if (activationCount == 1)
+                                                        {
+                                                            UILogServer.ins.info("重测前未获得心跳,继续等待");
+                                                        }
+                                                        if (MyTimer.restart && !mt.rolledBack)
                                                         {
-                                                            if (activationCount == 1)
-                                                            {
-                                                                UILogServer.ins.info("重测前未获得心跳,继续等待");
-                                                            }
-                                                            if (MyTimer.restart && !mt.rolledBack)
-                                                            {
-                                                                mt.rolledBack = true;
-                                                                UILogServer.ins.error("发起重测前超时未能获取摆扫激光心跳,请检查设备");
-                                                            }
+                                                            mt.rolledBack = true;
+                                                            UILogServer.ins.error("发起重测前超时未能获取摆扫激光心跳,请检查设备");
                                                         }
                                                     }
-                                                });
+                                                }
+                                            });
                                             UILogServer.ins.log("获得心跳,准备发起重测");
                                             rescan_wait_heartbeat.Wait();
                                             pn = new PLCNode(laser_start_address.ToString(), "1");

+ 3 - 3
parkMonitor/view/mainWin/MainWindow.xaml

@@ -37,11 +37,11 @@
 
 			<Grid Margin="8,0" Grid.Row="2">
 				<Grid.ColumnDefinitions>
-					<ColumnDefinition Width="500" MinWidth="150" MaxWidth="1080"/>
+					<ColumnDefinition Width="600" MinWidth="150" MaxWidth="1080"/>
 					<ColumnDefinition Width="8"/>
 					<ColumnDefinition Width="524*"/>
 					<ColumnDefinition Width="8"/>
-					<ColumnDefinition Width="300" MinWidth="150" MaxWidth="500"/>
+					<ColumnDefinition Width="200" MinWidth="150" MaxWidth="500"/>
 				</Grid.ColumnDefinitions>
 
 				<!--设备/部件树-->
@@ -91,7 +91,7 @@
 					<Grid.RowDefinitions>
 						<RowDefinition Height="*"/>
 						<RowDefinition Height="8"/>
-						<RowDefinition Height="350"/>
+						<RowDefinition Height="450"/>
 					</Grid.RowDefinitions>
 
 					<!--主监控面板-->