Procházet zdrojové kódy

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

# Conflicts:
#	parkMonitor/App.config
yct před 7 roky
rodič
revize
bf511fbb4f

+ 2 - 2
parkMonitor.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.40629.0
+# Visual Studio 15
+VisualStudioVersion = 15.0.27130.2026
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "parkMonitor", "parkMonitor\parkMonitor.csproj", "{DD3DCAB1-41A7-4EED-ADEE-9E4BBCE6B4C0}"
 EndProject

+ 2 - 1
parkMonitor/App.config

@@ -18,7 +18,8 @@
     <!--数据库连接配置文件-->
     <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="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"/>
     <!--日志写入地址配置文件-->
     <add key="LogPath" value="E:\\c#workspace\\LogDemo\\LoggerTest" />
     <!--测量数据误差-->

+ 106 - 0
parkMonitor/ClassDiagram1.cd

@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ClassDiagram MajorVersion="1" MinorVersion="1">
+  <Class Name="parkMonitor.entity.AbstractMessage" Collapsed="true">
+    <Position X="7.25" Y="0.5" Width="1.5" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+  </Class>
+  <Class Name="parkMonitor.entity.MessageUTF8">
+    <Position X="1" Y="1.75" Width="2.25" />
+    <TypeIdentifier>
+      <HashCode>AAgCAAACAAAAAAQAAAAAAAAAAAAAAAAABAAAAAAACBA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.PLCNode">
+    <Position X="4.75" Y="1.75" Width="1.75" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAAAAAAAAgAAAAAAAAAAAAIACAAAgAAAAAAA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+  </Class>
+  <Class Name="parkMonitor.entity.PLCMessage">
+    <Position X="10.25" Y="1.75" Width="1.5" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAAABIQAAAAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.NumberMachineNode" BaseTypeListCollapsed="true">
+    <Position X="6.5" Y="4.25" Width="2.25" />
+    <TypeIdentifier>
+      <HashCode>AAQAAAEAAAAAAAACgAAAAAAAAAAAAIAAAAAgAAABAhA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <ShowAsAssociation>
+      <Field Name="status" />
+    </ShowAsAssociation>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.NumberMachineMessage">
+    <Position X="6.5" Y="1.75" Width="2.25" />
+    <AssociationLine Name="aNode" Type="parkMonitor.entity.NumberMachineNode">
+      <MemberNameLabel ManuallyPlaced="true">
+        <Position X="-0.797" Y="0.105" />
+      </MemberNameLabel>
+    </AssociationLine>
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAABAAAAAgAAAAAAAAAAAAIAAAAAQAAAAAAA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <ShowAsAssociation>
+      <Field Name="aNode" />
+    </ShowAsAssociation>
+  </Class>
+  <Class Name="parkMonitor.entity.LaserMessage">
+    <Position X="11.75" Y="1.75" Width="2.25" />
+    <AssociationLine Name="data" Type="parkMonitor.entity.Data">
+      <MemberNameLabel ManuallyPlaced="true">
+        <Position X="0.303" Y="0.071" />
+      </MemberNameLabel>
+    </AssociationLine>
+    <TypeIdentifier>
+      <HashCode>AAQgAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAQAAAAAhA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <ShowAsAssociation>
+      <Field Name="data" />
+    </ShowAsAssociation>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.Data" BaseTypeListCollapsed="true">
+    <Position X="10.5" Y="4.75" Width="1.5" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAAAAAAQAQEAAABgAAAAAAAAAAAAAAABAABA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.Command">
+    <Position X="3" Y="1.75" Width="1.75" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAECAIAAAEAACAAAAAAAAAAAAAAAAAAgAAABChA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+    <Lollipop Position="0.2" />
+  </Class>
+  <Class Name="parkMonitor.entity.ParkingMessage">
+    <Position X="8.75" Y="1.75" Width="1.5" />
+    <TypeIdentifier>
+      <HashCode>AgQABAAAAAAAQAQAQEAAABgAQAAAAAAAAAAAAABADgA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+  </Class>
+  <Enum Name="parkMonitor.entity.EnumNumberMachineStatus">
+    <Position X="3.25" Y="5.75" Width="2.5" />
+    <TypeIdentifier>
+      <HashCode>AAAAAAAAAAAAAAAAAAgAAAAAAAAIAAAAAAAAAAAAAAA=</HashCode>
+      <FileName>entity\AbstractMessage.cs</FileName>
+    </TypeIdentifier>
+  </Enum>
+  <Font Name="微软雅黑" Size="9" />
+</ClassDiagram>

+ 3 - 3
parkMonitor/DB/DBOperation.cs

@@ -161,11 +161,11 @@ namespace parkMonitor.DB
             return isDataRight;
         }
         //查询车位位置及状态,返回list
