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