123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.WaferHolder;
- using CyberX8_RT.Modules.Loader;
- using CyberX8_RT.Modules;
- using CyberX8_RT.Schedulers;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MECF.Framework.Common.Jobs;
- using CyberX8_RT.Modules.PUF;
- using CyberX8_Core;
- using CyberX8_RT.Modules.Transporter;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.RecipeCenter;
- namespace CyberX8_RT.Dispatch
- {
- public class WaferHolderTaskManager : Singleton<WaferHolderTaskManager>
- {
- #region 内部变量
- /// <summary>
- /// wafer Holder task字典(key-id,value-waferHolderTask实例)
- /// </summary>
- private ConcurrentDictionary<string, WaferHolderTask> _waferHolderTaskDic = new ConcurrentDictionary<string, WaferHolderTask>();
- /// <summary>
- /// WaferTask集合
- /// </summary>
- private List<WaferHolderTask> _waferTaskList = new List<WaferHolderTask>();
- /// <summary>
- /// WaferTask锁
- /// </summary>
- private object _waferHolderTaskObject = new object();
- #endregion
- /// <summary>
- /// 创建任务
- /// </summary>
- public bool CreateWaferHolderTask(List<ProcessJobInfo> jobs)
- {
- SequenceRecipe sequenceRecipe = jobs[0].SequenceRecipe;
- List<string> chemistries = SchedulerSequenceRecipeManager.Instance.GetSequenceChemistry(sequenceRecipe);
- WaferSize waferSize = (WaferSize)sequenceRecipe.SubstrateSize;
- WaferHolderInfo waferHolderInfo = SchedulerManager.Instance.GetAvaibleBufferToLoaderWaferHolder(waferSize,sequenceRecipe.CrsType,chemistries);
- if (waferHolderInfo != null && CheckWaferHolderNotExist(waferHolderInfo))
- {
- if (CheckEnableCreateWaferHolderTask())
- {
- if(!Enum.TryParse(waferHolderInfo.CurrentLocation,out ModuleName locationModuleName))
- {
- return false;
- }
- if (ModuleHelper.IsBuffer(locationModuleName)&&string.IsNullOrEmpty(waferHolderInfo.OriginalBuffer))
- {
- waferHolderInfo.OriginalBuffer = waferHolderInfo.CurrentLocation;
- }
- WaferHolderTask waferHolderTask = new WaferHolderTask(waferHolderInfo, jobs[0]);
- waferHolderTask.OnTaskComplete += WaferHolderTask_OnTaskComplete;
- WaferInfo waferInfo = GetPreLoaderHasWafer();
- int productWaferCount = 0;
- int dummyWaferCount = 0;
- if (waferInfo==null)
- {
- var result= WaferTaskManager.Instance.CreateWaferTask(jobs, waferHolderInfo, waferHolderTask);
- productWaferCount = result.productWaferCount;
- dummyWaferCount= result.dummyWaferCount;
- }
- else
- {
- if(!CheckWaferMatchedWaferHolderTaskNotCreated(waferInfo))
- {
- return false;
- }
- string waferHasMatch = WaferTaskManager.Instance.CheckWaferHasMatch(waferInfo.WaferID);
- if(string.IsNullOrEmpty(waferHasMatch))
- {
- if (waferInfo.WaferType == WaferType.Production)
- {
- productWaferCount = 1;
- dummyWaferCount = 0;
- }
- else
- {
- productWaferCount = 0;
- dummyWaferCount = 1;
- }
- }
- else
- {
- WaferInfo matchWafer = WaferManager.Instance.GetWaferByWaferId(waferHasMatch);
- if (matchWafer == null || matchWafer.IsEmpty)
- {
- if (waferInfo.WaferType == WaferType.Production)
- {
- productWaferCount = 1;
- }
- else
- {
- dummyWaferCount = 1;
- }
- }
- else
- {
- if (waferInfo.WaferType == WaferType.Production)
- {
- productWaferCount = 1;
- }
- else
- {
- dummyWaferCount = 1;
- }
- if (matchWafer.WaferType == WaferType.Production)
- {
- productWaferCount += 1;
- }
- else
- {
- dummyWaferCount += 1;
- }
- }
- }
- }
- if(productWaferCount+dummyWaferCount == 0)
- {
- return false;
- }
- _waferHolderTaskDic.TryAdd(waferHolderTask.ID, waferHolderTask);
- lock (_waferHolderTaskObject)
- {
- _waferTaskList.Add(waferHolderTask);
- }
- LOG.WriteLog(eEvent.EV_SEQUENCE, "Scheduler", $"Create wafer Shuttle {waferHolderInfo.Id} task");
- List<SchedulerSequence> sequences = SchedulerSequenceManager.Instance.AnalyWaferHolderAllSchedulerSequence(waferHolderInfo, jobs[0].SequenceRecipe,productWaferCount,dummyWaferCount);
- waferHolderTask.InitialSchedulers(sequences);
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 查看Wafer对应的WaferHolderTask是否已经创建
- /// </summary>
- /// <param name="waferInfo"></param>
- /// <returns></returns>
- private bool CheckWaferMatchedWaferHolderTaskNotCreated(WaferInfo waferInfo)
- {
- WaferHolderTask waferHolderTask = WaferTaskManager.Instance.GetWaferHolderTaskByWaferId(waferInfo.WaferID);
- return waferHolderTask == null || CheckWaferHolderNotExist(waferHolderTask.WaferHolderInfo);
- }
- /// <summary>
- /// 检验是否可以创建WaferHolderTask
- /// </summary>
- /// <returns></returns>
- private bool CheckEnableCreateWaferHolderTask()
- {
- TransporterEntity loaderTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter2.ToString());
- LoaderEntity loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
- if (loaderEntity == null)
- {
- return false;
- }
- if (loaderEntity.IsError)
- {
- return false;
- }
- if (loaderTransporterEntity == null)
- {
- return false;
- }
- if (loaderEntity.WaferHolderInfo != null)
- {
- return false;
- }
- if (loaderTransporterEntity.IsError)
- {
- return false;
- }
- //if (loaderTransporterEntity.WaferHolderInfo != null)
- //{
- // return false;
- //}
- //if (loaderTransporterEntity.IsBusy)
- //{
- // return false;
- //}
- //存在其他任务没有完成Loader调度
- if (CheckExistWaferHolderTaskNotOverLoader())
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检验Loader前面是否存在Wafer
- /// </summary>
- /// <returns></returns>
- public WaferInfo GetPreLoaderHasWafer()
- {
- WaferInfo waferInfo = null;
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
- {
- waferInfo = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0);
- return CheckWaferTaskForward(waferInfo);
- }
- if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0))
- {
- waferInfo = WaferManager.Instance.GetWafer(ModuleName.Aligner1, 0);
- return CheckWaferTaskForward(waferInfo);
- }
- //PUF1 B面
- if(WaferManager.Instance.CheckHasWafer(ModuleName.PUF1,1))
- {
- waferInfo = WaferManager.Instance.GetWafer(ModuleName.PUF1, 1);
- return CheckWaferTaskForward(waferInfo);
- }
- return waferInfo;
- }
- /// <summary>
- /// 检验Wafer是否在于Loader之前
- /// </summary>
- /// <param name="waferInfo"></param>
- /// <returns></returns>
- private WaferInfo CheckWaferTaskForward(WaferInfo waferInfo)
- {
- if (!WaferTaskManager.Instance.Contains(waferInfo.WaferID))
- {
- return null;
- }
- WaferTask waferTask = WaferTaskManager.Instance.GetWaferTask(waferInfo.WaferID);
- if (waferTask == null)
- {
- return null;
- }
- if (waferTask.IsSchedulerForward())
- {
- return waferInfo;
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 创建Dummy WaferHolder Task
- /// </summary>
- public void CreateDummyWaferHolderTask()
- {
- List<WaferHolderInfo> waferHolderInfos = DummyWaferManager.Instance.LoadCompletedWaferHolderInfo();
- foreach (WaferHolderInfo waferHolderInfo in waferHolderInfos)
- {
- if (CheckWaferHolderNotExist(waferHolderInfo))
- {
- if (CheckEnableCreateWaferHolderTask())
- {
- int waferTaskCount = 0;
- WaferInfo waferInfo = GetPreLoaderHasWafer();
- if (waferInfo == null)
- {
- List<WaferInfo> waferInfos = DummyWaferManager.Instance.LoadDummyWafersByWaferHolder(waferHolderInfo);
- if (waferInfos.Count != 0)
- {
- WaferHolderTask waferHolderTask = new WaferHolderTask(waferHolderInfo, null);
- waferHolderTask.OnTaskComplete += WaferHolderTask_OnTaskComplete;
- waferTaskCount = WaferTaskManager.Instance.CreateDummyWaferTask(waferInfos, waferHolderInfo.SequenceRecipe, waferHolderTask);
- if (waferTaskCount == 0)
- {
- break;
- }
- _waferHolderTaskDic.TryAdd(waferHolderTask.ID, waferHolderTask);
- lock (_waferHolderTaskObject)
- {
- _waferTaskList.Add(waferHolderTask);
- }
- LOG.WriteLog(eEvent.EV_SEQUENCE, "Scheduler", $"Create dummy wafer Shuttle {waferHolderInfo.Id} task");
- List<SchedulerSequence> sequences = SchedulerSequenceManager.Instance.AnalyseDummyWaferHolderAllSchedulerSequence(waferHolderInfo,0, waferTaskCount);
- waferHolderTask.InitialSchedulers(sequences);
- break;
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// wafer Holder Task完成事件
- /// </summary>
- /// <param name="id"></param>
- private void WaferHolderTask_OnTaskComplete(string id)
- {
- RemoveById(id);
- }
- /// <summary>
- /// 检验WaferHolderTask是否完成Loader调度
- /// </summary>
- /// <returns></returns>
- private bool CheckExistWaferHolderTaskNotOverLoader()
- {
- List<WaferHolderTask> waferHolderTasks = _waferHolderTaskDic.Values.ToList();
- foreach(var task in waferHolderTasks)
- {
- if (task.IsNotPassLoader())
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 是否包含该任务
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool CheckWaferHolderNotExist(WaferHolderInfo waferHolderInfo)
- {
- List<WaferHolderTask> waferHolderTasks = _waferHolderTaskDic.Values.ToList();
- return waferHolderTasks.Find(O => O.WaferHolderInfo.Id == waferHolderInfo.Id) == null;
- }
- /// <summary>
- /// 移除
- /// </summary>
- /// <param name="id"></param>
- public void RemoveById(string id)
- {
- if (_waferHolderTaskDic.ContainsKey(id))
- {
- _waferHolderTaskDic.TryRemove(id, out var waferHolderTask);
- waferHolderTask.Dispose();
- waferHolderTask.OnTaskComplete -= WaferHolderTask_OnTaskComplete;
- LOG.WriteBackgroundLog(eEvent.EV_SCHEDULER, "Scheduler", $"remove wafer Shuttle {waferHolderTask.WaferHolderInfo.Id} task");
- }
- lock (_waferHolderTaskObject)
- {
- int index = _waferTaskList.FindIndex(O => O.ID == id);
- if (index != -1)
- {
- _waferTaskList.RemoveAt(index);
- }
- }
- }
- /// <summary>
- /// 加载WaferHolder任务集合
- /// </summary>
- /// <returns></returns>
- public List<WaferHolderTask> LoaderWaferHolderTaskList()
- {
- lock (_waferHolderTaskObject)
- {
- return _waferTaskList;
- }
- }
- /// <summary>
- /// 检验所有task是否完成
- /// </summary>
- /// <returns></returns>
- public bool CheckAllTaskComplete()
- {
- return _waferTaskList.Count == 0;
- }
- /// <summary>
- /// 暂停
- /// </summary>
- public void PauseAllTask()
- {
- List<WaferHolderTask> waferHolderTasks = _waferHolderTaskDic.Values.ToList();
- foreach (WaferHolderTask item in waferHolderTasks)
- {
- item.Pause();
- }
- }
- /// <summary>
- /// 恢复所有任务
- /// </summary>
- public void ResumeAllTask()
- {
- List<WaferHolderTask> waferHolderTasks = _waferHolderTaskDic.Values.ToList();
- foreach (WaferHolderTask item in waferHolderTasks)
- {
- item.Resume();
- }
- }
- /// <summary>
- /// 移除所有任务
- /// </summary>
- public void RemoveAllTask()
- {
- List<WaferHolderTask> waferHolderTasks = _waferHolderTaskDic.Values.ToList();
- foreach (WaferHolderTask item in waferHolderTasks)
- {
- RemoveById(item.ID);
- }
- }
- /// <summary>
- /// 中止WaferHolderTask
- /// </summary>
- /// <param name="processJobInfo"></param>
- public void AbortWaferHolderTaskByProcessJob(ProcessJobInfo processJobInfo)
- {
- List<string> keys = _waferHolderTaskDic.Keys.ToList();
- foreach (string key in keys)
- {
- WaferHolderTask waferHolderTask = _waferHolderTaskDic[key];
- if(waferHolderTask!=null&&waferHolderTask.ProcessJobInfo!=null&&waferHolderTask.ProcessJobInfo.InnerId == processJobInfo.InnerId)
- {
- _waferHolderTaskDic.TryRemove(key, out waferHolderTask);
- RemoveById(waferHolderTask.ID);
- LOG.WriteBackgroundLog(eEvent.EV_SCHEDULER, "Scheduler", $"remove wafer Shuttle {waferHolderTask.WaferHolderInfo.Id} task");
- }
- }
- }
- /// <summary>
- /// 是否存在其他WaferTask没有
- /// </summary>
- /// <returns></returns>
- private bool CheckExistWaferHolderTaskNotStart()
- {
- List<WaferHolderTask> tmp = _waferHolderTaskDic.Values.ToList();
- foreach (WaferHolderTask item in tmp)
- {
- if (item.State == WaferHolderTaskState.Created)
- {
- return true;
- }
- }
- return false;
- }
- }
- }
|