66 lines
2.5 KiB
C#
66 lines
2.5 KiB
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace AGVSystem.A17168
|
|
{
|
|
/// <summary>
|
|
/// 第三方交管自动归还路权监听
|
|
/// </summary>
|
|
public class TrafficCtrl
|
|
{
|
|
/// <summary>
|
|
/// 获取AGV当前地标
|
|
/// </summary>
|
|
private static int Agv_Land(int agvid)
|
|
{
|
|
for (byte b = 0; b < Func.AgvInfo.Length; b++)
|
|
{
|
|
if (Func.AgvInfo[b].Agv_ID == agvid)
|
|
{
|
|
return Func.AgvInfo[b].Location_Display;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 监听线程:占用超过AutoTime秒的路口自动归还路权
|
|
/// </summary>
|
|
public static void Listen()
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
if (Frm_A17168.businessCtrl?.apiModel == null)
|
|
continue;
|
|
int autoTime = Frm_A17168.businessCtrl.apiModel.AutoTime;
|
|
if (autoTime == 0 || string.IsNullOrEmpty(Frm_A17168.businessCtrl.apiModel.waitRfidList) || Frm_A17168.autoLeavedDic == null || Frm_A17168.autoLeavedDic.Count <= 0)
|
|
continue;
|
|
foreach (TrafficModel item in Frm_A17168.autoLeavedDic)
|
|
{
|
|
if (item.agvId == 0)
|
|
continue;
|
|
if ((DateTime.Now - item.InArea).TotalSeconds > autoTime)
|
|
{
|
|
bool flag = Frm_A17168.businessCtrl.ByLeaved(item.agvId.ToString(), Agv_Land(item.agvId).ToString(), item.areaCode.ToString());
|
|
WriteTxt.SaveLog1(item.areaCode.ToString() + "自动释放,返回的值" + flag, "放行日志" + item.agvId, "插件日志");
|
|
if (flag)
|
|
{
|
|
Frm_A17168.leavedDic[item.agvId] = 0;
|
|
item.agvId = 0;
|
|
WriteTxt.SaveLog1(item.areaCode.ToString() + "路口已自动归还", "放行日志" + item.agvId, "插件日志");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteTxt.SaveLog1("第三方交管监听线程异常!" + ex.ToString(), "异常日志", "插件日志");
|
|
}
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|