12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Xml;
- using System.Diagnostics;
- using System.Text;
- using System.Threading.Tasks;
- using VirgoRT.Modules.Schedulers;
- using VirgoRT.Scheduler;
- using MECF.Framework.Common.DBCore;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Jobs;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using Aitex.Core.Common;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.DataCenter;
- namespace VirgoRT.Modules
- {
- enum RobotFreeHand
- {
- Blade1 = 0, //Lower arm
- Blade2 = 1, //Upper arm
- Both = 2,
- None = 3,
- }
- enum ActionState
- {
- Init = 0,
- Prepare,
- Run,
- Post,
- Done,
- }
- struct MoveAction
- {
- public EnumTransferType eType;
- public ModuleName targetModule;
- public int targetSlot;
- public int robotSlot1;
- public int robotSlot2;
- public ActionState state;
- public MoveAction(EnumTransferType type, ModuleName module, int tSlot = 0, int Slot1 = 0, int Slot2 = 0)
- {
- eType = type;
- targetModule = module;
- targetSlot = tSlot;
- robotSlot1 = Slot1;
- robotSlot2 = Slot2;
- state = ActionState.Init;
- }
- }
- enum ModulePriority
- {
- High,
- Middle,
- Low,
- Stop,
- }
- class ModuleFlag
- {
- public ModulePriority priority;
- public ModuleFlag(ModulePriority _priority)
- {
- priority = _priority;
- }
- }
- enum RtTraceState
- {
- Init,
- Pumping,
- WaitEfemRobotReady,
- WaitPenddingActionsFinish,
- WaitModuleReady,
- WaitPMReadyForPlace,
- WaitPMReadyForPick,
- WaitModuleReadyForPlace,
- WaitModuleReadyForPick,
- WaitPMReadyForTemperature,
- VerifyTransferAction,
- }
- public class AutoTransfer_T : TransferModule, IAutoTransfer
- {
- private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
- private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
- Dictionary<ModuleName, SchedulerModule> dictSchedulers = new Dictionary<ModuleName, SchedulerModule>();
- Dictionary<ModuleName, ModuleFlag> dictModules = new Dictionary<ModuleName, ModuleFlag>();
- Dictionary<Guid, ModuleName> dictWaferProcessPM = new Dictionary<Guid, ModuleName>();
- Dictionary<ModuleName, ModuleName> dictLPAssociatedPM = new Dictionary<ModuleName, ModuleName>();
- Queue<MoveAction> queMoveAction = new Queue<MoveAction>();
- private List<ModuleName> _mapTarget = new List<ModuleName>();
- private const string LogSource = "Scheduler";
- private bool _isCycleMode;
- private int _cycleSetPoint = 0;
- private int _cycledCount = 0;
- private int _cycledWafer = 0;
- private bool _isInited;
- private Stopwatch _blockingWatcher = new Stopwatch();
- private RtTraceState _lastTraceState;
- private RtTraceState _currentTraceState;
- public bool HasJobRunning => _lstControlJobs.Count > 0;
- public bool IsEfemRobotAvavilable => _efemRobot.IsAvailable;
- public static int SystemInternalWaferCount => SC.GetValue<int>($"System.MaxInternalWaferCount");
- private static int _maxBufferWaferCount = 1;
- private int _bufferSlotNumber = 0;
- private bool IsModuleAvailable(ModuleName module) => dictSchedulers.Keys.Contains(module) && dictSchedulers[module].IsAvailable;
- private SchedulerModule GetScheduler(ModuleName module) => dictSchedulers.Keys.Contains(module) ? dictSchedulers[module] : null;
- private SchedulerFACallback _faCallback;
- private SchedulerDBCallback _dbCallback;
- MoveAction _curAction = new MoveAction();
- public AutoTransfer_T()
- {
- _faCallback = new SchedulerFACallback();
- _dbCallback = new SchedulerDBCallback();
- InitModules();
- _curAction.state = ActionState.Done;
- DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount);
- DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer);
- DATA.Subscribe("Scheduler.CycleSetPoint", () => _cycleSetPoint);
- DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
- foreach (var lp in dictSchedulers)
- {
- if (ModuleHelper.IsLoadPort(lp.Key))
- {
- DATA.Subscribe($"{lp.Key}.LocalJobName", () => {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
- if (cj != null)
- return cj.Name;
- return "";
- });
- DATA.Subscribe($"{lp.Key}.JobLotName", () => {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
- if (cj != null)
- return cj.LotName;
- return "";
- });
- DATA.Subscribe($"{lp.Key}.LocalJobStatus", () => {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
- if (cj != null)
- return cj.State.ToString();
- return "";
- });
- DATA.Subscribe($"{lp.Key}.CurrentRecipeList", () => {
- var local = lp;
- List<string> result = Enumerable.Repeat("", SC.GetValue<int>("EFEM.LoadPort.SlotNumber")).ToList();
- for (int i = 0; i < _lstProcessJobs.Count; i++)
- {
- foreach (var wafers in _lstProcessJobs[i].SlotWafers)
- {
- if (wafers.Item1 == local.Key)
- {
- result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
- }
- }
- }
- return result;
- });
- }
- }
- _maxBufferWaferCount = SC.GetValue<int>("EFEM.Buffer.SlotNumber") / 2;
- }
- private void InitModules()
- {
- void _initMoudle(ModuleName name, SchedulerModule sche, ModulePriority prio)
- {
- if (ModuleHelper.IsInstalled(name))
- {
- dictSchedulers[name] = sche;
- dictModules[name] = new ModuleFlag(prio);
- }
- }
- _initMoudle(ModuleName.PMA, _pma, ModulePriority.Middle);
- _initMoudle(ModuleName.PMB, _pmb, ModulePriority.Middle);
- _initMoudle(ModuleName.LP1, _lp1, ModulePriority.Middle);
- _initMoudle(ModuleName.LP2, _lp2, ModulePriority.Middle);
- _initMoudle(ModuleName.Aligner1, _aligner1, ModulePriority.Middle);
- _initMoudle(ModuleName.Aligner2, _aligner2, ModulePriority.Middle);
- _initMoudle(ModuleName.Cooling1, _cooling1, ModulePriority.Middle);
- _initMoudle(ModuleName.Cooling2, _cooling2, ModulePriority.Middle);
- _initMoudle(ModuleName.Flipper, _flipper, ModulePriority.Middle);
- _initMoudle(ModuleName.Buffer, _buffer, ModulePriority.Middle);
- }
- #region transfer routine
- private bool HasCrossSequence()
- {
- List<ModuleName> lstStepModules = new List<ModuleName>();
- foreach (var pj in _lstProcessJobs)
- {
- lstStepModules.Clear();
- foreach (var step in pj.Sequence.Steps)
- {
- foreach (var module in step.StepModules)
- {
- if (lstStepModules.Contains(module))
- return true;
- else
- lstStepModules.Add(module);
- }
- }
- }
- return false;
- }
- private void dumpMoveAction(string prefix, MoveAction action)
- {
- EV.PostInfoLog("System", $"{prefix} : {action.state}, {action.eType}, {action.targetModule}, {action.targetSlot}");
- }
- private void blockingChecking()
- {
- if (CheckAllJobDone())
- return;
- if (_currentTraceState != _lastTraceState)
- {
- _lastTraceState = _currentTraceState;
- _blockingWatcher.Restart();
- }
- if (_blockingWatcher.ElapsedMilliseconds >= 120 * 1000)
- {
- EV.PostInfoLog("", $"Router Blocking State: {_currentTraceState}");
- dumpMoveAction("Current Action", _curAction);
- for (int i = 0; i < queMoveAction.Count; i++)
- {
- dumpMoveAction(i.ToString(), queMoveAction.ElementAt(i));
- }
- foreach (var module in dictSchedulers)
- {
- string moduleStatus = module.Value.IsAvailable ? "Idle" : (module.Value.IsError ? "Error" : "Busy");
- EV.PostInfoLog("", $"Module State: {module.Key} is {moduleStatus}");
- }
- if (_curAction.state != ActionState.Done && dictSchedulers[_curAction.targetModule].IsError)
- {
- _curAction.state = ActionState.Done;
- queMoveAction.Clear();
- }
- _blockingWatcher.Restart();
- ResetTraceFlag();
- }
- }
- private bool prelude()
- {
- MonitorEfemRobotMapTask();
- return true;
- }
- private bool epilogue()
- {
- UpdateProcessJobStatus();
- UpdateControlJobStatus();
- StartNewJob();
- MonitorCleanTasks();
- blockingChecking();
- return true;
- }
- private bool Pump()
- {
- if (queMoveAction.Count > 0 || _curAction.state != ActionState.Done)
- return false;
- // move remaining wafers in robot arms
- for(int slot = 0; slot < 2; slot++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, slot))
- {
- var nextSlot = GetWaferNextReadySlot(new SlotItem(ModuleName.EfemRobot, slot));
- if (nextSlot.Module != ModuleName.System)
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, slot));
- PreparePMTemp(ModuleName.EfemRobot, slot, nextSlot.Module, EnumTransferType.Place);
- return true;
- }
- var swapSlot = GetWaferNextReadySlot(new SlotItem(ModuleName.EfemRobot, slot), true);
- if (swapSlot.Module != ModuleName.System)
- {
- int peerSlot = slot == 0 ? 1 : 0;
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, peerSlot))
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, swapSlot.Module, swapSlot.Slot, peerSlot /* Pick Blade */, slot /* Place Blade */));
- PreparePMTemp(ModuleName.EfemRobot, slot, swapSlot.Module, EnumTransferType.Pick);
- return true;
- }
- }
- }
- }
- ModulePriority[] prioritys = new ModulePriority[] { ModulePriority.High, ModulePriority.Middle, ModulePriority.Low };
- foreach (var prio in prioritys)
- {
- foreach (var module in dictModules)
- {
- if (module.Value.priority != prio)
- continue;
- var outSlot = GetReadyOutSlot(module.Key);
- if (outSlot.Module != ModuleName.System && IsWaferCtrlJobRuning(outSlot))
- {
- var nextSlot = GetWaferNextReadySlot(outSlot);
- if (nextSlot.Module != ModuleName.System)
- {
- var waitInSlot = GetWaitInWaferSlot(outSlot);
- if (waitInSlot.Module != ModuleName.System && GetRobotFreeHand() == RobotFreeHand.Both)
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, waitInSlot.Module, waitInSlot.Slot, (int)Hand.Blade1));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, module.Key, outSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, (int)Hand.Blade2));
- PreparePMTemp(waitInSlot.Module, waitInSlot.Slot, module.Key, EnumTransferType.Pick);
- PreparePMTemp(module.Key, outSlot.Slot, nextSlot.Module, EnumTransferType.Place);
- return true;
- }
- else
- {
- int nFreeHand = (int)SelectRobotFreeHand();
- if (nFreeHand != (int)RobotFreeHand.None)
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, module.Key, outSlot.Slot, nFreeHand));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, nFreeHand));
- PreparePMTemp(module.Key, outSlot.Slot, nextSlot.Module, EnumTransferType.Place);
- return true;
- }
- }
- }
- else
- {
- var swapSlot = GetCanSwapSlot(outSlot);
- if (swapSlot.Module != ModuleName.System && GetRobotFreeHand() == RobotFreeHand.Both)
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade1));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, module.Key, outSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade2));
- PreparePMTemp(swapSlot.Module, swapSlot.Slot, module.Key, EnumTransferType.Pick);
- PreparePMTemp(module.Key, outSlot.Slot, swapSlot.Module, EnumTransferType.Pick);
- return true;
- }
- }
- }
- }
- }
- // pick the wafer to robot arm while the next module is not ready
- if (HasCrossSequence() == false && GetRobotFreeHand() == RobotFreeHand.Both)
- {
- foreach (var module in dictModules)
- {
- var outSlot = GetReadyOutSlot(module.Key);
- if (outSlot.Module != ModuleName.System && IsWaferCtrlJobRuning(outSlot))
- {
- var swapSlot = GetWaferNextReadySlot(outSlot, true);
- if (swapSlot.Module != ModuleName.System)
- {
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, outSlot.Module, outSlot.Slot, (int)Hand.Blade1));
- queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
- PreparePMTemp(outSlot.Module, outSlot.Slot, swapSlot.Module, EnumTransferType.Pick);
- return true;
- }
- }
- }
- }
- _currentTraceState = RtTraceState.Pumping;
- return false;
- }
- private void Pop()
- {
- if (!_efemRobot.IsAvailable)
- {
- _currentTraceState = RtTraceState.WaitEfemRobotReady;
- return;
- }
- if (queMoveAction.Count == 0 && _curAction.state == ActionState.Done)
- return;
- switch (_curAction.state)
- {
- case ActionState.Init:
- {
- if (IsModuleAvailable(_curAction.targetModule))
- {
- if (PrepareCurrentAction())
- {
- _curAction.state = ActionState.Prepare;
- if (RunCurrentAction())
- {
- _curAction.state = ActionState.Run;
- }
- }
- }
- else
- {
- _currentTraceState = RtTraceState.WaitModuleReady;
- }
- }
- break;
- case ActionState.Prepare:
- {
- if (RunCurrentAction())
- {
- _curAction.state = ActionState.Run;
- }
- }
- break;
- case ActionState.Run:
- {
- if (dictSchedulers[_curAction.targetModule].IsWaitTransfer(ModuleName.EfemRobot))
- {
- NotifyFaWaferEnd();
- dictSchedulers[_curAction.targetModule].PostTransfer(ModuleName.EfemRobot);
- _curAction.state = ActionState.Post;
- }
- else
- {
- _currentTraceState = RtTraceState.VerifyTransferAction;
- }
- }
- break;
- case ActionState.Post:
- {
- if (IsModuleAvailable(_curAction.targetModule))
- {
- PostProcessCurrentAction();
- _curAction.state = ActionState.Done;
- }
- else
- {
- _currentTraceState = RtTraceState.WaitModuleReady;
- }
- }
- break;
- case ActionState.Done:
- {
- _curAction = queMoveAction.Dequeue();
- }
- break;
- default:
- break;
- }
- }
- private bool PrepareCurrentAction()
- {
- if (_curAction.targetModule == ModuleName.PMA || _curAction.targetModule == ModuleName.PMB)
- {
- if ((_curAction.eType == EnumTransferType.Place && !dictSchedulers[_curAction.targetModule].IsReadyForPlace(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1)) ||
- (_curAction.eType != EnumTransferType.Place && !dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1)))
- {
- dictSchedulers[_curAction.targetModule].PrepareTransfer(ModuleName.EfemRobot,
- _curAction.eType == EnumTransferType.Swap ? EnumTransferType.Pick : _curAction.eType,
- _curAction.targetSlot);
- _currentTraceState = _curAction.eType == EnumTransferType.Swap ? RtTraceState.WaitPMReadyForPick : RtTraceState.WaitPMReadyForPlace;
- return false;
- }
- else
- {
- if (_curAction.eType == EnumTransferType.Pick)
- return true;
- GetWaferTemperatureSetInRecipe(ModuleName.EfemRobot, _curAction.eType == EnumTransferType.Place ? _curAction.robotSlot1 : _curAction.robotSlot2, _curAction.targetModule, out float temp);
- if (temp < 0.1)
- return true;
- if (!((SchedulerPM)dictSchedulers[_curAction.targetModule]).IsTemperatureReady(temp))
- {
- _currentTraceState = RtTraceState.WaitPMReadyForTemperature;
- return false;
- }
- }
- }
- return true;
- }
- private void PreparePMTemp(ModuleName waferModule, int waferSlot, ModuleName pmModule, EnumTransferType type)
- {
- if (pmModule == ModuleName.PMA || pmModule == ModuleName.PMB)
- {
- GetWaferTemperatureSetInRecipe(waferModule, waferSlot, pmModule, out float temp);
- if (Math.Abs(temp) > 0.1 && !((SchedulerPM)dictSchedulers[pmModule]).IsTemperatureReady(temp))
- {
- ((SchedulerPM)dictSchedulers[pmModule]).PrepareTransfer(ModuleName.EfemRobot, type, 0, temp, Hand.Blade1, WaferSize.WS12);
- }
- }
- }
- private bool RunCurrentAction()
- {
- if (!IsModuleAvailable(_curAction.targetModule))
- {
- return false;
- }
-
- switch (_curAction.eType)
- {
- case EnumTransferType.Pick:
- {
- if (dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
- {
- _efemRobot.Pick(_curAction.targetModule, _curAction.targetSlot, (Hand)_curAction.robotSlot1);
- dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, _curAction.targetSlot);
- // Notify the FA for Port1JobWaferStart
- if (ModuleHelper.IsLoadPort(_curAction.targetModule))
- {
- ProcessJobInfo pj = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot).ProcessJob;
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- _faCallback.JobWaferStart(cj, pj, _curAction.targetModule.ToString(), _curAction.targetSlot);
- }
- return true;
- }
- else
- {
- _currentTraceState = RtTraceState.WaitModuleReadyForPick;
- }
- }
- break;
- case EnumTransferType.Place:
- {
- if (dictSchedulers[_curAction.targetModule].IsReadyForPlace(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
- {
- _efemRobot.Place(_curAction.targetModule, _curAction.targetSlot, (Hand)_curAction.robotSlot1);
- dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, _curAction.targetSlot);
- return true;
- }
- else
- {
- _currentTraceState = RtTraceState.WaitModuleReadyForPlace;
- }
- }
- break;
- case EnumTransferType.Swap:
- {
- if (dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
- {
- _efemRobot.PickAndPlace(_curAction.targetModule, _curAction.targetSlot, _curAction.targetSlot, (Hand)_curAction.robotSlot1, (Hand)_curAction.robotSlot2);
- dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Swap, _curAction.targetSlot);
- return true;
- }
- else
- {
- _currentTraceState = RtTraceState.WaitModuleReadyForPick;
- }
- }
- break;
- }
- return false;
- }
- private void PostProcessCurrentAction()
- {
- if (_curAction.eType != EnumTransferType.Pick)
- {
- var wafer = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot);
- if (wafer.IsEmpty)
- return;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return;
- if (_curAction.eType == EnumTransferType.Swap)
- {
- dictSchedulers[_curAction.targetModule].EventWaferLeaved?.Invoke(this, new WaferMoveArgs(_curAction.targetModule,
- _curAction.robotSlot2, ModuleName.EfemRobot, _curAction.targetSlot));
- if (ModuleHelper.IsLoadPort(_curAction.targetModule) && IsFixedPMMode())
- {
- AdjustLPPriority(_curAction.targetModule);
- }
- }
- dictSchedulers[_curAction.targetModule].EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.EfemRobot,
- _curAction.robotSlot1,
- _curAction.targetModule,
- _curAction.targetSlot));
- if(ModuleHelper.IsLoadPort(_curAction.targetModule))
- RemoveWaferPMMark(new SlotItem(_curAction.targetModule, _curAction.targetSlot));
- else if (ModuleHelper.IsPm(_curAction.targetModule))
- AddWaferPMMark(_curAction.targetModule);
- else if (ModuleHelper.IsAligner(_curAction.targetModule))
- {
- GetWaferSequenceAlignTime(_curAction.targetModule, 0, out float time);
- _efemRobot.Align(_curAction.targetModule, time);
- }
- else if (ModuleHelper.IsCooling(_curAction.targetModule))
- {
- GetWaferSequenceAlignTime(_curAction.targetModule, 0, out float time);
- dictSchedulers[_curAction.targetModule].Cooling((int)time);
- }
- if (!ModuleHelper.IsLoadPort(_curAction.targetModule))
- wafer.NextSequenceStep++;
- }
- else
- {
- dictSchedulers[_curAction.targetModule].EventWaferLeaved?.Invoke(this, new WaferMoveArgs(_curAction.targetModule,
- _curAction.targetSlot, ModuleName.EfemRobot, _curAction.robotSlot1));
- if (IsFixedPMMode())
- {
- if (ModuleHelper.IsLoadPort(_curAction.targetModule))
- {
- AdjustLPPriority(_curAction.targetModule);
- }
- else if (ModuleHelper.IsAligner(_curAction.targetModule))
- {
- AdjustAlignerPriority(_curAction.targetModule);
- }
- }
- }
- }
- private bool GetWaferSequenceAlignTime(ModuleName module, int slot, out float time)
- {
- time = 0;
- if (!WaferManager.Instance.CheckHasWafer(module, slot))
- return false;
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter.ContainsKey("CoolingTime"))
- return false;
- if (!float.TryParse((string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"],
- out time))
- return false;
- return true;
- }
- private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out float temp)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- var seq = wafer.ProcessJob.Sequence;
- for (int i = wafer.NextSequenceStep; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (module == pmModule)
- {
- temp = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
- return true;
- }
- }
- }
- temp = 0;
- LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
- return false;
- }
- private SlotItem GetWaferNextReadySlot(SlotItem slot, bool bSwap = false)
- {
- var nextSlot = new SlotItem(ModuleName.System, -1);
- var inWafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
- if (inWafer.IsEmpty)
- return nextSlot;
- if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
- return nextSlot;
- if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count) // need return
- {
- return new SlotItem((ModuleName)inWafer.OriginStation, inWafer.OriginSlot);
- }
- foreach (var module in inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules)
- {
- if (IsModuleAvailable(module))
- {
- // need enhancement
- int nMaxSlot = (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3) ?
- SC.GetValue<int>("EFEM.LoadPort.SlotNumber") : (module == ModuleName.Buffer ? SC.GetValue<int>("EFEM.Buffer.SlotNumber") : 1);
- for (int i = 0; i < nMaxSlot; i++)
- {
- if (WaferManager.Instance.IsWaferSlotLocationValid(module, i))
- {
- // the processed wafer must enter same pm
- if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(ModuleName.Flipper) && dictWaferProcessPM.ContainsKey(inWafer.InnerId) && dictWaferProcessPM[inWafer.InnerId] != module)
- continue;
- if (bSwap == false && WaferManager.Instance.CheckNoWafer(module, i))
- {
- return new SlotItem(module, i);
- }
- if (bSwap && WaferManager.Instance.CheckHasWafer(module, i))
- {
- return new SlotItem(module, i);
- }
- }
- }
- }
- }
- return nextSlot;
- }
- private SlotItem GetCanSwapSlot(SlotItem slot)
- {
- var swapSlot = new SlotItem(ModuleName.System, -1);
- var inWafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
- if (inWafer.IsEmpty)
- return swapSlot;
- if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
- return swapSlot;
- if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count) // need return
- return swapSlot;
- foreach (var module in inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules)
- {
- if (IsModuleAvailable(module))
- {
- // need enhancement
- int nMaxSlot = (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3) ?
- SC.GetValue<int>("EFEM.LoadPort.SlotNumber") : (module == ModuleName.Buffer ? SC.GetValue<int>("EFEM.Buffer.SlotNumber") : 1);
- for (int i = 0; i < nMaxSlot; i++)
- {
- if (WaferManager.Instance.IsWaferSlotLocationValid(module, i))
- {
- if (WaferManager.Instance.CheckHasWafer(module, i))
- {
- var swapWafer = WaferManager.Instance.GetWafer(module, i);
- if (!swapWafer.IsEmpty &&
- swapWafer.ProcessJob != null &&
- swapWafer.ProcessJob.Sequence != null &&
- swapWafer.NextSequenceStep < swapWafer.ProcessJob.Sequence.Steps.Count &&
- swapWafer.ProcessJob.Sequence.Steps[swapWafer.NextSequenceStep].StepModules.Contains(slot.Module))
- {
- return new SlotItem(module, i);
- }
- }
- }
- }
- }
- }
- return swapSlot;
- }
- private SlotItem GetWaitInWaferSlot(SlotItem slot)
- {
- ModulePriority[] prioritys = new ModulePriority[] { ModulePriority.High, ModulePriority.Middle, ModulePriority.Low };
- foreach (var prio in prioritys)
- {
- foreach (var module in dictModules)
- {
- if (module.Value.priority != prio || module.Key == slot.Module)
- continue;
- var inSlot = GetReadyOutSlot(module.Key);
- if (inSlot.Module != ModuleName.System)
- {
- var inWafer = WaferManager.Instance.GetWafer(inSlot.Module, inSlot.Slot);
- if (inWafer.IsEmpty)
- continue;
- if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
- continue;
- if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count)
- continue;
- if (inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules
- .Contains(slot.Module))
- return inSlot;
- }
- }
- }
- return new SlotItem(ModuleName.System, -1);
- }
- private SlotItem GetReadyOutSlot(ModuleName module)
- {
- if (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3)
- return GetLPReadyOutSlot(module);
- else if (module == ModuleName.Buffer)
- return GetBufferReadyOutSlot(module);
- else
- return GetModuleReadyOutSlot(module);
- }
- private bool IsWaferCtrlJobRuning(SlotItem slotItem)
- {
- return IsWaferCtrlJobRuning(slotItem.Module, slotItem.Slot);
- }
- private bool IsWaferCtrlJobRuning(ModuleName mod, int slot)
- {
- var wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- var waferCtrlJob = _lstControlJobs.Find(item => (int)ModuleHelper.Converter(item.Module) == wafer.OriginStation);
- if (waferCtrlJob != null)
- {
- return waferCtrlJob.State == EnumControlJobState.Executing;
- }
- return false;
- }
- private SlotItem GetLPReadyOutSlot(ModuleName lp)
- {
- var slot = GetNextWaferInJobQueue(lp);
- if (slot == null)
- return new SlotItem(ModuleName.System, -1);
- return slot;
- }
- private SlotItem GetModuleReadyOutSlot(ModuleName module)
- {
- var slot = new SlotItem(ModuleName.System, -1);
- if (!IsModuleAvailable(module))
- return slot;
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, 0);
- if (wafer.IsEmpty)
- return slot;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return slot;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count) // return to loadport
- return new SlotItem(module, 0);
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
- .Contains(module))
- return slot;
- return new SlotItem(module, 0);
- }
- private SlotItem GetBufferReadyOutSlot(ModuleName buffer)
- {
- return dictSchedulers[buffer].GetReadyOutSlot();
- }
- private RobotFreeHand GetRobotFreeHand()
- {
- var blade1Enable = SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable");
- var blade2Enable = SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable");
- var blade1HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0);
- var blade2HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1);
- if (blade1HasWafer && blade2HasWafer)
- return RobotFreeHand.None;
- else if (!blade1HasWafer && !blade2HasWafer && blade1Enable && blade2Enable)
- return RobotFreeHand.Both;
- else if (!blade2HasWafer && blade2Enable)
- return RobotFreeHand.Blade2;
- else if (!blade1HasWafer && blade1Enable)
- return RobotFreeHand.Blade1;
- else
- return RobotFreeHand.None;
- }
- private RobotFreeHand SelectRobotFreeHand()
- {
- var freeHand = GetRobotFreeHand();
- return freeHand == RobotFreeHand.Both ? RobotFreeHand.Blade1 : freeHand;
- }
- private void AddWaferPMMark(ModuleName pm)
- {
- var wafer = WaferManager.Instance.GetWafer(pm, 0);
- if (wafer.IsEmpty)
- return;
- dictWaferProcessPM[wafer.InnerId] = pm;
- }
- private void RemoveWaferPMMark(SlotItem slot)
- {
- var wafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
- if (wafer.IsEmpty)
- return;
- dictWaferProcessPM.Remove(wafer.InnerId);
- }
- private void ResetTraceFlag()
- {
- _lastTraceState = _currentTraceState = RtTraceState.Init;
- }
- public Result Monitor()
- {
- prelude();
- Pump();
- Pop();
- epilogue();
- return Result.RUN;
- }
- private List<ModuleName> GetPmUsedInRunningPj()
- {
- var pmUsed = new List<ModuleName>();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
- continue;
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
- {
- for (int i = 0; i < pj.Sequence.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
- pmUsed.Add(module);
- }
- }
- }
- }
- }
- return pmUsed;
- }
- private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
- {
- List<SchedulerPM> result = new List<SchedulerPM>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName != cj.Name)
- continue;
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- var pm = dictSchedulers[module] as SchedulerPM;
- if (pm != null && !result.Contains(pm))
- {
- result.Add(pm);
- }
- }
- }
- }
- }
- return result;
- }
- private void InitClean()
- {
- foreach (var pm in dictSchedulers)
- {
- if (ModuleHelper.IsPm(pm.Key))
- {
- var scheduler = pm.Value as SchedulerPM;
- scheduler.InitClean();
- }
- }
- }
- public Result MonitorCleanTasks()
- {
- if (!_isInited)
- {
- _isInited = true;
- InitClean();
- }
- foreach (var pm in dictSchedulers)
- {
- if (ModuleHelper.IsPm(pm.Key))
- {
- var scheduler = pm.Value as SchedulerPM;
- scheduler.MonitorCleanTasks();
- }
- }
- return Result.RUN;
- }
- private void PreJobClean(ControlJobInfo cj)
- {
- if (cj.IsPreJobCleanDone)
- return;
- cj.IsPreJobCleanDone = true;
- List<SchedulerPM> pms = GetPmNeeded(cj);
- foreach (var pm in pms)
- {
- pm.PreJobClean();
- }
- }
- private bool ActiveProcessJob(ProcessJobInfo pj)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- wafer.ProcessJob = pj;
- wafer.NextSequenceStep = 0;
- WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
- }
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
- JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
- pj.SetState(EnumProcessJobState.Processing);
- PreJobClean(cj);
- return true;
- }
- private void StartNewJob()
- {
- ControlJobInfo cjActived = null;
- List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State != EnumControlJobState.Executing)
- continue;
- cjActived = cj;
- foreach (var pjName in cjActived.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
- {
- ActiveProcessJob(pj);
- foreach (var moduleName in pmUsed)
- {
- if (!pmOccupied.Contains(moduleName))
- pmOccupied.Add(moduleName);
- }
- }
- break;
- }
- }
- }
- }
- private bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
- {
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMB))
- {
- var hasPmAvailable = false;
- foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
- {
- var pm = GetScheduler(stepModule) as SchedulerPM;
- if (pm != null)
- {
- if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
- {
- hasPmAvailable = true;
- break;
- }
- }
- }
- if (!hasPmAvailable)
- return false;
- if (processIn == ModuleName.System)
- return true;
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(processIn))
- return true;
- }
- }
- return false;
- }
- private bool IsFixedPMMode()
- {
- List<ModuleName> associatedPMs = new List<ModuleName>();
- foreach (var module in dictSchedulers.Keys)
- {
- if (ModuleHelper.IsLoadPort(module))
- {
- if (dictLPAssociatedPM.ContainsKey(module))
- {
- if (dictLPAssociatedPM[module] == ModuleName.System)
- return false;
- if (!associatedPMs.Contains(dictLPAssociatedPM[module]))
- associatedPMs.Add(dictLPAssociatedPM[module]);
- }
- }
- }
- return associatedPMs.Count >= 2;
- }
- void AdjustLPPriority(ModuleName lp)
- {
- foreach (var module in dictModules.Keys)
- {
- if (ModuleHelper.IsLoadPort(module))
- {
- dictModules[module].priority = module == lp ? ModulePriority.Low : ModulePriority.Middle;
- }
- }
- }
- void AdjustAlignerPriority(ModuleName aligner)
- {
- foreach (var module in dictModules.Keys)
- {
- if (ModuleHelper.IsAligner(module))
- {
- dictModules[module].priority = module == aligner ? ModulePriority.Low : ModulePriority.Middle;
- }
- }
- }
- private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
- {
- if (GetSystemInnerWaferCount() >= SystemInternalWaferCount || GetBufferWaferCount() > _maxBufferWaferCount)
- return new SlotItem(ModuleName.System, -1);
- foreach (var cj in _lstControlJobs)
- {
- if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
- continue;
- if (cj.State == EnumControlJobState.Executing)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
- {
- return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
- }
-
- }
- }
- }
- }
- }
- return new SlotItem(ModuleName.System, -1);
- }
- static public int GetSystemInnerWaferCount()
- {
- int count = 0;
- var lstPosition = new List<ModuleName>()
- {
- ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2, ModuleName.Flipper, ModuleName.PMA, ModuleName.PMB,
- };
- foreach (var moduleName in lstPosition)
- {
- if (ModuleHelper.IsInstalled(moduleName) && WaferManager.Instance.CheckHasWafer(moduleName, 0))
- count++;
- }
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
- count++;
- return count;
- }
- private int GetBufferWaferCount()
- {
- int nCount = 0;
- for (int i = 0; i < SC.GetValue<int>("EFEM.Buffer.SlotNumber"); i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.Buffer, i))
- nCount++;
- }
- return nCount;
- }
- #endregion transfer routine
- private void MonitorEfemRobotMapTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- if (_mapTarget.Count > 0)
- {
- ModuleName first = _mapTarget[0];
- //避免重复map,job信息被清除
- foreach (var cj in _lstControlJobs)
- {
- if (cj.Module != first.ToString())
- continue;
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
- {
- EV.PostWarningLog("System", $"{first} is running, can not map again");
- _mapTarget.Remove(first);
- }
- }
- SchedulerLoadPort lp = GetScheduler(first) as SchedulerLoadPort;
- if (lp != null && lp.IsAvailable)
- {
- _efemRobot.Map(first);
- _mapTarget.Remove(first);
- }
- }
- }
- private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
- {
- pmUsed = new List<ModuleName>();
- reason = "";
- bool pmIsReady = true;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- bool hasPm = false;
- foreach (var module in stepInfo.StepModules)
- {
- if (!ModuleHelper.IsPm(module))
- {
- hasPm = true;
- break;
- }
- PM pm = DEVICE.GetDevice<PM>(module.ToString());
- if (pm != null && pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
- {
- hasPm = true;
- }
- if (!pmUsed.Contains(module))
- pmUsed.Add(module);
- }
- if (pmIsReady && !hasPm)
- {
- reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
- pmIsReady = false;
- }
- }
- return pmIsReady;
- }
- private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
- {
- reason = "";
- bool foundPm = false;
- bool isAlignerAfterPm = false;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- foundPm = true;
- }
- if (ModuleHelper.IsAligner(module) && foundPm)
- {
- isAlignerAfterPm = true;
- }
- }
- }
- if (!foundPm)
- {
- reason = $"not found PM in the sequence file;";
- }
- if (isAlignerAfterPm)
- {
- reason += "Aligner after PM not support";
- }
- return true;
- }
- private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
- {
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- var recipeContent =
- RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
- if (string.IsNullOrEmpty(recipeContent))
- {
- reason = $"Can not find recipe file{recipeName}";
- return false;
- }
- }
- }
- }
- }
- }
- reason = "";
- return true;
- }
- private bool SetSequenceTemperatureInfo(SequenceInfo seq, out string reason)
- {
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- var recipeContent =
- RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
- if (string.IsNullOrEmpty(recipeContent))
- {
- reason = $"Can not find recipe file{recipeName}";
- return false;
- }
- try
- {
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(recipeContent);
- var substrateTemp = xml.DocumentElement.HasAttribute("SubstrateTemp") ? xml.DocumentElement.Attributes["SubstrateTemp"].Value : "";
- if (!float.TryParse(substrateTemp, out float temp))
- {
- reason = $"Invalid substrate temperature in recipe head {recipeName}";
- return false;
- }
- seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"] = temp;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- reason = $"recipe not valid, {recipeName}";
- return false;
- }
- }
- }
- }
- }
- }
- reason = "";
- return true;
- }
- private void AssociatedPMWithLP(ControlJobInfo ctrlInfo)
- {
- List<ModuleName> lstPMs = new List<ModuleName>();
- foreach (var process in _lstProcessJobs)
- {
- if (process.ControlJobName == ctrlInfo.Name)
- {
- foreach (var step in process.Sequence.Steps)
- {
- foreach (var module in step.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- if (!lstPMs.Contains(module))
- lstPMs.Add(module);
- }
- }
- }
- }
- }
- var lp = ModuleHelper.Converter(ctrlInfo.Module);
- dictLPAssociatedPM[lp] = lstPMs.Count == 1 ? lstPMs[0] : ModuleName.System;
- }
- private static bool IsWaferNeedGotoModule(WaferInfo wafer, ModuleName module)
- {
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
- {
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(module))
- return true;
- }
- return false;
- }
- private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
- {
- for (int i = 0; i < pj.SlotWafers.Count; ++i)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
- if (wafer.IsEmpty)
- return false;
- if (checkAllProcessed && IsWaferNeedGotoModule(wafer, ModuleName.PMA) || IsWaferNeedGotoModule(wafer, ModuleName.PMB))
- return false;
- }
- return true;
- }
- private void UpdateProcessJobStatus()
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.State == EnumProcessJobState.Processing)
- {
- if (CheckAllWaferReturned(pj, true))
- {
- pj.SetState(EnumProcessJobState.ProcessingComplete);
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
- }
- }
- else if (pj.State == EnumProcessJobState.Stopping)
- {
- if (CheckAllWaferReturned(pj, false))
- {
- pj.SetState(EnumProcessJobState.ProcessingComplete);
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
- }
- }
- }
- }
- private void CompleteJobClean(ControlJobInfo cj)
- {
- List<SchedulerPM> pms = GetPmNeeded(cj);
- foreach (var pm in pms)
- {
- pm.CompleteJobClean();
- }
- }
- private void UpdateControlJobStatus()
- {
- if (_lstControlJobs.Count == 0)
- return;
- if (_curAction.state != ActionState.Done)
- return;
- bool allControlJobComplete = true;
- List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
- foreach (var cj in _lstControlJobs)
- {
- if (!IsModuleAvailable(ModuleHelper.Converter(cj.Module)))
- {
- allControlJobComplete = false;
- continue;
- }
- if (cj.State == EnumControlJobState.Executing)
- {
- bool allPjCompleted = true;
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Error($"Not find pj named {pjName} in {cj.Name}");
- continue;
- }
- if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
- {
- allPjCompleted = false;
- break;
- }
- if (allPjCompleted)
- {
- pj.SlotWafers.ForEach(p => {
- if (ModuleHelper.IsLoadPort(p.Item1))
- {
- allPjCompleted = allPjCompleted && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(p.Item1.ToString()), p.Item2);
- }
- });
- }
- }
- if (allPjCompleted)
- {
- cj.SetState(EnumControlJobState.Completed);
- cj.EndTime = DateTime.Now;
- if (!(_isCycleMode && _cycledCount + 1 < _cycleSetPoint))
- {
- CompleteJobClean(cj);
- }
- _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- if (!(_isCycleMode&& _cycledCount < _cycleSetPoint))
- (GetScheduler( ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
- }
- }
- LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
- if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
- {
- cjRemoveList.Add(cj);
- }
- allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
- }
- if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
- {
- int countPerCycle = 0;
- int countProcessed = 0;
- foreach (var pj in _lstProcessJobs)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- countPerCycle++;
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- if (!wafer.IsEmpty && !IsWaferNeedGotoModule(wafer, ModuleName.PMA) && !IsWaferNeedGotoModule(wafer, ModuleName.PMB))
- countProcessed++;
- }
- }
- _cycledWafer = _cycledCount * countPerCycle + countProcessed;
- if (allControlJobComplete)
- {
- _cycledCount++;
- if (_cycledCount < _cycleSetPoint)
- {
- foreach (var cj in _lstControlJobs)
- {
- cj.SetState(EnumControlJobState.Executing);
- cj.LotInnerId = Guid.NewGuid();
- _dbCallback.LotCreated(cj);
- }
- foreach (var pj in _lstProcessJobs)
- {
- pj.SetState(EnumProcessJobState.Queued);
- pj.InnerId = Guid.NewGuid();
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- wafer.ProcessJob = null;
- wafer.NextSequenceStep = 0;
- wafer.ProcessState = EnumWaferProcessStatus.Idle;
- }
- }
- }
- }
- }
- foreach (var cj in cjRemoveList)
- {
- List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- pjRemoveList.Add(pj);
- }
- foreach (var pj in pjRemoveList)
- {
- _lstProcessJobs.Remove(pj);
- }
- _lstControlJobs.Remove(cj);
- }
- }
- #region public interface
- public bool CheckAllJobDone()
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
- return false;
- }
- return true;
- }
- public bool CheckJobJustDone(out string sJobName)
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
- {
- //LP;WaferSize;Lot;Number;Start;End;
- sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
- cj.BeenPosted = true;
- return true;
- }
- }
- sJobName = "NULL";
- return false;
- }
- public Result Start(params object[] objs)
- {
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
- _cycledWafer = 0;
- _cycledCount = 0;
- queMoveAction.Clear();
- _curAction.state = ActionState.Done;
- bool hasPmOnline = false;
- ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
- foreach (var pm in pms)
- {
- if (IsModuleAvailable(pm))
- {
- var pmSchedule = dictSchedulers[pm] as SchedulerPM;
- pmSchedule.SetPMAuto();
- hasPmOnline = true;
- continue;
- }
- }
- if (!hasPmOnline)
- {
- EV.PostWarningLog("Scheduler", "can not change to auto mode, at least one process chamber be online");
- return Result.FAIL;
- }
- return Result.RUN;
- }
- public void Map(string moduleName)
- {
- ModuleName target = ModuleHelper.Converter(moduleName);
- if (!ModuleHelper.IsLoadPort(target))
- {
- EV.PostWarningLog(LogSource, $"Invalid map target {target}");
- return;
- }
- if (!_mapTarget.Contains(target))
- {
- _mapTarget.Add(target);
- }
- }
- public bool CheckRecipeUsedInJob(string pathName)
- {
- foreach (var pj in _lstProcessJobs)
- {
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- if (pathName.EndsWith(recipeName + ".rcp"))
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
- public bool CheckSequenceUsedInJob(string pathName)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pathName.EndsWith(pj.Sequence.Name + ".seq"))
- return true;
- }
- return false;
- }
- public void CreateJob(Dictionary<string, object> param)
- {
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
- string[] slotSequence = (string[])param["SlotSequence"];
- string jobId = (string)param["JobId"];
- string module = (string)param["Module"];
- //bool autoStart = (bool)param["AutoStart"];
- string lotId = jobId;
- if (param.ContainsKey("LotId"))
- lotId = (string)param["LotId"];
- if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
- {
- EV.PostWarningLog(LogSource, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
- {
- EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (string.IsNullOrEmpty(jobId))
- {
- jobId = "CJ_Local_" + module;
- }
- if (_lstControlJobs.Exists(x => x.Name == jobId))
- {
- EV.PostWarningLog(LogSource, $"{jobId} already created");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- SchedulerLoadPort lp = GetScheduler(ModuleHelper.Converter(module)) as SchedulerLoadPort;
- if (!lp.CheckReadyRunJob())
- {
- EV.PostWarningLog(LogSource, $"{module} not ready");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- ControlJobInfo cj = new ControlJobInfo();
- cj.Name = jobId;
- cj.Module = module;
- cj.LotName = lotId;
- cj.LotInnerId = Guid.NewGuid();
- cj.LotWafers = new List<WaferInfo>();
- cj.CarrierID = lp.GetCarrierID();
- cj.SetState(EnumControlJobState.WaitingForStart);
- Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
- Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
- Dictionary<string, string> indexSequence = new Dictionary<string, string>();
- bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
- for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
- {
- if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
- continue;
- string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
- indexSequence[groupName] = slotSequence[i];
- if (!seqSlot.ContainsKey(groupName))
- {
- seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
- }
- if (!seqSlotWafers.ContainsKey(groupName))
- {
- seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
- }
- seqSlot[groupName][i] = true;
- if (!WaferManager.Instance.CheckHasWafer(module, i))
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} not in the carrier");
- //return;
- }
- if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- var smallWafer = SC.GetValue<int>($"System.SmallWafer");
- //特殊场景,3寸片第一片不能取放
- if (i == 0 && (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size == WaferSize.WS3) && (int)smallWafer == 3)
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} 3 inch slot {i + 1} is not supported.");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
- WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
- seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
- cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
- LOG.Info($"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
- }
- if (seqSlotWafers.Count == 0)
- {
- EV.PostWarningLog(LogSource, $"job has not assign wafer");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
- string[] seqs = seqSlot.Keys.ToArray();
- for (int i = 0; i < seqs.Length; i++)
- {
- ProcessJobInfo pj = new ProcessJobInfo();
- pj.Name = jobId + "_" + (i + 1);
- pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
- pj.ControlJobName = cj.Name;
- pj.LotName = lotId;
- pj.SlotWafers = seqSlotWafers[seqs[i]];
- pj.SetState(EnumProcessJobState.Queued);
- if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
- {
- EV.PostWarningLog(LogSource, $"no valid chamber for the {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!CheckSequenceOrderOk(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"sequence path not valid, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!SC.GetValue<bool>("System.IsATMMode") && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"recipe file not valid in the sequence, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!SetSequenceTemperatureInfo(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"sequence recipe temperature not valid, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- pjs.Add(pj);
- }
- _dbCallback.LotUpdate(cj);
- foreach (var pj in pjs)
- {
- cj.ProcessJobNameList.Add(pj.Name);
- _lstProcessJobs.Add(pj);
- }
- _lstControlJobs.Add(cj);
- AssociatedPMWithLP(cj);
- _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
- }
- public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- return pj;
- }
- return null;
- }
- public void AbortJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
- return;
- }
- List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- {
- pj.SetState(EnumProcessJobState.Aborting);
- pjAbortList.Add(pj);
- int unprocessed = 0;
- int aborted = 0;
- WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
- foreach (var waferInfo in wafers)
- {
- waferInfo.ProcessJob = null;
- waferInfo.NextSequenceStep = 0;
- if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
- unprocessed++;
- }
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
- }
- }
- _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- foreach (var pj in pjAbortList)
- {
- _lstProcessJobs.Remove(pj);
- }
- _lstControlJobs.Remove(cj);
- }
- public void StopJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
- return;
- }
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- {
- pj.SetState(EnumProcessJobState.Stopping);
- }
- }
- _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- }
- public void ResumeJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.Paused)
- {
- cj.SetState(EnumControlJobState.Executing);
- }
- _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
- }
- public void PauseJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.Executing)
- {
- cj.SetState(EnumControlJobState.Paused);
- }
- _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
- }
- public void StartJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.WaitingForStart)
- {
- cj.SetState(EnumControlJobState.Executing);
- //PreJobClean(cj);
- (GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobStart();
- cj.StartTime = DateTime.Now;
- _dbCallback.LotCreated(cj);
- _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
- if (!_blockingWatcher.IsRunning)
- _blockingWatcher.Restart();
- ResetTraceFlag();
- }
- }
- private void NotifyFaWaferEnd()
- {
- if (ModuleHelper.IsLoadPort(_curAction.targetModule))
- {
- // Notify FA for Port1JobWaferEnd
- if (_curAction.eType == EnumTransferType.Place)
- {
- ProcessJobInfo pj = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot)
- .ProcessJob;
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- _faCallback.JobWaferEnd(cj, pj, _curAction.targetModule.ToString(), _curAction.targetSlot);
- }
- }
- }
- public void ResetIdleCleanTime(string module)
- {
- if (string.IsNullOrEmpty(module))
- {
- ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
- foreach (var schedulerPm in pms)
- {
- var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
- pmSchedule.ResetIdleCleanTime();
- }
- }
- else
- {
- var pm = ModuleHelper.Converter(module);
- if (ModuleHelper.IsPm(pm))
- {
- var pmSchedule = dictSchedulers[pm] as SchedulerPM;
- pmSchedule.ResetIdleCleanTime();
- }
- }
- }
- public void ResetIdlePurgeTime(string module)
- {
- if (string.IsNullOrEmpty(module))
- {
- ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
- foreach (var schedulerPm in pms)
- {
- var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
- pmSchedule.ResetIdlePurgeTime();
- }
- }
- else
- {
- var pm = ModuleHelper.Converter(module);
- if (ModuleHelper.IsPm(pm))
- {
- var pmSchedule = dictSchedulers[pm] as SchedulerPM;
- pmSchedule.ResetIdlePurgeTime();
- }
- }
- }
- public void Clear()
- {
- _efemRobot.ResetTask();
- foreach (var module in dictSchedulers)
- {
- module.Value.ResetTask();
- }
- _lstControlJobs.Clear();
- _lstProcessJobs.Clear();
- _mapTarget.Clear();
- queMoveAction.Clear();
- _curAction.state = ActionState.Done;
- }
- #endregion
- }
- }
|