| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 | 
							- using Aitex.Common.Util;
 
- using Aitex.Core.Common;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using Aitex.Sorter.Common;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.SubstrateTrackings;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using FurnaceRT.Equipments.CarrierRobots;
 
- using FurnaceRT.Equipments.PMs.RecipeExecutions;
 
- using FurnaceRT.Equipments.Schedulers;
 
- using FurnaceRT.Equipments.Systems;
 
- using FurnaceRT.Equipments.WaferRobots;
 
- using MECF.Framework.Common.Jobs;
 
- using FurnaceRT.Equipments.LPs;
 
- using FurnaceRT.Equipments.Stockers;
 
- using Aitex.Core.RT.Log;
 
- using FurnaceRT.Equipments.FIMSs;
 
- using Aitex.Core.RT.DataCenter;
 
- using FurnaceRT.Devices;
 
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
 
- using FurnaceRT.Equipments.PMs;
 
- using MECF.Framework.Common.Tolerance;
 
- using MECF.Framework.Common.CommonData.SorterDefines;
 
- namespace FurnaceRT.Equipments.Jobs
 
- {
 
-     public class TransferJob : SchedulerModuleFactory
 
-     {
 
-         private List<TransferJobInfo> _lstTransferJobs = new List<TransferJobInfo>();
 
-         private SchedulerFACallback _faCallback;
 
-         private SchedulerDBCallback _dbCallback;
 
-         private const string LogSource = "System";
 
-         private LoadPortModule _lp1Module;
 
-         private LoadPortModule _lp2Module;
 
-         public bool HasJobRunning
 
-         {
 
-             get { return _lstTransferJobs.Count > 0; }
 
-         }
 
-         public TransferJob()
 
-         {
 
-             _faCallback = new SchedulerFACallback();
 
-             _dbCallback = new SchedulerDBCallback();
 
-             InitModule();
 
-             _lp1Module = Singleton<EquipmentManager>.Instance.Modules.ContainsKey(ModuleName.LP1) ?
 
-                 Singleton<EquipmentManager>.Instance.Modules[ModuleName.LP1] as LoadPortModule : null;
 
-             _lp2Module = Singleton<EquipmentManager>.Instance.Modules.ContainsKey(ModuleName.LP2) ?
 
-                 Singleton<EquipmentManager>.Instance.Modules[ModuleName.LP2] as LoadPortModule : null;
 
-             DATA.Subscribe($"Scheduler.TransferJobList", () =>
 
-             {
 
-                 return _lstTransferJobs;
 
-             });
 
-             DATA.Subscribe($"Scheduler.CurrentTransferJob", () =>
 
-             {
 
-                 var pj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-                 return pj;
 
-             });
 
-             DATA.Subscribe($"Scheduler.OccupyStockers", () =>
 
-             {
 
-                 return GetOccupyStockers();
 
-             });
 
-         }
 
-         public void ResetTask(ModuleName module)
 
-         {
 
-             if (module == _waferRobot.Module)
 
-                 _waferRobot.ResetTask();
 
-             if (module == _carrierRobot.Module)
 
-                 _carrierRobot.ResetTask();
 
-         }
 
-         public void Clear()
 
-         {
 
-             _carrierRobot.ResetTask();
 
-             _waferRobot.ResetTask();
 
-             foreach (var lp in _lstLPs)
 
-             {
 
-                 lp.ResetTask();
 
-             }
 
-             foreach (var fims in _lstFIMSs)
 
-             {
 
-                 fims.ResetTask();
 
-             }
 
-             _lstTransferJobs.Clear();
 
-         }
 
-         #region Job Management
 
-         public Result CreateJob(params object[] objs)
 
-         {
 
-             if (objs == null || objs.Length == 0)
 
-             {
 
-                 Singleton<EquipmentManager>.Instance.TransferJobStartFailedWarning.Set("Parameter not valid");
 
-                 return Result.FAIL;
 
-             }
 
-             var param = (Dictionary<string, object>)objs[0];
 
-             if (param == null)
 
-             {
 
-                 Singleton<EquipmentManager>.Instance.TransferJobStartFailedWarning.Set("Parameter not valid");
 
-                 return Result.FAIL;
 
-             }
 
-             var content = "";
 
-             foreach (var key in param.Keys)
 
-             {
 
-                 content += $"{key}-{param[key]}#";
 
-             }
 
-             LOG.Write($"Transfer Job: {content}");
 
-             var waferTypeString = param.ContainsKey("WaferType") ? (string)param["WaferType"] : "";
 
-             var transferTypeString = (string)param["TransferType"];
 
-             TransferJobInfo tj = new TransferJobInfo();
 
-             tj.CreateTime = DateTime.Now;
 
-             tj.BatchName = param.ContainsKey("Batch") ? (string)param["Batch"] : "";
 
-             tj.CarrierType = (CarrierType)Enum.Parse(typeof(CarrierType), waferTypeString);
 
-             tj.Type = (EnumTransferJobType)Enum.Parse(typeof(EnumTransferJobType), transferTypeString);
 
-             tj.State = EnumTransferJobState.Created;
 
-             tj.CarrierParas = new List<CarrierPara>();
 
-             tj.FimsCheckOxDensityDict = new Dictionary<string, Tuple<FilterChecker, double>>();
 
-             List<string> carrierIdLst = new List<string>();
 
-             List<ModuleName> moduleLst = new List<ModuleName>();
 
-             foreach (var module in Singleton<EquipmentManager>.Instance.Modules.Keys)
 
-             {
 
-                 if ((Singleton<EquipmentManager>.Instance.Modules[module] is StockerModule) ||
 
-                     (Singleton<EquipmentManager>.Instance.Modules[module] is FIMSModule))
 
-                 {
 
-                     if (CarrierManager.Instance.HasCarrier(module.ToString()))
 
-                     {
 
-                         var carrier = CarrierManager.Instance.GetCarrier(module.ToString());
 
-                         carrierIdLst.Add(carrier.CarrierId);
 
-                         moduleLst.Add(carrier.InternalModuleName);
 
-                     }
 
-                 }
 
-             }
 
-             if (param.ContainsKey("CarrierPara"))
 
-             {
 
-                 if (tj.Type == EnumTransferJobType.Loading)
 
-                 {
 
-                     //Stocker1,P_00000036,25,Exist,1111111111111111111111111,LP1;Stocker2,P_00000037,25,Exist,1111111111111111111111111,LP2
 
-                     var paras = param["CarrierPara"].ToString().Split(';');
 
-                     if (paras != null && paras.Length > 0)
 
-                     {
 
-                         foreach (var item in paras)
 
-                         {
 
-                             var arry = item.Split(',');
 
-                             if (arry != null && arry.Length == 6)
 
-                             {
 
-                                 CarrierPara carrierPara = new CarrierPara()
 
-                                 {
 
-                                     Stocker = ModuleHelper.Converter(arry[0]),
 
-                                     CarrierID = arry[1],
 
-                                     //WaferCount = int.Parse(arry[2]),
 
-                                     IsCompareWithSlotMap = arry[3].ToLower() == "exist",
 
-                                     SlotMap = arry[4],
 
-                                     TargetPort = ModuleHelper.Converter(arry[5]),
 
-                                     CarrierType = tj.CarrierType,
 
-                                 };
 
-                                 if (carrierIdLst.Any(x => x == carrierPara.CarrierID) || moduleLst.Any(x => x == carrierPara.Stocker))
 
-                                 {
 
-                                     Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Carrier ID ={carrierPara.CarrierID} of {carrierPara.Stocker} is already exist");
 
-                                     return Result.FAIL;
 
-                                 }
 
-                                 if (CarrierManager.Instance.HasCarrier($"{carrierPara.Stocker}"))
 
-                                 {
 
-                                     Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is already exist in stocker");
 
-                                     return Result.FAIL;
 
-                                 }
 
-                                 if (!SC.GetValue<bool>("System.IsSimulatorMode"))
 
-                                 {
 
-                                     var stockerModule = Singleton<EquipmentManager>.Instance.Modules[carrierPara.Stocker] as StockerModule;
 
-                                     if (stockerModule != null && stockerModule.IsFoupPresent)
 
-                                     {
 
-                                         Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Cassette of {carrierPara.Stocker} is already exist in stocker");
 
-                                         return Result.FAIL;
 
-                                     }
 
-                                 }
 
-                                 tj.CarrierParas.Add(carrierPara);
 
-                                 carrierIdLst.Add(arry[1]);
 
-                                 moduleLst.Add(carrierPara.Stocker);
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     //Stocker1,LP1;Stocker2,LP2
 
-                     var paras = param["CarrierPara"].ToString().Split(';');
 
-                     if (paras != null && paras.Length > 0)
 
-                     {
 
-                         foreach (var item in paras)
 
-                         {
 
-                             var arry = item.Split(',');
 
-                             CarrierPara carrierPara = null;
 
-                             if (arry != null && arry.Length >= 2)
 
-                             {
 
-                                 //两个参数是Unload,6个参数是Load Process Unload
 
-                                 carrierPara = new CarrierPara()
 
-                                 {
 
-                                     Stocker = ModuleHelper.Converter(arry[0]),
 
-                                     TargetPort = arry.Length == 6 ? ModuleHelper.Converter(arry[5]) : ModuleHelper.Converter(arry[1]),
 
-                                 };
 
-                                 if (arry.Length != 6)
 
-                                 {
 
-                                     if (!CarrierManager.Instance.HasCarrier($"{carrierPara.Stocker}"))
 
-                                     {
 
-                                         Singleton<EquipmentManager>.Instance.UnloadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is not exist in stocker");
 
-                                         return Result.FAIL;
 
-                                     }
 
-                                     if (CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}", 0).InternalModuleName != carrierPara.Stocker)
 
-                                     {
 
-                                         Singleton<EquipmentManager>.Instance.UnloadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is not match stocker module name {CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}", 0).InternalModuleName}");
 
-                                         return Result.FAIL;
 
-                                     }
 
-                                     if (!SC.GetValue<bool>("System.IsSimulatorMode"))
 
-                                     {
 
-                                         var stockerModule = Singleton<EquipmentManager>.Instance.Modules[carrierPara.Stocker] as StockerModule;
 
-                                         if (stockerModule != null && !stockerModule.IsFoupPresent)
 
-                                         {
 
-                                             Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Cassette of {carrierPara.Stocker} is not exist in stocker");
 
-                                             return Result.FAIL;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                             }
 
-                             if (carrierPara != null)
 
-                             {
 
-                                 carrierPara.CarrierID = CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}").CarrierId;
 
-                                 tj.CarrierParas.Add(carrierPara);
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             _lstTransferJobs.Add(tj);
 
-             var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
 
-             foreach (var item in _lstFIMSs)
 
-             {
 
-                 if (!tj.FimsCheckOxDensityDict.ContainsKey(item.Module.ToString()))
 
-                 {
 
-                     tj.FimsCheckOxDensityDict.Add(item.Module.ToString(), Tuple.Create(new FilterChecker(), pm.GetFoupEnterLAO2CheckSV()));
 
-                 }
 
-             }
 
-             return Result.RUN;
 
-         }
 
-         internal void AbortJob(string jobName)
 
-         {
 
-             var tj = _lstTransferJobs.Find(x => x.Name == jobName);
 
-             if (tj == null)
 
-             {
 
-                 EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
 
-                 return;
 
-             }
 
-             tj.State = EnumTransferJobState.Aborting;
 
-         }
 
-         internal void CancelUnloadingJob(string port, string CarrierId)
 
-         {
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null)
 
-             {
 
-                 EV.PostWarningLog(LogSource, $"cancel unloading job rejected, not found job with CarrierId {CarrierId}");
 
-                 return;
 
-             }
 
-             var carrierPara = tj.CarrierParas.Find(x => x.TargetPort.ToString() == port && x.CarrierID == CarrierId);
 
-             if (carrierPara != null)
 
-                 tj.CarrierParas.Remove(carrierPara);
 
-         }
 
-         internal bool StartJob(string jobName)
 
-         {
 
-             return true;
 
-         }
 
-         #endregion Job Management
 
-         public Result Monitor()
 
-         {
 
-             TransferJobInfo tjActive = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tjActive != null)
 
-             {
 
-                 MonitorModuleTasks();
 
-             }
 
-             MonitorJobTasks();
 
-             UpdateLoadPortLotIDList();
 
-             return Result.RUN;
 
-         }
 
-         public bool CheckAllJobDone()
 
-         {
 
-             foreach (var tj in _lstTransferJobs)
 
-             {
 
-                 if (tj.State == EnumTransferJobState.Created ||
 
-                     tj.State == EnumTransferJobState.Active)
 
-                     return false;
 
-             }
 
-             return true;
 
-         }
 
-         private void UpdateLoadPortLotIDList()
 
-         {
 
-             TransferJobInfo tjActive = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tjActive != null && tjActive.CarrierParas != null)
 
-             {
 
-                 if (_lp1Module != null)
 
-                 {
 
-                     _lp1Module.CurrentLotId = "";
 
-                 }
 
-                 if (_lp2Module != null)
 
-                 {
 
-                     _lp2Module.CurrentLotId = "";
 
-                 }
 
-                 List<string> lp1WaitLotId = new List<string>();
 
-                 List<string> lp2WaitLotId = new List<string>();
 
-                 foreach (var item in tjActive.CarrierParas)
 
-                 {
 
-                     if ((tjActive.Type == EnumTransferJobType.Loading && !item.IsLoaded) ||
 
-                         (tjActive.Type == EnumTransferJobType.Unloading && !item.IsUnloaded))
 
-                     {
 
-                         var lpModule = Singleton<EquipmentManager>.Instance.Modules[item.TargetPort] as LoadPortModule;
 
-                         if (lpModule != null && item.TargetPort == ModuleName.LP1 && string.IsNullOrEmpty(lpModule.CurrentLotId))
 
-                         {
 
-                             _lp1Module.CurrentLotId = item.CarrierID;
 
-                         }
 
-                         if (lpModule != null && item.TargetPort == ModuleName.LP2 && string.IsNullOrEmpty(lpModule.CurrentLotId))
 
-                         {
 
-                             _lp2Module.CurrentLotId = item.CarrierID;
 
-                         }
 
-                         if (item.TargetPort == ModuleName.LP1)
 
-                         {
 
-                             lp1WaitLotId.Add(item.CarrierID);
 
-                         }
 
-                         if (item.TargetPort == ModuleName.LP2)
 
-                         {
 
-                             lp2WaitLotId.Add(item.CarrierID);
 
-                         }
 
-                     }
 
-                 }
 
-                 if (_lp1Module != null)
 
-                 {
 
-                     _lp1Module.WaitLotId = lp1WaitLotId;
 
-                 }
 
-                 if (_lp2Module != null)
 
-                 {
 
-                     _lp2Module.WaitLotId = lp2WaitLotId;
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 if (_lp1Module != null)
 
-                 {
 
-                     _lp1Module.CurrentLotId = "";
 
-                     if (_lp1Module.WaitLotId == null || _lp1Module.WaitLotId.Any())
 
-                         _lp1Module.WaitLotId = new List<string>();
 
-                 }
 
-                 if (_lp2Module != null)
 
-                 {
 
-                     _lp2Module.CurrentLotId = "";
 
-                     if (_lp2Module.WaitLotId == null || _lp2Module.WaitLotId.Any())
 
-                         _lp2Module.WaitLotId = new List<string>();
 
-                 }
 
-             }
 
-         }
 
-         #region Module task
 
-         public Result MonitorModuleTasks()
 
-         {
 
-             MonitorLPClampInLoadingTask();
 
-             MonitorCarrierRobotTask();
 
-             MonitorWaferRobotTask();
 
-             MonitorLPTask();
 
-             MonitorFIMSTask();
 
-             return Result.RUN;
 
-         }
 
-         private void MonitorLPClampInLoadingTask()
 
-         {
 
-             if (!_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             if (tj.Type == EnumTransferJobType.Loading)
 
-             {
 
-                 foreach (var lp in _lstLPs)
 
-                 {
 
-                     if (!lp.IsAvailable)
 
-                         continue;
 
-                     if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
 
-                         continue;
 
-                     var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
 
-                     if (lpModule.LPDevice.IsFoupPresent)
 
-                     {
 
-                         //FOUP放上去之后,先上锁
 
-                         if (!lpModule.IsClamp && lpModule.LPDevice.Clamp(out _))
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorLPTask()
 
-         {
 
-             if (!_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             if (tj.Type == EnumTransferJobType.Loading)
 
-             {
 
-                 foreach (var lp in _lstLPs)
 
-                 {
 
-                     if (!lp.IsAvailable)
 
-                         continue;
 
-                     if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
 
-                         continue;
 
-                     var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
 
-                     if (lpModule.LPDevice.IsFoupPresent)
 
-                     {
 
-                         //FOUP放上去之后,先上锁
 
-                         if (!lpModule.IsClamp && lpModule.LPDevice.Clamp(out _))
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         //空的,先松开锁
 
-                         if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             else if (tj.Type == EnumTransferJobType.Unloading)
 
-             {
 
-                 foreach (var lp in _lstLPs)
 
-                 {
 
-                     if (!lp.IsAvailable)
 
-                         continue;
 
-                     if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
 
-                         continue;
 
-                     var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
 
-                     if (lpModule.LPDevice.IsFoupPresent)
 
-                     {
 
-                         if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         //空的,先松开锁
 
-                         if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorFIMSTask()
 
-         {
 
-             var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
 
-             if (!_lstTransferJobs.Any() || SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             if (tj.Type == EnumTransferJobType.Loading)
 
-             {
 
-                 var hasNotMappedCarrier = false;
 
-                 var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-                 if (robotCarrier != null && !robotCarrier.IsEmpty && !robotCarrier.IsMapped)
 
-                 {
 
-                     if (tj.CarrierParas.Any(x => x.Stocker == robotCarrier.InternalModuleName && x.IsLoaded))
 
-                     {
 
-                         hasNotMappedCarrier = true;
 
-                     }
 
-                 }
 
-                 foreach (var item in tj.CarrierParas)
 
-                 {
 
-                     var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
 
-                     if (carrier == null || carrier.IsEmpty || carrier.IsMapped)
 
-                         continue;
 
-                     if (item.IsLoaded)
 
-                     {
 
-                         hasNotMappedCarrier = true;
 
-                         break;
 
-                     }
 
-                 }
 
-                 bool haveLoadingFims = false;
 
-                 foreach (var fims in _lstFIMSs)
 
-                 {
 
-                     if ((Singleton<EquipmentManager>.Instance.Modules[fims.Module] as FIMSModule).IsLoading)
 
-                     {
 
-                         haveLoadingFims = true;
 
-                         break;
 
-                     }
 
-                 }
 
-                 foreach (var fims in _lstFIMSs)
 
-                 {
 
-                     if (!fims.IsAvailable)
 
-                         continue;
 
-                     var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{fims.Module}");
 
-                     if (CarrierManager.Instance.CheckNoCarrier(fims.Module, 0))
 
-                     {
 
-                         if (hasNotMappedCarrier && fimsDevice.IsWaferRobotEX1AxisHomePosition && fimsDevice.IsWaferRobotEX2AxisHomePosition &&
 
-                             !fimsDevice.IsUnloadCompleted && fims.Unload())
 
-                         {
 
-                             return;
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
 
-                         if (carrier == null || carrier.IsEmpty)
 
-                             continue;
 
-                         if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName && x.IsLoaded))
 
-                         {
 
-                             if (carrier.IsMapped && fimsDevice.IsWaferRobotEX1AxisHomePosition && fimsDevice.IsWaferRobotEX2AxisHomePosition &&
 
-                                 !fimsDevice.IsUnloadCompleted)
 
-                             {
 
-                                 if (fims.Unload())
 
-                                 {
 
-                                     return;
 
-                                 }
 
-                             }
 
-                             if (!haveLoadingFims && !carrier.IsMapped && !fimsDevice.IsLoadCompleted)
 
-                             {
 
-                                 var foupEnterFIMSN2purgeConfig = pm.GetFoupEnterFIMSN2purgeConfig();
 
-                                 var foupEnterLAO2CheckSV = pm.GetFoupEnterLAO2CheckSV();
 
-                                 var lACurrectN2purgeMode = pm.GetLACurrectN2purgeMode();
 
-                                 if (!SC.GetValue<bool>("System.IsSimulatorMode"))
 
-                                 {
 
-                                     var fims1Device = DEVICE.GetDevice<IoFIMS>($"PM1.FIMS1");
 
-                                     var fims2Device = DEVICE.GetDevice<IoFIMS>($"PM1.FIMS2");
 
-                                     if (fims.Module == ModuleName.FIMS1 && fims2Device.IsRunning)
 
-                                         continue;
 
-                                     if (fims.Module == ModuleName.FIMS2 && fims1Device.IsRunning)
 
-                                         continue;
 
-                                 }
 
-                                 var CheckFimsIsNeedOxygenPressure = pm.CheckFimsIsNeedOxygenPressure(foupEnterFIMSN2purgeConfig, "", out var isCheckO2, false);
 
-                                 if (isCheckO2)
 
-                                 {
 
-                                     tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.CheckInterval = 1;
 
-                                     tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Monitor(pm.GetN2PurgeUnder20PPMStatus(foupEnterLAO2CheckSV) && pm.CheckIsLASide());
 
-                                     if (tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Trig)
 
-                                     {
 
-                                         if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
 
-                                         {
 
-                                             tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Restart();
 
-                                             LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load,wait FoupEnter 。a");
 
-                                             return;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                                 else
 
-                                 {
 
-                                     if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
 
-                                     {
 
-                                         LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load, direct FoupEnter 。b");
 
-                                         return;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             else if (tj.Type == EnumTransferJobType.Unloading)
 
-             {
 
-                 //do nothing
 
-             }
 
-         }
 
-         private void MonitorWaferRobotTask()
 
-         {
 
-             if (!_waferRobot.IsAvailable)
 
-                 return;
 
-             //wafer robot is idle, release all the target 
 
-             foreach (var fims in _lstFIMSs)
 
-             {
 
-                 if (fims.IsWaitTransfer(ModuleName.WaferRobot))
 
-                 {
 
-                     fims.StopWaitTransfer(ModuleName.WaferRobot);
 
-                 }
 
-             }
 
-             MonitorWaferRobotFIMSTask();
 
-         }
 
-         private void MonitorWaferRobotFIMSTask()
 
-         {
 
-             if (!_waferRobot.IsAvailable || !_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             foreach (var fims in _lstFIMSs)
 
-             {
 
-                 if (!fims.IsAvailable)
 
-                     continue;
 
-                 if (!CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
 
-                     continue;
 
-                 var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{fims.Module}");
 
-                 if (!fimsDevice.IsLoadCompleted)
 
-                     continue;
 
-                 var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
 
-                 if (carrier == null || carrier.IsEmpty || carrier.IsMapped || SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                     continue;
 
-                 if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                 {                 
 
-                     var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
 
-                     if (carrierPara != null && _waferRobot.Map(fims.Module, carrierPara.WaferCount, carrierPara.SlotMap, carrierPara.IsCompareWithSlotMap, true, Hand.Blade1))
 
-                     {
 
-                         fims.WaitTransfer(ModuleName.WaferRobot);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorCarrierRobotTask()
 
-         {
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             //carrier robot is idle, release all the target 
 
-             foreach (var stocker in _lstTotlaStockers)
 
-             {
 
-                 if (stocker.IsWaitTransfer(ModuleName.CarrierRobot))
 
-                 {
 
-                     stocker.StopWaitTransfer(ModuleName.CarrierRobot);
 
-                 }
 
-             }
 
-             foreach (var fims in _lstFIMSs)
 
-             {
 
-                 if (fims.IsWaitTransfer(ModuleName.CarrierRobot))
 
-                 {
 
-                     fims.StopWaitTransfer(ModuleName.CarrierRobot);
 
-                 }
 
-             }
 
-             foreach (var lp in _lstLPs)
 
-             {
 
-                 if (lp.IsWaitTransfer(ModuleName.CarrierRobot))
 
-                 {
 
-                     lp.StopWaitTransfer(ModuleName.CarrierRobot);
 
-                 }
 
-             }
 
-             MonitorCarrierRobotFIMSTask();
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             MonitorCarrierRobotStockerTask();
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             MonitorCarrierRobotLPTask();
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             //MonitorCarrierGotoTask();
 
-         }
 
-         private void MonitorCarrierGotoTask()
 
-         {
 
-             if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             if (tj.Type == EnumTransferJobType.Loading)
 
-             {
 
-                 if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
 
-                 {
 
-                     foreach (var lp in _lstLPs)
 
-                     {
 
-                         if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
 
-                             continue;
 
-                         var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
 
-                         if (lpDevice.IsFoupPresent)
 
-                         {
 
-                             if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, true))
 
-                             {
 
-                                 return;
 
-                             }
 
-                         }
 
-                     }
 
-                     if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                     {
 
-                         foreach (var fims in _lstFIMSs)
 
-                         {
 
-                             if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
 
-                             {
 
-                                 var carrier1 = CarrierManager.Instance.GetCarrier(fims.Module, 0);
 
-                                 if (carrier1 != null && !carrier1.IsMapped)
 
-                                 {
 
-                                     if (tj.CarrierParas.Any(x => x.Stocker == carrier1.InternalModuleName) && _carrierRobot.PreviousTarget != fims.Module &&
 
-                                         _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, true))
 
-                                     {
 
-                                         return;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     //goto fims 放
 
-                     if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                     {
 
-                         foreach (var fims in _lstFIMSs)
 
-                         {
 
-                             if (!fims.IsAvailable)
 
-                                 continue;
 
-                             if (CarrierManager.Instance.CheckNoCarrier(fims.Module, 0))
 
-                             {
 
-                                 var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-                                 if (robotCarrier != null && !robotCarrier.IsMapped && tj.CarrierParas.Any(x => x.Stocker == robotCarrier.InternalModuleName))
 
-                                 {
 
-                                     if (_carrierRobot.PreviousTarget != fims.Module && _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, false))
 
-                                     {
 
-                                         return;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             else if (tj.Type == EnumTransferJobType.Unloading)
 
-             {
 
-                 if (CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
 
-                 {
 
-                     foreach (var lp in _lstLPs)
 
-                     {
 
-                         if (!CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
 
-                             continue;
 
-                         var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-                         var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == robotCarrier.InternalModuleName);
 
-                         if (para == null || para.TargetPort != lp.Module)
 
-                             continue;
 
-                         var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
 
-                         if (!lpDevice.IsFoupPresent)
 
-                         {
 
-                             if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, false))
 
-                             {
 
-                                 lp.WaitTransfer(ModuleName.CarrierRobot);
 
-                                 return;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorCarrierRobotStockerTask()
 
-         {
 
-             if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             //pick
 
-             var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-             if (carrier != null && carrier.IsEmpty)
 
-             {
 
-                 SchedulerStocker stocker = null;
 
-                 foreach (var st in _lstTotlaStockers)
 
-                 {
 
-                     if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
 
-                         continue;
 
-                     if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
 
-                     {
 
-                         carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
 
-                         if (tj.Type == EnumTransferJobType.Loading)
 
-                         {
 
-                             //没有map,FIMS具备map条件时
 
-                             if (carrier != null && !carrier.IsMapped &&
 
-                                 _lstFIMSs.Any(x => x.IsAvailable && x.IsReadyForPlace(ModuleName.CarrierRobot, 0)) &&
 
-                                 !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                             {
 
-                                 //有job执行且在charging和discharge状态,先不执行mapping
 
-                                 if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job != null &&
 
-                           (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
 
-                          || (job.ProcessingState == EnumProcessingState.Processing && DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <=SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
 
-                                 {
 
-                                     continue;
 
-                                 }
 
-                                 if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                                 {
 
-                                     stocker = st;
 
-                                     break;
 
-                                 }
 
-                             }
 
-                         }
 
-                         else
 
-                         {
 
-                             if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                             {
 
-                                 stocker = st;
 
-                                 break;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 if (stocker != null && _waferRobot.IsAvailable)
 
-                 {
 
-                     if (_carrierRobot.Pick(stocker.Module, 0, Hand.Blade1))
 
-                     {
 
-                         stocker.WaitTransfer(ModuleName.CarrierRobot);
 
-                         return;
 
-                     }
 
-                 }
 
-             }
 
-             if (!_carrierRobot.IsAvailable || tj.Type != EnumTransferJobType.Loading)
 
-                 return;
 
-             //place
 
-             carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-             if (carrier != null && !carrier.IsEmpty &&
 
-                 tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-             {
 
-                 var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
 
-                 SchedulerStocker stocker = null;
 
-                 foreach (var st in _lstTotlaStockers)
 
-                 {
 
-                     if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
 
-                         continue;
 
-                     if (st.Module != carrier.InternalModuleName)
 
-                         continue;
 
-                     if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0))
 
-                     {
 
-                         stocker = st;
 
-                         break;
 
-                     }
 
-                 }
 
-                 if (stocker != null)
 
-                 {
 
-                     if (_carrierRobot.Place(stocker.Module, 0, Hand.Blade1))
 
-                     {
 
-                         stocker.WaitTransfer(ModuleName.CarrierRobot);
 
-                         return;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorCarrierRobotLPTask()
 
-         {
 
-             if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return;
 
-             if (tj.Type == EnumTransferJobType.Loading)
 
-             {
 
-                 if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
 
-                 {
 
-                     foreach (var lp in _lstLPs)
 
-                     {
 
-                         if (!lp.IsAvailable)
 
-                             continue;
 
-                         if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
 
-                             continue;
 
-                         var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
 
-                         if (lp.IsReadyForPick(_carrierRobot.Module, 0) && (lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted))
 
-                         {
 
-                             var carrierPara = tj.CarrierParas.First(x => x.TargetPort == lp.Module && !x.IsLoaded);
 
-                             if (carrierPara != null && _carrierRobot.Load(lp.Module, 0, Hand.Blade1, carrierPara.Stocker, carrierPara.CarrierType, carrierPara.CarrierID, carrierPara))
 
-                             {
 
-                                 lp.WaitTransfer(ModuleName.CarrierRobot);
 
-                                 return;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-                 if (carrier != null && !carrier.IsEmpty)
 
-                 {
 
-                     foreach (var lp in _lstLPs)
 
-                     {
 
-                         if (!lp.IsAvailable || !CarrierManager.Instance.CheckNoCarrier(lp.Module, 0))
 
-                             continue;
 
-                         var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
 
-                         if (para == null || para.TargetPort != lp.Module)
 
-                             continue;
 
-                         var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
 
-                         if (lp.IsReadyForPlace(_carrierRobot.Module, 0) && lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted)
 
-                         {
 
-                             if (_carrierRobot.Unload(lp.Module, 0, Hand.Blade1, para))
 
-                             {
 
-                                 lp.WaitTransfer(ModuleName.CarrierRobot);
 
-                                 return;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void MonitorCarrierRobotFIMSTask()
 
-         {
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null || tj.Type != EnumTransferJobType.Loading)
 
-                 return;
 
-             //pick
 
-             var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-             if (carrier != null && carrier.IsEmpty)
 
-             {
 
-                 SchedulerFIMS fims = null;
 
-                 foreach (var st in _lstFIMSs)
 
-                 {
 
-                     if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
 
-                         continue;
 
-                     if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
 
-                     {
 
-                         carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
 
-                         var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
 
-                         if (carrier != null && carrier.IsMapped && carrier.IsMapOK &&
 
-                             fimsDevice.IsUnloadCompleted && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-                         {
 
-                             if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                             {
 
-                                 fims = st;
 
-                                 break;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 if (fims != null)
 
-                 {
 
-                     if (_carrierRobot.Pick(fims.Module, 0, Hand.Blade1))
 
-                     {
 
-                         fims.WaitTransfer(ModuleName.CarrierRobot);
 
-                         return;
 
-                     }
 
-                 }
 
-             }
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             //place
 
-             carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
 
-             if (carrier != null && !carrier.IsEmpty && !carrier.IsMapped &&
 
-                 tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName) &&
 
-                 !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
 
-             {
 
-                 SchedulerFIMS fims = null;
 
-                 foreach (var st in _lstFIMSs)
 
-                 {
 
-                     //有job执行且在charging和discharge状态,先不执行mapping
 
-                     if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job!=null&&
 
-                         (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
 
-                        ||(job.ProcessingState == EnumProcessingState.Processing&&DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <= SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
 
-                     {
 
-                         continue;
 
-                     }
 
-                     if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
 
-                         continue;
 
-                     var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
 
-                     if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0) && fimsDevice.IsUnloadCompleted)
 
-                     {
 
-                         fims = st;
 
-                         break;
 
-                     }
 
-                 }
 
-                 if (fims != null)
 
-                 {
 
-                     if (_carrierRobot.Place(fims.Module, 0, Hand.Blade1))
 
-                     {
 
-                         fims.WaitTransfer(ModuleName.CarrierRobot);
 
-                         return;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         public List<CarrierPara> GetTransferJobStockers()
 
-         {
 
-             if (!_lstTransferJobs.Any())
 
-                 return null;
 
-             var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
 
-             if (tj == null || tj.CarrierParas == null)
 
-                 return null;
 
-             return tj.CarrierParas;
 
-         }
 
-         #endregion
 
-         #region Job task
 
-         public Result MonitorJobTasks()
 
-         {
 
-             UpdateTransferJobStatus();
 
-             StartNewJob();
 
-             return Result.RUN;
 
-         }
 
-         private void UpdateTransferJobStatus()
 
-         {
 
-             if (!_lstTransferJobs.Any())
 
-                 return;
 
-             if (!_carrierRobot.IsAvailable)
 
-                 return;
 
-             List<TransferJobInfo> removeJobLst = new List<TransferJobInfo>();
 
-             foreach (var tj in _lstTransferJobs)
 
-             {
 
-                 if (tj == null || tj.CarrierParas == null)
 
-                     continue;
 
-                 bool isComplete = true;
 
-                 if (tj.Type == EnumTransferJobType.Loading)
 
-                 {
 
-                     foreach (var item in tj.CarrierParas)
 
-                     {
 
-                         if (!CarrierManager.Instance.CheckHasCarrier(item.Stocker, 0))
 
-                         {
 
-                             isComplete = false;
 
-                             continue;
 
-                         }
 
-                         var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
 
-                         if (carrier != null && (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded))
 
-                         {
 
-                             isComplete = false;
 
-                             continue;
 
-                         }
 
-                         if (carrier != null)
 
-                         {
 
-                             if (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded)
 
-                             {
 
-                                 isComplete = false;
 
-                                 continue;
 
-                             }
 
-                             else
 
-                             {
 
-                                 if (!item.HasTrigEvent)
 
-                                 {
 
-                                     Task.Delay(1000).ContinueWith(x =>
 
-                                     {
 
-                                         _faCallback.CarrierInEnd(item.Stocker);
 
-                                     });
 
-                                     item.HasTrigEvent = true;
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     foreach (var item in tj.CarrierParas)
 
-                     {
 
-                         if (!item.IsUnloaded)
 
-                             continue;
 
-                         if (!item.HasTrigEvent)
 
-                         {
 
-                             foreach (var lp in _lstLPs)
 
-                             {
 
-                                 if (item.TargetPort == lp.Module)
 
-                                 {
 
-                                     var carrier = CarrierManager.Instance.GetCarrier(item.TargetPort, 0);
 
-                                     if (carrier != null && !carrier.IsEmpty)
 
-                                     {
 
-                                         //_faCallback.CarrierOutEnd(carrier);
 
-                                         item.HasTrigEvent = true;
 
-                                         break;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                     foreach (var lp in _lstLPs)
 
-                     {
 
-                         if (tj.CarrierParas.Any(x => x.TargetPort == lp.Module))
 
-                         {
 
-                             if (CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
 
-                             {
 
-                                 isComplete = false;
 
-                                 continue;
 
-                             }
 
-                         }
 
-                     }
 
-                     if (tj.CarrierParas.Any(x => !x.IsUnloaded))
 
-                     {
 
-                         isComplete = false;
 
-                         continue;
 
-                     }
 
-                 }
 
-                 if (isComplete)
 
-                 {
 
-                     tj.State = EnumTransferJobState.Complete;
 
-                     removeJobLst.Add(tj);
 
-                     string stocker = "";
 
-                     tj.CarrierParas.ForEach(x => stocker += $"{x.Stocker}-");
 
-                     LOG.Write($"Scheduler:{stocker} {tj.Type} change to complete");
 
-                     if (tj.Type == EnumTransferJobType.Loading)
 
-                     {
 
-                         List<ModuleName> unloadLPs = new List<ModuleName>();
 
-                         foreach (var item in tj.CarrierParas)
 
-                         {
 
-                             if (!unloadLPs.Contains(item.TargetPort) &&
 
-                                 !_lstTransferJobs.Any(x => (x.State == EnumTransferJobState.Created || x.State == EnumTransferJobState.Active) &&
 
-                                 x.CarrierParas.Any(ca => ca.TargetPort == item.TargetPort)))
 
-                                 unloadLPs.Add(item.TargetPort);
 
-                         }
 
-                         //foreach (var lp in unloadLPs)
 
-                         //{
 
-                         //    (Singleton<EquipmentManager>.Instance.Modules[lp] as LoadPortModule).InvokeUnload();
 
-                         //    LOG.Write($"Scheduler:{lp} start unload");
 
-                         //}
 
-                     }
 
-                 }
 
-             }
 
-             foreach (var item in removeJobLst)
 
-             {
 
-                 _lstTransferJobs.Remove(item);
 
-             }
 
-         }
 
-         private void StartNewJob()
 
-         {
 
-             if (!_lstTransferJobs.Any() || !_carrierRobot.IsAvailable)
 
-                 return;
 
-             //没有在process的stocker时,以时间先后为准
 
-             var processingStockers = Singleton<EquipmentManager>.Instance.GetProcessingStockers();
 
-             if (processingStockers != null)
 
-             {
 
-                 //有在process的stocker时,以时间先后和所有stokcer都不在process为准
 
-                 foreach (var tj in _lstTransferJobs)
 
-                 {
 
-                     if (tj == null || tj.CarrierParas == null)
 
-                         continue;
 
-                     bool hasStokcerInProcessing = false;
 
-                     foreach (var item in tj.CarrierParas)
 
-                     {
 
-                         if (processingStockers.Any(x => x.Item1 == item.Stocker.ToString()))
 
-                         {
 
-                             hasStokcerInProcessing = true;
 
-                             break;
 
-                         }
 
-                     }
 
-                     if (!hasStokcerInProcessing)
 
-                     {
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             var tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Loading);
 
-             if (tjActives.Any())
 
-             {
 
-                 foreach (var tjActive in tjActives)
 
-                 {
 
-                     if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Loading)
 
-                     {
 
-                         bool isStockerReady = true;
 
-                         foreach (var stocker in _lstTotlaStockers)
 
-                         {
 
-                             if (CarrierManager.Instance.CheckHasCarrier(stocker.Module, 0))
 
-                             {
 
-                                 var carrier = CarrierManager.Instance.GetCarrier(stocker.Module, 0);
 
-                                 if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                                     isStockerReady = false;
 
-                             }
 
-                         }
 
-                         if (CarrierManager.Instance.CheckHasCarrier(_carrierRobot.Module, 0))
 
-                         {
 
-                             var carrier = CarrierManager.Instance.GetCarrier(_carrierRobot.Module, 0);
 
-                             if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                                 isStockerReady = false;
 
-                         }
 
-                         foreach (var fims in _lstFIMSs)
 
-                         {
 
-                             if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
 
-                             {
 
-                                 var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
 
-                                 if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
 
-                                     isStockerReady = false;
 
-                             }
 
-                         }
 
-                         if (isStockerReady)
 
-                         {
 
-                             //transfer job开始
 
-                             tjActive.State = EnumTransferJobState.Active;
 
-                         }
 
-                         if (tjActive.State == EnumTransferJobState.Active)
 
-                         {
 
-                             foreach (var lp in _lstLPs)
 
-                             {
 
-                                 if (!lp.IsAvailable)
 
-                                     continue;
 
-                                 if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
 
-                                     continue;
 
-                                 var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Unloading);
 
-             if (tjActives.Any())
 
-             {
 
-                 foreach (var tjActive in tjActives)
 
-                 {
 
-                     if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Unloading)
 
-                     {
 
-                         bool isStockerReady = true;
 
-                         var allPJStockers = Singleton<EquipmentManager>.Instance.GetAllPJStockers();
 
-                         foreach (var item in tjActive.CarrierParas)
 
-                         {
 
-                             if (CarrierManager.Instance.CheckNoCarrier(item.Stocker, 0))
 
-                             {
 
-                                 isStockerReady = false;
 
-                                 continue;
 
-                             }
 
-                             if (allPJStockers != null && allPJStockers.Any(x => x.Item1 == item.Stocker.ToString()))
 
-                             {
 
-                                 isStockerReady = false;
 
-                                 continue;
 
-                             }
 
-                             var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
 
-                             if (carrier != null && item.Stocker != carrier.InternalModuleName)
 
-                                 isStockerReady = false;
 
-                         }
 
-                         if (isStockerReady)
 
-                         {
 
-                             //transfer job开始
 
-                             tjActive.State = EnumTransferJobState.Active;
 
-                         }
 
-                         if (tjActive.State == EnumTransferJobState.Active)
 
-                         {
 
-                             foreach (var lp in _lstLPs)
 
-                             {
 
-                                 if (!lp.IsAvailable)
 
-                                     continue;
 
-                                 if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
 
-                                     continue;
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         internal List<TransferJobInfo> GetFirstCreatedTransferJob(EnumTransferJobType type)
 
-         {
 
-             DateTime dtMin = DateTime.MaxValue;
 
-             List<TransferJobInfo> currentTj = new List<TransferJobInfo>();
 
-             var lpNumber = 2;
 
-             List<ModuleName> occupyLPs = new List<ModuleName>();
 
-             foreach (var tj in _lstTransferJobs)
 
-             {
 
-                 if (tj == null || tj.State == EnumTransferJobState.Active || tj.State == EnumTransferJobState.Complete || tj.Type != type)
 
-                 {
 
-                     continue;
 
-                 }
 
-                 if (occupyLPs.Count == lpNumber)
 
-                     break;
 
-                 currentTj.Add(tj);
 
-                 foreach (var para in tj.CarrierParas)
 
-                 {
 
-                     if (type == EnumTransferJobType.Loading && !para.IsLoaded && !occupyLPs.Any(x => x == para.TargetPort))
 
-                         occupyLPs.Add(para.TargetPort);
 
-                     if (type == EnumTransferJobType.Unloading && !para.IsUnloaded && !occupyLPs.Any(x => x == para.TargetPort))
 
-                         occupyLPs.Add(para.TargetPort);
 
-                 }
 
-             }
 
-             return currentTj;
 
-         }
 
-         public List<string> GetOccupyStockers()
 
-         {
 
-             var occupyStockers = new List<string>();
 
-             var checkModuleLst = new List<ModuleName>();
 
-             checkModuleLst.Add(ModuleName.CarrierRobot);
 
-             foreach (var fims in _lstFIMSs)
 
-             {
 
-                 if (fims == null)
 
-                     continue;
 
-                 checkModuleLst.Add(fims.Module);
 
-             }
 
-             foreach (var stocker in _lstTotlaStockers)
 
-             {
 
-                 if (stocker == null)
 
-                     continue;
 
-                 checkModuleLst.Add(stocker.Module);
 
-             }
 
-             foreach (var module in checkModuleLst)
 
-             {
 
-                 var carrier = CarrierManager.Instance.GetCarrier(module, 0);
 
-                 if (carrier == null || carrier.IsEmpty)
 
-                     continue;
 
-                 occupyStockers.Add(carrier.InternalModuleName.ToString());
 
-             }
 
-             var loadCarrierParas = new List<CarrierPara>();
 
-             if (_lstTransferJobs.Any())
 
-             {
 
-                 foreach (var tj in _lstTransferJobs)
 
-                 {
 
-                     if (tj == null || tj.Type != EnumTransferJobType.Loading)
 
-                         continue;
 
-                     loadCarrierParas.AddRange(tj.CarrierParas);
 
-                 }
 
-             }
 
-             if (loadCarrierParas != null && loadCarrierParas.Any())
 
-             {
 
-                 foreach (var para in loadCarrierParas)
 
-                 {
 
-                     occupyStockers.Add(para.Stocker.ToString());
 
-                 }
 
-             }
 
-             return occupyStockers;
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |