|
|
@ -39,7 +39,12 @@ namespace Aucma.Scada.Business
|
|
|
|
|
|
|
|
|
|
|
|
private TaskHandleBusiness taskHandleBusiness = TaskHandleBusiness.Instance;
|
|
|
|
private TaskHandleBusiness taskHandleBusiness = TaskHandleBusiness.Instance;
|
|
|
|
|
|
|
|
|
|
|
|
private Semaphore m_SendTaskSem = new Semaphore(0, 100000);
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 出库任务等待反馈信号量
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private Semaphore m_ShellTaskSem = new Semaphore(0, 1);
|
|
|
|
|
|
|
|
private Semaphore m_LinerTaskSem = new Semaphore(0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化出库任务
|
|
|
|
/// 初始化出库任务
|
|
|
@ -65,13 +70,10 @@ namespace Aucma.Scada.Business
|
|
|
|
public delegate void RefreshLogMessage(string message);
|
|
|
|
public delegate void RefreshLogMessage(string message);
|
|
|
|
public event RefreshLogMessage RefreshLogMessageEvent;
|
|
|
|
public event RefreshLogMessage RefreshLogMessageEvent;
|
|
|
|
|
|
|
|
|
|
|
|
public OutStoreBusiness()
|
|
|
|
private OutStoreBusiness()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle;
|
|
|
|
assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle;
|
|
|
|
Task.Run(() =>
|
|
|
|
StartPassDown();
|
|
|
|
{
|
|
|
|
|
|
|
|
StartTimerPassDown();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -123,6 +125,7 @@ namespace Aucma.Scada.Business
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//报警停线
|
|
|
|
//报警停线
|
|
|
|
|
|
|
|
PrintLogInfoMessage($"{storeCode};仓库内未获取到{bomInfo.materialCode}相匹配的物料及货道");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -231,70 +234,140 @@ namespace Aucma.Scada.Business
|
|
|
|
_spaceInfoService.UpdateSpaceInfo(spaceInfo);
|
|
|
|
_spaceInfoService.UpdateSpaceInfo(spaceInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 开启定时获取出库任务下发至PLC,等待PLC执行反馈,完成后再次下发
|
|
|
|
#region 轮询获取出库任务下发至PLC,等待PLC执行反馈,完成后再次下发
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
|
|
|
|
|
|
|
|
private int completedTasks = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private System.Timers.Timer timer = new System.Timers.Timer(5000);
|
|
|
|
private int taskAmount = 2;
|
|
|
|
|
|
|
|
|
|
|
|
private void StartTimerPassDown()
|
|
|
|
private void StartPassDown()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//try
|
|
|
|
while (true)
|
|
|
|
//{
|
|
|
|
{
|
|
|
|
// if (!timer.Enabled)
|
|
|
|
PassDownTaskInfo();
|
|
|
|
// {
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
// timer.Elapsed += new System.Timers.ElapsedEventHandler(PassDownTaskInfoByTimer);
|
|
|
|
}
|
|
|
|
// timer.AutoReset = true;
|
|
|
|
});
|
|
|
|
// timer.Enabled = false;
|
|
|
|
|
|
|
|
// timer.Start();
|
|
|
|
|
|
|
|
// PrintLogInfoMessage("StartTimerPassDown(),开启定时获取出库任务进行下发");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//catch (Exception ex)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// PrintLogErrorMessage("开启定时下发出库任务异常", ex);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 依次获取任务队列进行下发
|
|
|
|
/// 依次获取任务队列进行下发
|
|
|
|
/// object sender, System.Timers.ElapsedEventArgs e
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="source"></param>
|
|
|
|
/// <param name="source"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private bool PassDownTaskInfoByTimer()
|
|
|
|
private void PassDownTaskInfo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<RealTaskInfo> realTasks = new List<RealTaskInfo>();
|
|
|
|
completedTasks = 0;
|
|
|
|
RealTaskInfo shellTask = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, 2);
|
|
|
|
|
|
|
|
RealTaskInfo linerTaks = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, 2);
|
|
|
|
|
|
|
|
if(shellTask != null && linerTaks != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (shellTask.taskStatus != 2 && linerTaks.taskStatus != 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
shellTask.taskStatus = 2;
|
|
|
|
|
|
|
|
linerTaks.taskStatus = 2;
|
|
|
|
|
|
|
|
realTasks.Add(shellTask);
|
|
|
|
|
|
|
|
realTasks.Add(linerTaks);
|
|
|
|
|
|
|
|
bool result = _taskInfoService.UpdateRangeTaskInfo(realTasks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
//获取待执行的出库任务下发至PLC,并将任务状态改为执行中
|
|
|
|
|
|
|
|
var taskInfoList = GetAwaitSendTask();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (taskInfoList.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GetAllRelese(m_SendTaskSem);
|
|
|
|
taskAmount = taskInfoList.Count; //下发的任务数量,默认2(箱壳、内胆),箱壳、内胆均执行完成后才会释放信号量
|
|
|
|
foreach (var item in realTasks)
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in taskInfoList)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
//taskHandleBusiness.SendOutStoreTask(item);
|
|
|
|
|
|
|
|
PrintLogInfoMessage($"下发出库任务:{item.taskCode};仓库{item.storeCode};货道:{item.spaceCode}");
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode);
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode);
|
|
|
|
taskHandleBusiness.SendOutStoreTask(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_SendTaskSem.WaitOne(5000, false))
|
|
|
|
|
|
|
|
|
|
|
|
if (semaphore.Wait(TimeSpan.FromSeconds(20)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
// 收到反馈
|
|
|
|
|
|
|
|
PrintLogInfoMessage("收到反馈,继续执行");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
PrintLogInfoMessage("超时未反馈");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//semaphore.Wait(); //一直堵塞直到信号量释放
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PrintLogInfoMessage("未获取到需要下发的出库任务");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取待执行的出库任务
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
private List<RealTaskInfo> GetAwaitSendTask()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
List<RealTaskInfo> taskInfos = new List<RealTaskInfo>();
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode,2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(shellTaskInfo != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//获取与箱壳任务匹配的内胆任务
|
|
|
|
|
|
|
|
RealTaskInfo linerTaskInfo = _taskInfoService.GetTaskInfoByTaskCode(shellTaskInfo.taskCode, appConfig.linerStoreCode);
|
|
|
|
|
|
|
|
taskInfos.Add(shellTaskInfo);
|
|
|
|
|
|
|
|
if (linerTaskInfo != null) taskInfos.Add(linerTaskInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(taskInfos.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
taskInfos.ForEach(x => x.taskStatus = 2);
|
|
|
|
|
|
|
|
_taskInfoService.UpdateRangeTaskInfo(taskInfos);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PrintLogErrorMessage("获取待执行的出库任务异常", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return taskInfos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 箱壳执行反馈
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void ShellTaskFeedback()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Interlocked.Increment(ref completedTasks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckCompletedTasks();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage("箱壳执行完成,自动释放信号量");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutStoreFinish("", appConfig.shellStoreCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 内胆执行反馈
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void LinerTaskFeedback()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Interlocked.Increment(ref completedTasks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckCompletedTasks();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage("内胆执行完成,自动释放信号量");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutStoreFinish("", appConfig.linerStoreCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 信号量释放,根据任务完成数量,执行完成后进行释放
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void CheckCompletedTasks()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (completedTasks == taskAmount)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 释放信号量
|
|
|
|
|
|
|
|
semaphore.Release();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
@ -306,11 +379,11 @@ namespace Aucma.Scada.Business
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
/// <param name="spaceCode"></param>
|
|
|
|
/// <param name="spaceCode"></param>
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
private void OutStoreFinish(string taskCode)
|
|
|
|
private void OutStoreFinish(string taskCode, string storeCode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var taskInfo = _taskInfoService.GetTaskInfoByTaskCode(taskCode);
|
|
|
|
var taskInfo = _taskInfoService.GetTaskInfoByTaskCode(taskCode, storeCode);
|
|
|
|
if (taskInfo != null)
|
|
|
|
if (taskInfo != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode);
|
|
|
|
var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode);
|
|
|
@ -324,7 +397,7 @@ namespace Aucma.Scada.Business
|
|
|
|
//读取PLC获取物料类型进行绑定
|
|
|
|
//读取PLC获取物料类型进行绑定
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//清除任务信息
|
|
|
|
//清除任务信息
|
|
|
|
_taskInfoService.DeleteTaskInfo(taskCode);
|
|
|
|
_taskInfoService.DeleteTaskInfo(taskCode, storeCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -405,12 +478,15 @@ namespace Aucma.Scada.Business
|
|
|
|
logHelper.Error(message, ex);
|
|
|
|
logHelper.Error(message, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 手动释放信号量
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sph"></param>
|
|
|
|
private void GetAllRelese(Semaphore sph)
|
|
|
|
private void GetAllRelese(Semaphore sph)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool res = sph.WaitOne(1, false);
|
|
|
|
bool res = sph.WaitOne(1, false);
|
|
|
|
if (res)
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// LogHelper.RfidLog("信号量手动释放");
|
|
|
|
|
|
|
|
GetAllRelese(sph);
|
|
|
|
GetAllRelese(sph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|