-        public List<Parking_Space> GetParkingSpace()
+        public List<Parking_Space> GetParkingSpace(int garageID)
         {
             List<Parking_Space> lps = new List<Parking_Space>();
             MySqlDataReader reader = null;
-            string sql = "select * from parkingspace where parkingSpaceState = 0 ";
+            string sql = "select * from parkingspace where parkingSpaceState = 0 and garageID = '"+garageID+"' ";
             con = oper.getConn();
             try
             {
@@ -179,7 +179,7 @@ namespace parkMonitor.DB
                         int parkingSpaceID = reader.GetInt32("parkingSpaceID");
                         //float parkingSpaceWeight = reader.GetFloat("parkingSpaceWeight");
                         //int parkingSpaceStatement = reader.GetInt32("parkingSpaceState");
-                        int garageID = reader.GetInt32("garageID");
+                        //int garageID = reader.GetInt32("garageID");
                         int parkingSpaceX = reader.GetInt32("parkingSpaceX");
                         int parkingSpaceY = reader.GetInt32("parkingSpaceY");
                         int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");

+ 159 - 6
parkMonitor/DBLocation/DBLocation.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using MySql.Data.MySqlClient;
+using parkMonitor.DB;
 
 namespace parkMonitor.DBLocation
 {
@@ -198,10 +199,10 @@ namespace parkMonitor.DBLocation
         }
 
         //车库有无此车
-        public bool IsNumberPlate(string numberPlate)
+        public bool IsNumberPlate(string numberPlate,int garageID)
         {
             bool isNumberPlate = true;
-            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '"+garageID+"'";
             con = oper.getConn();
             try
             {
@@ -230,9 +231,9 @@ namespace parkMonitor.DBLocation
         }
 
         //数据插入记录表,并返回停车记录id
-        public int InsertToParkingRecords(int parkingStatus, int userID, string numberPlate, int parkingSpaceID, int garageID, int parkingRecordsState, string realParkTime)
+        public int InsertToParkingRecords(int parkingStatus, int userID, string numberPlate, int parkingSpaceID, int garageID, int parkingRecordsState, string realParkTime, int frontWheelbase, int rearWheelbase)
         {
-            string sql = "insert into parkingrecords(parkingStatus,userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime) values('" + parkingStatus + "','" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "')";
+            string sql = "insert into parkingrecords(parkingStatus,userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,frontWheelbase,rearWheelbase) values('" + parkingStatus + "','" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "','" + frontWheelbase + "','" + rearWheelbase + "')";
             con = oper.getConn();
             int parkingRecordsID = 0;
             try
@@ -339,7 +340,7 @@ namespace parkMonitor.DBLocation
         //更新停车记录表
         public void UpdateParkingRecords(int parkingStatus, int parkingRecordsState, string realGetTime, int parkingRecordsID)
         {
-            string sql = "update parkingrecords set parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
+            string sql = "update parkingrecords set parkingStatus = '"+parkingStatus+"', parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
             con = oper.getConn();
             try
             {
@@ -447,7 +448,7 @@ namespace parkMonitor.DBLocation
         }
 
         //查询手动停车的车位ID
-        public int[] GetParkingSpaceID()
+        public int[] GetAllParkingSpaceID()
         {
             int parkingSpaceID = 0;
             List<int> listID = new List<int>();
@@ -487,5 +488,157 @@ namespace parkMonitor.DBLocation
             listID.Add(parkingSpaceID);
             return listID.ToArray();
         }
+
+        //查询车位位置及状态,返回list
+        public List<Parking_Space> GetParkingSpace(int garageID)
+        {
+            List<Parking_Space> lps = new List<Parking_Space>();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where parkingSpaceState = 0 and garageID = '" + garageID + "'";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                reader = oper.getResultSet(cmd);
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                        //float parkingSpaceWeight = reader.GetFloat("parkingSpaceWeight");
+                        //int parkingSpaceStatement = reader.GetInt32("parkingSpaceState");
+                        //int garageID = reader.GetInt32("garageID");
+                        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.garageID = garageID;
+                        //ps.parkingSpaceWeight = parkingSpaceWeight;
+                        //ps.parkingSpaceStatement = parkingSpaceStatement;
+                        ps.parkingSpaceX = parkingSpaceX;
+                        ps.parkingSpaceY = parkingSpaceY;
+                        ps.parkingSpaceZ = parkingSpaceZ;
+
+                        lps.Add(ps);
+                    }
+                }
+                if (reader != null)
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+                if (cmd != null)
+                {
+                    cmd.Dispose();
+                }
+                if (con != null)
+                {
+                    con.Close();
+                    con.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return lps;
+        }
+
+        //根据车牌查询得到车库id和车位id以及轮距
+        public Vehicle GetVehicle(string numberPlate, int garageID)
+        {
+            // List<Vehicle> lVehicle = new List<Vehicle>();
+            Vehicle v = new Vehicle();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                reader = oper.getResultSet(cmd);
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                        int frontwheelbase = reader.GetInt32("frontwheelbase");
+                        int rearwheelbase = reader.GetInt32("rearwheelbase");
+                        v.parkingSpaceID = parkingSpaceID;
+                        v.garageID = garageID;
+                        v.frontwheelbase = frontwheelbase;
+                        v.rearwheelbase = rearwheelbase;
+                    }
+                }
+                if (reader != null)
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+                if (cmd != null)
+                {
+                    cmd.Dispose();
+                }
+                if (con != null)
+                {
+                    con.Close();
+                    con.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return v;
+        }
+
+        //根据车位id获得x,y,z
+        public Fetching_Space GetFetchingSpace(int parkingSpaceID)
+        {
+            Fetching_Space fs = new Fetching_Space();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                reader = oper.getResultSet(cmd);
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        int parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                        int parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                        int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
+                        fs.parkingSpaceX = parkingSpaceX;
+                        fs.parkingSpaceY = parkingSpaceY;
+                        fs.parkingSpaceZ = parkingSpaceZ;
+                    }
+                }
+                if (reader != null)
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+                if (cmd != null)
+                {
+                    cmd.Dispose();
+                }
+                if (con != null)
+                {
+                    con.Close();
+                    con.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return fs;
+        }
+
     }
 }

+ 18 - 18
parkMonitor/entity/AbstractMessage.cs

@@ -79,9 +79,9 @@ namespace parkMonitor.entity
     //plc list
     public class PLCMessage : AbstractMessage, ICloneable
     {
-        public List<PLCNode> extendedPlcList;
-        public List<PLCNode> originalPlcList;
-        public List<LaserMessage> laserMsgList;
+        public List<PLCNode> extendedPlcList { get; set; }
+        public List<PLCNode> originalPlcList { get; set; }
+        public List<LaserMessage> laserMsgList { get; set;}
 
         public PLCMessage()
         {
@@ -119,9 +119,9 @@ namespace parkMonitor.entity
     //NumMachine component
     public class NumberMachineNode : ICloneable
     {
-        public string ip;
-        public string LicenseNum;
-        public string TimeRecord;
+        public string ip { get; set; }
+        public string LicenseNum { get; set; }
+        public string TimeRecord { get; set; }
         public int id;
         public EnumNumberMachineStatus status;
         public NumberMachineNode() { }
@@ -166,7 +166,7 @@ namespace parkMonitor.entity
     //NumMachine list+aModel
     public class NumberMachineMessage : AbstractMessage
     {
-        public List<NumberMachineNode> data;
+        public List<NumberMachineNode> data { get; set; }
         public NumberMachineNode aNode;
 
         public NumberMachineMessage()
@@ -255,16 +255,16 @@ namespace parkMonitor.entity
     //********************************************** command **********************************************
     public class Command : AbstractMessage, ICloneable
     {
-        public char commandType;
-        public string LicenseNum;
-        public string userID;
-        public int garageID;
-        public int parkingRecordsID;
-        public string TimeRecord;
-        public string ip;//新添加,用于定位号牌机
-        public int returnedCount;//标记被返回的命令
-        public int id;
-        public bool manual;//判断是否手动停取
+        public char commandType { get; set; }
+        public string LicenseNum { get; set; }
+        public string userID { get; set; }
+        public int garageID { get; set; }
+        public int parkingRecordsID { get; set; }
+        public string TimeRecord { get; set; }
+        public string ip { get; set; }//新添加,用于定位号牌机
+        public int returnedCount { get; set; }//标记被返回的命令
+        public int id { get; set; }
+        public bool manual { get; set; }//判断是否手动停取
 
         public Command()
         {
@@ -299,7 +299,7 @@ namespace parkMonitor.entity
         }
     }
 
-    public class ParkingMessage : AbstractMessage
+    public class ControlMessage : AbstractMessage
     {
         //1: 停车startLaser--park_command_address
         //2: 停车激光的6个数据,startRobot,车位信息4个

+ 9 - 3
parkMonitor/manualParking/ManualParking.cs

@@ -69,15 +69,21 @@ namespace parkMonitor.manualParking
             storeCmd.userID = locationOper.GetUserID(tel.Text).ToString();
             storeCmd.LicenseNum = numberPlate.Text;
             storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum);
-            if (isNumberPlate == false)
+            storeCmd.garageID = Convert.ToInt32(selectGarage.Text);
+            bool isTelRegister = locationOper.IsTelRegister(tel.Text);
+            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum, storeCmd.garageID);
+            if (isTelRegister == false)
+            {
+                MessageBox.Show("该号码未被注册,请先注册");
+            }
+            else if (isNumberPlate == false)
             {
                 MessageBox.Show("车库中查无此车");
             }
             else
             {
                 storeCmd.parkingRecordsID = locationOper.GetParkingRecordsID(storeCmd.LicenseNum);
-                if (storeCmd.userID != "" && storeCmd.LicenseNum != "")
+                if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
                 {
                     qt.SetMessage((Command)storeCmd.Clone());
                     MessageBox.Show("发送成功");

+ 3 - 0
parkMonitor/parkMonitor.csproj

@@ -24,6 +24,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Debug\parkMonitor.xml</DocumentationFile>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,6 +34,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\parkMonitor.xml</DocumentationFile>
   </PropertyGroup>
   <PropertyGroup>
     <ApplicationIcon>resource\image\icon.ico</ApplicationIcon>
@@ -488,6 +490,7 @@
     <EmbeddedResource Include="view\FormModbus\VideoCfg_Form.resx">
       <DependentUpon>VideoCfg_Form.cs</DependentUpon>
     </EmbeddedResource>
+    <None Include="ClassDiagram1.cd" />
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>

+ 68 - 52
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -179,11 +179,11 @@ namespace parkMonitor.server.CoreThread
             {
                 if (!queueCmd.manual)
                 {
-                    ppp = aps.MallocParkingSpace(cEntrance, oper);//自动
+                    ppp = aps.MallocParkingSpace(cEntrance, oper, queueCmd);//自动
                 }
                 else
                 {
-                    ppp = aps.MallocParkingSpace(cEntrance, locationOper);//手动
+                    ppp = aps.MallocParkingSpace(cEntrance, locationOper, queueCmd);//手动
                 }
                 if (ppp != null)
                 {
@@ -297,10 +297,10 @@ namespace parkMonitor.server.CoreThread
         {        
             //第一步:
             int status = 1;//停车
-            ParkingMessage pm = new ParkingMessage();
-            pm.status = status;
-            pm.laserID = queueCmd.id;//启动对应激光
-            PLC.SetMessage(pm);
+            ControlMessage cm = new ControlMessage();
+            cm.status = status;
+            cm.laserID = queueCmd.id;//启动对应激光
+            PLC.SetMessage(cm);
             Console.WriteLine("停车,开激光:" + queueCmd.LicenseNum);
             Log.WriteLog("停车,开激光:" + queueCmd.LicenseNum);
             UILogServer.ins.info("停车,开激光:" + queueCmd.LicenseNum);   
@@ -394,19 +394,19 @@ namespace parkMonitor.server.CoreThread
             robotFree.Wait();
             //第二步:
             status = 2;
-            pm.status = status;
-            pm.RobotID = robotID;//启动对应机械手
-            pm.centerX = Convert.ToString(centerX);
-            pm.centerY = Convert.ToString(centerY);
-            pm.angleA = Convert.ToString(angleA);
-            pm.length = Convert.ToString(length);
-            pm.width = Convert.ToString(width);
-            pm.height = Convert.ToString(height);
-            pm.parkingSpaceID = Convert.ToString(parkingSpaceID);
-            pm.parkingSpaceX = Convert.ToString(parkingSpaceX);
-            pm.parkingSpaceY = Convert.ToString(parkingSpaceY);
-            pm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
-            PLC.SetMessage(pm);
+            cm.status = status;
+            cm.RobotID = robotID;//启动对应机械手
+            cm.centerX = Convert.ToString(centerX);
+            cm.centerY = Convert.ToString(centerY);
+            cm.angleA = Convert.ToString(angleA);
+            cm.length = Convert.ToString(length);
+            cm.width = Convert.ToString(width);
+            cm.height = Convert.ToString(height);
+            cm.parkingSpaceID = Convert.ToString(parkingSpaceID);
+            cm.parkingSpaceX = Convert.ToString(parkingSpaceX);
+            cm.parkingSpaceY = Convert.ToString(parkingSpaceY);
+            cm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
+            PLC.SetMessage(cm);
 
             Console.WriteLine("停车,抓车:" + queueCmd.LicenseNum);
             Log.WriteLog("停车,抓车:" + queueCmd.LicenseNum);
@@ -421,8 +421,8 @@ namespace parkMonitor.server.CoreThread
             storeSignal.Wait();
             //第三步:
             status = 3;
-            pm.status = status;
-            PLC.SetMessage(pm);
+            cm.status = status;
+            PLC.SetMessage(cm);
             //机械手异常则跳出
             if (robotError)
             {
@@ -480,18 +480,18 @@ namespace parkMonitor.server.CoreThread
                 else
                 {
                     //插入停车记录表
-                    int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
-                    //判断车辆表是否存在车辆
-                    bool isNumberPlateFromVehicle = locationOper.IsNumberPlateFromVehicle(numberPlate);
-                    if (isNumberPlateFromVehicle == false)
-                    {
-                        //车辆表更新车辆信息
-                        locationOper.InsertVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
-                    }
-                    else
-                    {
-                        locationOper.UpdateVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
-                    }
+                    int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
+                    ////判断车辆表是否存在车辆
+                    //bool isNumberPlateFromVehicle = locationOper.IsNumberPlateFromVehicle(numberPlate);
+                    //if (isNumberPlateFromVehicle == false)
+                    //{
+                    //    //车辆表更新车辆信息
+                    //    locationOper.InsertVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
+                    //}
+                    //else
+                    //{
+                    //    locationOper.UpdateVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
+                    //}
                     //更新车库表剩余车位数
                     int freeSpaceCount = locationOper.getGarageFreeSpace(garageID);
                     freeSpaceCount = freeSpaceCount - 1;
@@ -520,16 +520,32 @@ namespace parkMonitor.server.CoreThread
         public override void executeCmd(Command queueCmd)
         {
             PLCMessage PLCMsg = null;
-            Vehicle vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
+            Vehicle vehiclelist = null;
+            if (queueCmd.manual)
+            {
+                vehiclelist = locationOper.GetVehicle(queueCmd.LicenseNum, queueCmd.garageID);
+            }
+            else
+            {
+                vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
+            }
             int parkingSpaceID = vehiclelist.parkingSpaceID;
             int garageID = vehiclelist.garageID;
             int frontwheelbase = vehiclelist.frontwheelbase;
             int rearwheelbase = vehiclelist.rearwheelbase;
-            Fetching_Space fslist = oper.GetFetchingSpace(parkingSpaceID);
+            Fetching_Space fslist = null;
+            if (queueCmd.manual)
+            {
+                fslist = locationOper.GetFetchingSpace(parkingSpaceID);
+            }
+            else
+            {
+                fslist = oper.GetFetchingSpace(parkingSpaceID);
+            }
             int parkingSpaceX = fslist.parkingSpaceX;
             int parkingSpaceY = fslist.parkingSpaceY;
             int parkingSpaceZ = fslist.parkingSpaceZ;
-            ParkingMessage pm = new ParkingMessage();
+            ControlMessage cm = new ControlMessage();
             
             int robotID = 0;
             robotID = parkingSpaceID / 15 + 1;
@@ -540,17 +556,17 @@ namespace parkMonitor.server.CoreThread
             robotFree.Wait();
             //取车
             int status = 4;
-            pm.status = status;
+            cm.status = status;
             //先手动赋值
-            pm.RobotID = 1;
-            pm.fetchPosition = 1;//放置地址
-            pm.parkingSpaceID = Convert.ToString(parkingSpaceID);
-            pm.parkingSpaceX = Convert.ToString(parkingSpaceX);
-            pm.parkingSpaceY = Convert.ToString(parkingSpaceY);
-            pm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
-            pm.frontWheelbase = frontwheelbase;
-            pm.rearWheelbase = rearwheelbase;
-            PLC.SetMessage(pm);
+            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.frontWheelbase = frontwheelbase;
+            cm.rearWheelbase = rearwheelbase;
+            PLC.SetMessage(cm);
 
             Console.WriteLine("取车:" + queueCmd.LicenseNum);
             Log.WriteLog("取车:" + queueCmd.LicenseNum);
@@ -575,11 +591,11 @@ namespace parkMonitor.server.CoreThread
             signalFromPLC.Wait();
             //取车完成
             status = 5;
-            ParkingMessage pm2 = new ParkingMessage();
-            pm2.status = status;
+            ControlMessage cm2 = new ControlMessage();
+            cm2.status = status;
             //先手动赋值
-            pm2.RobotID = 1;
-            PLC.SetMessage(pm2);
+            cm2.RobotID = 1;
+            PLC.SetMessage(cm2);
             Console.WriteLine("号牌:" + queueCmd.LicenseNum + "取车完成");
             Log.WriteLog("号牌:" + queueCmd.LicenseNum + "取车完成");
             UILogServer.ins.info("号牌:" + queueCmd.LicenseNum + "取车完成");
@@ -615,8 +631,8 @@ namespace parkMonitor.server.CoreThread
                 locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
                 //更新车位表车位状态
                 locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
-                //更新车辆表车辆停车状态
-                locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                ////更新车辆表车辆停车状态
+                //locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
                 //更新停车记录表
                 locationOper.UpdateParkingRecords(0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
             }

+ 15 - 3
parkMonitor/server/CoreThread/AllotParkingSpace.cs

@@ -4,17 +4,29 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using parkMonitor.DB;
+using parkMonitor.DBLocation;
 using System.Configuration;
+using parkMonitor.entity;
 
 namespace parkMonitor.server.CoreThread
 {
     public class AllotParkingSpace
     {
         //根据车位位置及状态分配目标车位,返回Parking Space的ID
-        public Parking_Space MallocParkingSpace(CEntrance pt_Ent,object c)
+        public Parking_Space MallocParkingSpace(CEntrance pt_Ent,object c,Command queueCmd)
         {
-            DBOperation o = new DBOperation();
-            List<Parking_Space> lps = o.GetParkingSpace();
+            //DBOperation o = new DBOperation();
+            List<Parking_Space> lps = null;
+            if (c.GetType() == typeof(DBOperation))
+            {
+                DBOperation oper = (DBOperation)c;
+                lps = oper.GetParkingSpace(queueCmd.garageID);
+            }
+            else
+            {
+                DBLocationOperator locationOper = (DBLocationOperator)c;
+                lps = locationOper.GetParkingSpace(queueCmd.garageID);
+            }
             double xWeight = Convert.ToDouble(ConfigurationManager.AppSettings["xWeight"]);
             double yWeight = Convert.ToDouble(ConfigurationManager.AppSettings["yWeight"]);
             double zWeight = Convert.ToDouble(ConfigurationManager.AppSettings["zWeight"]);

+ 59 - 43
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -27,14 +27,20 @@ namespace parkMonitor.server.CoreThread
         //
         DBLocationOperator locationOper;
         DBOperation oper;
+        int localGarageId = 0;
 
         string[] equipNames = new string[] { EquipmentName.PLC, EquipmentName.NumMachine, EquipmentName.Web, EquipmentName.Queue };
 
         public CoreThreadTest2()
         {
-            equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
-            locationOper = new DBLocationOperator();
-            oper = new DBOperation();
+            try
+            {
+                equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
+                localGarageId = Convert.ToInt32(ConfigurationManager.AppSettings["localGarageId"]);
+                locationOper = new DBLocationOperator();
+                oper = new DBOperation();
+            }
+            catch (Exception) { }
         }
 
         public void Start()
@@ -88,49 +94,59 @@ namespace parkMonitor.server.CoreThread
 
         public void BeginWorking()
         {
-            while (true)
+            Task.Factory.StartNew(() =>
             {
-                Func<AbstractMessage> func = new Func<AbstractMessage>(GetExecuteNumberPlate);
-
-                TaskFactory taskFactory = new TaskFactory();
-                List<Task> tasklist = new List<Task>();
-                IAsyncResult result = func.BeginInvoke(null, null);
-                Action act1 = new Action(() =>
+                while (true)
                 {
-                    GetTotalStatus();
-                });
-                tasklist.Add(taskFactory.StartNew(act1));
-                Task.WaitAll(tasklist.ToArray());
-                Command queueCmd = (Command)func.EndInvoke(result);
-                Task.Factory.StartNew(() =>
-                {
-                    SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
-                    AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
-                    abstractCmd.executeCmd(queueCmd);
-                });
-                ////同步数据库
-                //Task.Factory.StartNew(() =>
-                //{
-                //    try
-                //    {
-                //        //更新车库表车位数
-                //        int freeSpaceCount = locationOper.getGarageFreeSpace(queueCmd.garageID);
-                //        oper.UpdateGarageFreeSpace(freeSpaceCount, queueCmd.garageID);
-                //        //更新车位状态
-                //        int[] spaceID = locationOper.GetParkingSpaceID();
-                //        for (int i = 0; i < spaceID.Length; i++)
-                //        {
+                    Func<AbstractMessage> func = new Func<AbstractMessage>(GetExecuteNumberPlate);
 
-                //        }
-                //    }
-                //    catch(Exception)
-                //    {
-                //        Console.WriteLine("无同步数据");
-                //    }
-                //    Thread.Sleep(1800000);
-                //});
-                Thread.Sleep(100);
-            }
+                    TaskFactory taskFactory = new TaskFactory();
+                    List<Task> tasklist = new List<Task>();
+                    IAsyncResult result = func.BeginInvoke(null, null);
+                    Action act1 = new Action(() =>
+                    {
+                        GetTotalStatus();
+                    });
+                    tasklist.Add(taskFactory.StartNew(act1));
+                    Task.WaitAll(tasklist.ToArray());
+                    Command queueCmd = (Command)func.EndInvoke(result);
+                    Task.Factory.StartNew(() =>
+                    {
+                        SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
+                        AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
+                        abstractCmd.executeCmd(queueCmd);
+                    });
+                    Thread.Sleep(100);
+                }
+            });
+
+            //同步数据库
+            Task.Factory.StartNew(() =>
+            {
+                while (true)
+                {
+                    try
+                    {
+                        //更新车库表车位数
+                        int freeSpaceCount = locationOper.getGarageFreeSpace(localGarageId);
+                        oper.UpdateGarageFreeSpace(freeSpaceCount, localGarageId);
+                        //更新车位状态                       
+                        int[] spaceID = locationOper.GetAllParkingSpaceID();
+                        if (spaceID != null)
+                        {
+                            for (int i = 0; i < spaceID.Length; i++)
+                            {
+                                oper.UpdateParkingSpaceState(spaceID[i], 1);
+                            }
+                        }
+                    }
+                    catch (Exception)
+                    {
+                        Console.WriteLine("无同步数据");
+                    }
+                    Thread.Sleep(8000);
+                }
+            });
         }
 
         /// <summary>挂起</summary>

+ 15 - 6
parkMonitor/server/CoreThread/QueuingThread.cs

@@ -28,7 +28,6 @@ namespace parkMonitor.server.CoreThread
         NumberMachineNode license;
         MessageUTF8 webMsg;
 
-
         public QueuingThread()
         {
             webHandle = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Web);
@@ -349,19 +348,29 @@ namespace parkMonitor.server.CoreThread
             else if (message.GetType().Equals(typeof(Command)))
             {
                 Command command = (Command)message;
-                command.garageID = 0;
-                command.parkingRecordsID = 0;
+                //command.garageID = 0;
+                //command.parkingRecordsID = 0;
                 command.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 //input user command
                 if (command != null)
                 {
                     if (command.returnedCount > 0)
                     {
-                        lock (ValidStoreCmdQueue)
+                        if (command.commandType.Equals('s'))
                         {
-                            ValidStoreCmdQueue.Enqueue((Command)command.Clone());
+                            lock (ValidStoreCmdQueue)
+                            {
+                                ValidStoreCmdQueue.Enqueue((Command)command.Clone());
+                            }
+                            UILogServer.ins.info("收到退回的停车指令:" + command.LicenseNum);
+                        }
+                        else if(command.commandType.Equals('f')){
+                            lock (FetchCmdQueue)
+                            {
+                                FetchCmdQueue.Enqueue((Command)command.Clone());
+                            }
+                            UILogServer.ins.info("收到退回的取车指令:" + command.LicenseNum);
                         }
-                        UILogServer.ins.info("收到退回的停车指令:" + command.LicenseNum);
                     }
                     else
                     {

+ 208 - 206
parkMonitor/server/NumMachine/NumMachine.cs

@@ -58,7 +58,7 @@ namespace parkMonitor.server
         ///<summary>通过设备句柄访问pic;链接时add,系统关闭时remove</summary>
         private Dictionary<int, PictureBox> devPicMap = new Dictionary<int, PictureBox>();
         ///<summary>通过名字获取pic对象;创建pic时add,系统关闭remove</summary>
-        private Dictionary<string, PictureBox> picNameMap = new Dictionary<string, PictureBox>();
+        private Dictionary<string, PictureBox> namePicMap = new Dictionary<string, PictureBox>();
         ///<summary>通过ip获取设备id;产生ip时创建</summary>
         private Dictionary<string, int> ipIdMap = new Dictionary<string, int>();
         ///<summary>通过ip获取设备句柄;产生句柄时创建</summary>
@@ -67,14 +67,14 @@ namespace parkMonitor.server
         private Queue<NumberMachineNode> LicBuffer = new Queue<NumberMachineNode>();
         ///<summary>计数Map</summary>
         private Dictionary<string, Dictionary<NumberMachineNode, int>> filterMap = new Dictionary<string, Dictionary<NumberMachineNode, int>>();
-        /// <summary>句柄到图像映射</summary>
-        private Dictionary<int, IntPtr> handleImgMap = new Dictionary<int, IntPtr>();
         /// <summary>筛选计数</summary>
         private int filterCount = 0;
         /// <summary>系统关闭</summary>
-        private bool closing = false;
+        private bool isClosing = false;
         /// <summary>开启拍照的设备</summary>
         private int snapshotDevHandle = -1;
+        /// <summary>允许无号牌时拍照</summary>
+        private bool enableEmptySnapshot = true;
 
         private NumberMachineMessage nmMsg = new NumberMachineMessage();
         VzClientSDK.VZLPRC_FIND_DEVICE_CALLBACK_EX find_DeviceCB = null;
@@ -146,7 +146,7 @@ namespace parkMonitor.server
 
         private void UpdateStatus(NumberMachineNode nmn)
         {
-            while (!closing)
+            while (!isClosing)
             {
                 if (GetStatus(nmn.ip) == 1)
                 {
@@ -169,7 +169,7 @@ namespace parkMonitor.server
         {
             try
             {
-                while (!closing)
+                while (!isClosing)
                 {
                     Thread.Sleep(REFRESHINGTIME);
                     //定时返回号牌
@@ -277,7 +277,7 @@ namespace parkMonitor.server
                     {
                         string str = "PictureBox" + Convert.ToString(i);
                         //该名称对应控件不存在,则创建并链接pic
-                        if (!picNameMap.ContainsKey(str))
+                        if (!namePicMap.ContainsKey(str))
                         {
                             PictureBox pic;
                             if (CreatePic(i, out pic))
@@ -317,29 +317,31 @@ namespace parkMonitor.server
 
                 VzClientSDK.VZ_LPR_MSG_PLATE_INFO plateInfo = new VzClientSDK.VZ_LPR_MSG_PLATE_INFO();
                 plateInfo.plate = strLicense;
-                
+
                 //根据setMessage中通过id信息找到的handle保存图片
-                if (!strLicense.Contains("_无_") && handle == snapshotDevHandle)
+                if (handle == snapshotDevHandle)
                 {
-                    string strFilePath = ConfigurationManager.AppSettings["LogPath"] + DateTime.Now.ToString("yyyyMMdd") + "\\";
-                    if (!Directory.Exists(strFilePath))
-                    {
-                        Directory.CreateDirectory(strFilePath);
-                    }
-                    string ip = Get_IP(handle);
-                    string path = strFilePath + ip +"-"+ DateTime.Now.ToString("hh_mm_ss") + ".jpg";
-                    int temp = VzClientSDK.VzLPRClient_ImageSaveToJpeg(pImgFull, path, 50);
-                    if (temp!=-1)
-                    {
-                        LogFile logFile = LogFile.LOG;
-                        Log.WriteLog(logFile, "号牌机" + ip + "已拍照,图片保存于 " + strFilePath);
-                        UILogServer.ins.info("号牌机" + ip + "已拍照,图片保存于 " + strFilePath);
-                    }
-                    else
+                    if (enableEmptySnapshot || !strLicense.Contains("_无_"))
                     {
-                        UILogServer.ins.info("图片保存失败");
+                        string strFilePath = ConfigurationManager.AppSettings["LogPath"] + DateTime.Now.ToString("yyyyMMdd") + "\\";
+                        if (!Directory.Exists(strFilePath))
+                        {
+                            Directory.CreateDirectory(strFilePath);
+                        }
+                        string ip = Get_IP(handle);
+                        string path = strFilePath + ip + "-" + DateTime.Now.ToString("hh_mm_ss") + ".jpg";
+                        int temp = VzClientSDK.VzLPRClient_ImageSaveToJpeg(pImgFull, path, 50);
+                        if (temp != -1)
+                        {
+                            LogFile logFile = LogFile.LOG;
+                            Log.WriteLog(logFile, "号牌机" + ip + "已拍照,图片保存于 " + strFilePath);
+                            UILogServer.ins.info("号牌机" + ip + "已拍照,图片保存于 " + strFilePath);
+                        }
+                        else
+                        {
+                            UILogServer.ins.info("图片保存失败");
+                        }
                     }
-                    
                     snapshotDevHandle = -1;
                 }
                 int size = Marshal.SizeOf(plateInfo);
@@ -557,10 +559,10 @@ namespace parkMonitor.server
                 AutoSize = false,
                 Name = "PictureBox" + Convert.ToString(index)
             };
-            if (!picNameMap.ContainsKey(pb.Name))
+            if (!namePicMap.ContainsKey(pb.Name))
             {
                 flowLayoutPanel1.Controls.Add(pb);
-                picNameMap.Add(pb.Name, pb);
+                namePicMap.Add(pb.Name, pb);
                 return true;
             }
             else
@@ -607,7 +609,7 @@ namespace parkMonitor.server
         {
             Task.Run(() =>
             {
-                closing = false;
+                isClosing = false;
 
                 try
                 {
@@ -630,7 +632,7 @@ namespace parkMonitor.server
 
             //Task imgTest = Task.Factory.StartNew(() =>
             //{
-            //    while (!closing)
+            //    while (!isClosing)
             //    {
             //        Command cmd = new Command
             //        {
@@ -638,219 +640,219 @@ namespace parkMonitor.server
             //        };
             //        SetMessage(cmd);
             //        Thread.Sleep(5000);
-            //    } 
+            //    }
             //});
 
         }
 
-    /// <summary>
-    /// 系统关闭
-    /// </summary>
-    public void Stop()
-    {
-        VzClientSDK.VZLPRClient_StopFindDevice();
-        Dictionary<int, PictureBox>.Enumerator enumer = devPicMap.GetEnumerator();
-        do
+        /// <summary>
+        /// 系统关闭
+        /// </summary>
+        public void Stop()
         {
-            if (enumer.Current.Key != 0)
+            VzClientSDK.VZLPRClient_StopFindDevice();
+            Dictionary<int, PictureBox>.Enumerator enumer = devPicMap.GetEnumerator();
+            do
             {
-                StopPlay(enumer.Current.Key);
-                VzClientSDK.VzLPRClient_Close(enumer.Current.Key);
-                flowLayoutPanel1.Controls.Remove(enumer.Current.Value);
-            }
-        } while (enumer.MoveNext());
-        closing = true;
-        devPicMap.Clear();
-        picNameMap.Clear();
-        ipIdMap.Clear();
-        ipHandleMap.Clear();
-        //this.Close();
-    }
+                if (enumer.Current.Key != 0)
+                {
+                    StopPlay(enumer.Current.Key);
+                    VzClientSDK.VzLPRClient_Close(enumer.Current.Key);
+                    flowLayoutPanel1.Controls.Remove(enumer.Current.Value);
+                }
+            } while (enumer.MoveNext());
+            isClosing = true;
+            devPicMap.Clear();
+            namePicMap.Clear();
+            ipIdMap.Clear();
+            ipHandleMap.Clear();
+            //this.Close();
+        }
 
-    /// <summary>
-    /// 监控线程获取号牌机信息,核心线程获取号牌信息
-    /// </summary>
-    public AbstractMessage GetMessage()
-    {
-        lock (LicBuffer)
+        /// <summary>
+        /// 监控线程获取号牌机信息,核心线程获取号牌信息
+        /// </summary>
+        public AbstractMessage GetMessage()
         {
-            //准备输出的数据中存在非法Node,且LicBuffer可出队产生一个合法Node,则替换该非法Node,否则让Node=null
-            if (!NodeValidation(nmMsg.aNode))
+            lock (LicBuffer)
             {
-                for (int i = 0; i < LicBuffer.Count; i++)
+                //准备输出的数据中存在非法Node,且LicBuffer可出队产生一个合法Node,则替换该非法Node,否则让Node=null
+                if (!NodeValidation(nmMsg.aNode))
                 {
-                    NumberMachineNode n = LicBuffer.Dequeue();
-                    if (NodeValidation(n))
+                    for (int i = 0; i < LicBuffer.Count; i++)
                     {
-                        if (nmMsg.aNode != null && nmMsg.aNode.ip != null)
+                        NumberMachineNode n = LicBuffer.Dequeue();
+                        if (NodeValidation(n))
                         {
-                            LicBuffer.Enqueue((NumberMachineNode)nmMsg.aNode.Clone());
+                            if (nmMsg.aNode != null && nmMsg.aNode.ip != null)
+                            {
+                                LicBuffer.Enqueue((NumberMachineNode)nmMsg.aNode.Clone());
+                            }
+                            nmMsg.aNode = n;
+                            break;
+                        }
+                        else
+                        {
+                            LicBuffer.Enqueue(n);
                         }
-                        nmMsg.aNode = n;
-                        break;
-                    }
-                    else
-                    {
-                        LicBuffer.Enqueue(n);
                     }
                 }
             }
+            //if (NodeValidation(nmMsg.aNode) && ipIdMap.TryGetValue(nmMsg.aNode.ip, out int id))
+            //{
+            //    nmMsg.aNode.id = id;
+            //}
+            return nmMsg;
         }
-        //if (NodeValidation(nmMsg.aNode) && ipIdMap.TryGetValue(nmMsg.aNode.ip, out int id))
-        //{
-        //    nmMsg.aNode.id = id;
-        //}
-        return nmMsg;
-    }
 
-    /// <summary>
-    /// 一次停车流程完成时调用该方法,发送已完成车辆号牌信息
-    /// </summary>
-    /// <param name="message">已完成车辆的号牌相关信息存于message的aNode中,用于标记需清空的号牌</param>
-    public void SetMessage(AbstractMessage message)
-    {
-        if (message.GetType().Equals(typeof(NumberMachineMessage)))
+        /// <summary>
+        /// 一次停车流程完成时调用该方法,发送已完成车辆号牌信息
+        /// </summary>
+        /// <param name="message">已完成车辆的号牌相关信息存于message的aNode中,用于标记需清空的号牌</param>
+        public void SetMessage(AbstractMessage message)
         {
-            NumberMachineNode n = ((NumberMachineMessage)message).aNode;
-            lock (LicBuffer)
+            if (message.GetType().Equals(typeof(NumberMachineMessage)))
             {
-                //输入号牌格式无误
-                if (n != null && n.ip != null && n.ip == "")
+                NumberMachineNode n = ((NumberMachineMessage)message).aNode;
+                lock (LicBuffer)
                 {
-                    //与类成员变量中aNode号牌相同,将其ip复位表示已使用,重新入队等待清除
-                    if (nmMsg != null && nmMsg.aNode != null && nmMsg.aNode.LicenseNum.Equals(n.LicenseNum))
+                    //输入号牌格式无误
+                    if (n != null && n.ip != null && n.ip == "")
                     {
-                        nmMsg.aNode.ip = "";
-                        LicBuffer.Enqueue((NumberMachineNode)nmMsg.aNode.Clone());
-                        nmMsg.aNode = null;
-                    }
-                    //搜索号牌队列,将相应号牌置空,准备清除
-                    else
-                    {
-                        for (int i = 0; i < LicBuffer.Count; i++)
+                        //与类成员变量中aNode号牌相同,将其ip复位表示已使用,重新入队等待清除
+                        if (nmMsg != null && nmMsg.aNode != null && nmMsg.aNode.LicenseNum.Equals(n.LicenseNum))
+                        {
+                            nmMsg.aNode.ip = "";
+                            LicBuffer.Enqueue((NumberMachineNode)nmMsg.aNode.Clone());
+                            nmMsg.aNode = null;
+                        }
+                        //搜索号牌队列,将相应号牌置空,准备清除
+                        else
                         {
-                            NumberMachineNode temp = LicBuffer.Dequeue();
-                            //已匹配上,ip置空
-                            if (temp.LicenseNum.Equals(n.LicenseNum))
+                            for (int i = 0; i < LicBuffer.Count; i++)
                             {
-                                temp.ip = "";
+                                NumberMachineNode temp = LicBuffer.Dequeue();
+                                //已匹配上,ip置空
+                                if (temp.LicenseNum.Equals(n.LicenseNum))
+                                {
+                                    temp.ip = "";
+                                    LicBuffer.Enqueue(temp);
+                                    break;
+                                }
                                 LicBuffer.Enqueue(temp);
-                                break;
                             }
-                            LicBuffer.Enqueue(temp);
                         }
                     }
                 }
             }
-        }
-        //传入异常号牌,根据ip找到handle,改变snapshotDevHandle的值在回调函数中截图
-        if (message.GetType().Equals(typeof(Command)))
-        {
-            Command cmd = (Command)message;
-            if (cmd != null && cmd.id != 0)
+            //传入异常号牌,根据ip找到handle,改变snapshotDevHandle的值在回调函数中截图
+            if (message.GetType().Equals(typeof(Command)))
             {
-                Dictionary<string, int>.Enumerator enumerator = ipIdMap.GetEnumerator();
-                do
+                Command cmd = (Command)message;
+                if (cmd != null && cmd.id != 0)
                 {
-                   // if (enumerator.Current.Value == cmd.id && ipHandleMap.TryGetValue(enumerator.Current.Key, out int handle))
-                    int handle = 0;
-                     if(enumerator.Current.Value == cmd.id && ipHandleMap.TryGetValue(enumerator.Current.Key, out handle))
+                    Dictionary<string, int>.Enumerator enumerator = ipIdMap.GetEnumerator();
+                    do
                     {
-                        snapshotDevHandle = handle;
-                        break;
-                    }
-                } while (enumerator.MoveNext());
-            }
-            else
-            {
-                UILogServer.ins.error("参数错误,图片未保存");
+                        // if (enumerator.Current.Value == cmd.id && ipHandleMap.TryGetValue(enumerator.Current.Key, out int handle))
+                        int handle = 0;
+                        if (enumerator.Current.Value == cmd.id && ipHandleMap.TryGetValue(enumerator.Current.Key, out handle))
+                        {
+                            snapshotDevHandle = handle;
+                            break;
+                        }
+                    } while (enumerator.MoveNext());
+                }
+                else
+                {
+                    UILogServer.ins.error("参数错误,图片未保存");
+                }
             }
-        }
 
+        }
     }
-}
-public class Win32API
-{
-    [DllImport("User32.dll", EntryPoint = "FindWindow")]
-    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
+    public class Win32API
+    {
+        [DllImport("User32.dll", EntryPoint = "FindWindow")]
+        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
 
-    [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
-    public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
+        [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
+        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
 
-    /// <summary>
-    /// 自定义的结构
-    /// </summary>
-    public struct My_lParam
-    {
-        public int i;
-        public string s;
-    }
-    /// <summary>
-    /// 使用COPYDATASTRUCT来传递字符串
-    /// </summary>
-    [StructLayout(LayoutKind.Sequential)]
-    public struct COPYDATASTRUCT
-    {
-        public IntPtr dwData;
-        public int cbData;
-        [MarshalAs(UnmanagedType.LPStr)]
-        public string lpData;
-    }
-    //消息发送API
-    [DllImport("User32.dll", EntryPoint = "SendMessage")]
-    public static extern int SendMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        int lParam          //参数2
-    );
-
-
-    //消息发送API
-    [DllImport("User32.dll", EntryPoint = "SendMessage")]
-    public static extern int SendMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        ref My_lParam lParam //参数2
-    );
-
-    //消息发送API
-    [DllImport("User32.dll", EntryPoint = "SendMessage")]
-    public static extern int SendMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        ref COPYDATASTRUCT lParam  //参数2
-    );
-
-    //消息发送API
-    [DllImport("User32.dll", EntryPoint = "PostMessage")]
-    public static extern int PostMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        int lParam            // 参数2
-    );
-
-
-    //消息发送API
-    [DllImport("User32.dll", EntryPoint = "PostMessage")]
-    public static extern int PostMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        ref My_lParam lParam //参数2
-    );
-
-    //异步消息发送API
-    [DllImport("User32.dll", EntryPoint = "PostMessage")]
-    public static extern int PostMessage(
-        IntPtr hWnd,        // 信息发往的窗口的句柄
-       int Msg,            // 消息ID
-        int wParam,         // 参数1
-        ref COPYDATASTRUCT lParam  // 参数2
-    );
+        /// <summary>
+        /// 自定义的结构
+        /// </summary>
+        public struct My_lParam
+        {
+            public int i;
+            public string s;
+        }
+        /// <summary>
+        /// 使用COPYDATASTRUCT来传递字符串
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct COPYDATASTRUCT
+        {
+            public IntPtr dwData;
+            public int cbData;
+            [MarshalAs(UnmanagedType.LPStr)]
+            public string lpData;
+        }
+        //消息发送API
+        [DllImport("User32.dll", EntryPoint = "SendMessage")]
+        public static extern int SendMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            int lParam          //参数2
+        );
+
+
+        //消息发送API
+        [DllImport("User32.dll", EntryPoint = "SendMessage")]
+        public static extern int SendMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            ref My_lParam lParam //参数2
+        );
+
+        //消息发送API
+        [DllImport("User32.dll", EntryPoint = "SendMessage")]
+        public static extern int SendMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            ref COPYDATASTRUCT lParam  //参数2
+        );
+
+        //消息发送API
+        [DllImport("User32.dll", EntryPoint = "PostMessage")]
+        public static extern int PostMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            int lParam            // 参数2
+        );
+
+
+        //消息发送API
+        [DllImport("User32.dll", EntryPoint = "PostMessage")]
+        public static extern int PostMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            ref My_lParam lParam //参数2
+        );
+
+        //异步消息发送API
+        [DllImport("User32.dll", EntryPoint = "PostMessage")]
+        public static extern int PostMessage(
+            IntPtr hWnd,        // 信息发往的窗口的句柄
+           int Msg,            // 消息ID
+            int wParam,         // 参数1
+            ref COPYDATASTRUCT lParam  // 参数2
+        );
 
-}
+    }
 }

+ 17 - 19
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -62,9 +62,6 @@ namespace parkMonitor.server
         private int parking_startRobot_address;
         //addresses for laser data to be written to plc
         private int parkingSpaceID_address;
-        private int parkingSpaceX_address;
-        private int parkingSpaceY_address;
-        private int parkingSpaceZ_address;
         //addresses for space info to be written to plc
         private int parkingLaserCenterX_address;
         //parameters(addresses) for Laser monitoring
@@ -100,9 +97,6 @@ namespace parkMonitor.server
                 parkingSpaceID_address = Int32.Parse(ConfigurationManager.AppSettings.Get("parkingSpaceID_address"));
                 park_completed_address = Int32.Parse(ConfigurationManager.AppSettings.Get("park_completed_address"));
                 park_completed_acknowledge_address = Int32.Parse(ConfigurationManager.AppSettings.Get("park_completed_acknowledge_address")); 
-                //parkingSpaceX_address = Int32.Parse(ConfigurationManager.AppSettings.Get("parkingSpaceX_address"));
-                //parkingSpaceY_address = Int32.Parse(ConfigurationManager.AppSettings.Get("parkingSpaceY_address"));
-                //parkingSpaceZ_address = Int32.Parse(ConfigurationManager.AppSettings.Get("parkingSpaceZ_address"));
 
                 fetching_startRobot_address = Int32.Parse(ConfigurationManager.AppSettings.Get("fetching_startRobot_address"));
                 fetch_to_address = Int32.Parse(ConfigurationManager.AppSettings.Get("fetch_to_address"));
@@ -460,11 +454,6 @@ namespace parkMonitor.server
             }
         }
 
-        private void WheelbaseRadarMonitor()
-        {
-
-        }
-
         //***************公有方法****************
         public AbstractMessage GetMessage()
         {
@@ -499,9 +488,9 @@ namespace parkMonitor.server
                 PLCNode pv = (PLCNode)message;
                 SendtoPLC(pv.Address, pv.Value);
             }
-            else if (message.GetType().Equals(typeof(ParkingMessage)))
+            else if (message.GetType().Equals(typeof(ControlMessage)))
             {
-                ParkingMessage pm = (ParkingMessage)message;
+                ControlMessage pm = (ControlMessage)message;
                 if (pm != null && pm.status != 0)
                 {
                     switch (pm.status)
@@ -528,7 +517,7 @@ namespace parkMonitor.server
                                 bool jumpOut = false;
                                 while (!jumpOut)
                                 {
-                                    Thread.Sleep(1000 + (new Random()).Next(5, 10) * 200);
+                                    Thread.Sleep(1000);
                                     if (plcMsg != null && plcMsg.originalPlcList.Count > lpuTemp.laser_status_address)
                                     {
                                         foreach (PLCNode node in plcMsg.originalPlcList)
@@ -541,7 +530,6 @@ namespace parkMonitor.server
                                             }
                                         }
                                     }
-                                    Thread.Sleep(200);
                                 }
                                 SendtoPLC(laser_start_addr, "0");
                                 foreach (LaserMessage lm in plcMsg.laserMsgList)
@@ -755,10 +743,20 @@ namespace parkMonitor.server
                     //after status 3 or 4, start to check laser heartbeat
                     if (value == 3 && !laserMsg.recorded)
                     {
-                        Thread.Sleep(2000);
-                        laser_record = true;
-                        laser_rescan_countdown = LASER_RESCAN_COUNT;
-                        laser_heartbeat_test = true;
+                        if (plc == null)
+                        {
+                            plc = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
+                        }
+                        if (plc != null)
+                        {
+                            //停车指令置0
+                            PLCNode pn = new PLCNode(laser_start_address.ToString(), "0");
+                            plc.SetMessage(pn);
+                            Thread.Sleep(2000);
+                            laser_record = true;
+                            laser_rescan_countdown = LASER_RESCAN_COUNT;
+                            laser_heartbeat_test = true;
+                        }
                     }
 
                     else if (value == 4)