123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 |
- using System.Diagnostics;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.ModuleLibrary.PMModules;
- using MECF.Framework.RT.ModuleLibrary.SystemModules;
- namespace EfemDualSchedulerLib.Schedulers
- {
- public class SchedulerPM : SchedulerModule
- {
- public override bool IsAvailable
- {
- get { return _pm.IsReady && _pm.IsOnline && CheckTaskDone() && !_waitCompletejobClean; }
- }
- public override bool IsOnline
- {
- get { return _pm.IsOnline; }
- }
- public override bool IsError
- {
- get { return _pm.IsError; }
- }
- public bool IsIdle
- {
- get { return _pm.IsReady && _pm.IsOnline && CheckTaskDone(); }
- }
- private PMModuleBase _pm = null;
- private ModuleName _taskRobot;
- private EnumTransferType _taskTransferType;
- private int _taskSlot;
- private DeviceTimer _timer = new DeviceTimer();
- protected readonly string _statNameProcessedWaferCount;//zyx add 2021.8.6
- protected readonly string _statNameProcessTime;
- public RD_TRIG IdlePurgeTrig { get; set; } = new RD_TRIG();
- public Stopwatch IdlePurgeTimer { get; set; } = new Stopwatch();
- public int IdlePurgeTime { get; set; }
- public int IdlePurgeNextRunTime { get; set; }
- public RD_TRIG IdleCleanTrig { get; set; } = new RD_TRIG();
- public Stopwatch IdleCleanTimer { get; set; } = new Stopwatch();
- public int IdleCleanTime { get; set; }
- public int IdleCleanNextRunTime { get; set; }
- private bool _waitPreJobClean;
- private bool _waitCompletejobClean;
- private R_TRIG _trigIdleCleanFailed = new R_TRIG();
- private R_TRIG _trigIdlePurgeFailed = new R_TRIG();
- public RD_TRIG PreJobCleanTrig { get; set; } = new RD_TRIG();
- public Stopwatch PreJobCleanTimer { get; set; } = new Stopwatch();
- public int PreJobCleanTime { get; set; }
- //protected readonly string _statNameRFTime;
- //protected readonly string _statNameMWTime;
- public SchedulerPM(ModuleName chamber) : base(chamber.ToString())
- {
- _pm = EquipmentManager.Modules[chamber] as PMModuleBase;
- _pm.IsOnline = true;
- _statNameProcessedWaferCount = $"{chamber}.ProcessedWaferCount";
- _statNameProcessTime = $"{chamber}.ProcessTime";
- //_statNameRFTime = $"{chamber}.RFTime";
- //_statNameMWTime = $"{chamber}.MWTime";
- System.Diagnostics.Trace.Assert(_pm != null);
- }
- public bool CheckTempReady(double temp1, double temp2)
- {
- return _pm.CheckTempReady(temp1, temp2);
- }
- public override bool IsReadyForPick(ModuleName robot, Hand blade, int slot)
- {
- return _pm.CheckReadyForTransfer(robot, blade, slot, EnumTransferType.Pick, out _)
- && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(_module), slot);
- }
- public override bool IsReadyForPlace(ModuleName robot, Hand blade, int slot)
- {
- return _pm.CheckReadyForTransfer(robot, blade, slot, EnumTransferType.Place, out _)
- && WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(_module), slot);
- }
- public override bool PrepareTransfer(ModuleName robot, EnumTransferType type, int slot)
- {
- _task = TaskType.PrepareTransfer;
- _taskRobot = robot;
- _taskSlot = slot;
- _taskTransferType = type;
- if (!_pm.PrepareTransfer(robot, Hand.Blade1, slot, type, 0, 0, false, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- LogTaskStart(_task, $"{robot} {type} slot {slot + 1}");
- return true;
- }
- public bool Preheating(double temperature1, double temperature2)
- {
- _task = TaskType.Heating;
- if (_pm.InvokePreHeat(temperature1, temperature2))
- {
- LOG.Write("Can not PreHeat");
- return false;
- }
- LogTaskStart(_task, $"preheat to {temperature1},{temperature2}");
- return true;
- }
- public bool IsPrepareTransfer(ModuleName robot, EnumTransferType type, int slot)
- {
- return _task == TaskType.PrepareTransfer && _taskRobot == robot && _taskSlot == slot &&
- _taskTransferType == type;
- }
- public override bool Process(string recipeName, bool isCleanRecipe, bool withWafer)
- {
- _task = TaskType.Process;
- //if (SC.GetValue<bool>("System.IsATMMode"))
- //{
- // _timer.Start(SC.GetValue<int>("System.ATMProcessDelayTime") * 1000);
- // //_entityTaskToken = (int)FSM_MSG.TIMER;
- // WaferManager.Instance.GetWafer(Module, 0).ProcessState = EnumWaferProcessStatus.InProcess;
- // WaferManager.Instance.GetWafer(Module, 1).ProcessState = EnumWaferProcessStatus.InProcess;
- //}
- //else
- {
- if (!_pm.Process(recipeName, isCleanRecipe, withWafer, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- }
- UpdateStats_data(recipeName, isCleanRecipe);
- LogTaskStart(_task, $"recipe: {recipeName}, clean: {isCleanRecipe}, with wafer: {withWafer}");
- return true;
- }
- public virtual void UpdateStats_data(string recipeName, bool isClean)
- {
- if (!isClean)
- {
- int value1 = StatsDataManager.Instance.Increase(_statNameProcessedWaferCount);
- int value2 = StatsDataManager.Instance.Increase(_statNameProcessTime);
- LOG.Write($"{_statNameProcessedWaferCount} counter increase 1 to {value1}");
- LOG.Write($"{_statNameProcessTime} counter increase 1 to {value2}");
- }
- }
- public bool CheckTaskDone()
- {
- bool ret = false;
- switch (_task)
- {
- case TaskType.None:
- ret = true;
- break;
- case TaskType.PrepareTransfer:
- ret = _pm.CheckReadyForTransfer(_taskRobot, Hand.Blade1, _taskSlot, _taskTransferType, out _);
- break;
- case TaskType.Heating:
- ret = true;
- break;
- case TaskType.Process:
- case TaskType.IdlePurgeProcess:
- case TaskType.IdleCleanProcess:
- case TaskType.PreJobProcess:
- case TaskType.CompleteJobProcess:
- //if (SC.GetValue<bool>("System.IsATMMode"))
- //{
- // ret = _timer.IsTimeout();
- // if (ret)
- // {
- // WaferManager.Instance.GetWafer(Module, 0).ProcessState = EnumWaferProcessStatus.Completed;
- // WaferManager.Instance.GetWafer(Module, 1).ProcessState = EnumWaferProcessStatus.Completed;
- // }
- //}
- //else
- {
- ret = _pm.IsReady;
- }
- break;
- }
- if (ret && _task != TaskType.None)
- {
- LogTaskDone(_task, "");
- _task = TaskType.None;
- }
- return ret;
- }
- public bool CheckInProcess()
- {
- return _task == TaskType.Process;
- }
- public bool CloseSlitValve()
- {
- return _pm.CloseSlitValve(out _);
- }
- public bool CheckSlitValveClose()
- {
- return _pm.CheckSlitValveClose();
- }
- public bool Monitor()
- {
- return true;
- }
- #region clean task
- public void InitClean()
- {
- DATA.Subscribe($"{Module}.IdlePurgeNextRunTime", () => IdlePurgeNextRunTime);
- DATA.Subscribe($"{Module}.IdleCleanNextRunTime", () => IdleCleanNextRunTime);
- OP.Subscribe($"{Module}.ResetIdlePurgeTime", (string cmd, object[] args) =>
- {
- ResetIdlePurgeTime();
- return true;
- });
- OP.Subscribe($"{Module}.ResetIdleCleanTime", (string cmd, object[] args) =>
- {
- ResetIdleCleanTime();
- return true;
- });
- }
- internal void ResetIdlePurgeTime()
- {
- IdlePurgeTimer.Restart();
- }
- internal void ResetIdleCleanTime()
- {
- IdleCleanTimer.Restart();
- }
- public bool ResetClean(bool resetPurge, bool resetClean, bool jobClean)
- {
- if (resetPurge)
- {
- IdlePurgeTrig.RST = true;
- IdlePurgeTimer.Stop();
- IdlePurgeTime = 0;
- }
- if (resetClean)
- {
- IdleCleanTrig.RST = true;
- IdleCleanTimer.Stop();
- IdleCleanTime = 0;
- }
- if (jobClean)
- {
- _waitPreJobClean = false;
- _waitCompletejobClean = false;
- PreJobCleanTrig.RST = true;
- PreJobCleanTimer.Stop();
- }
- return true;
- }
- public void MonitorCleanTasks()
- {
- var hasWafer = WaferManager.Instance.CheckHasWafer(Module, 0) && WaferManager.Instance.CheckHasWafer(Module, 1);
- var enablePurge = false;//SC.GetValue<bool>($"{Module}.IdlePurge.IsEnabled");
- var enableClean = SC.GetValue<bool>($"{Module}.IdleClean.IsEnabled");
- #region Idle Purge
- IdlePurgeTrig.CLK = (IsIdle || _task != TaskType.IdlePurgeProcess) && enablePurge && !hasWafer;
- if (IdlePurgeTrig.R)
- {
- LOG.Write($"{Module} idle purge start calc elapse time");
- IdlePurgeTimer.Restart();
- }
- if (IdlePurgeTrig.T)
- {
- LOG.Write($"{Module} idle purge stopped calc elapse time");
- ResetClean(true, false, false);
- }
- if (IdlePurgeTimer.IsRunning)
- {
- IdlePurgeTime = (int)IdlePurgeTimer.ElapsedMilliseconds / 1000;
- int idlePurgeTimeSetPoint = SC.GetValue<int>($"{Module}.IdlePurge.IdlePurgeTime");
- var nextRunTime = idlePurgeTimeSetPoint - IdlePurgeTime;
- if (nextRunTime < 0)
- nextRunTime = 0;
- if (enablePurge)
- {
- if (nextRunTime <= 0 && IsAvailable)
- {
- var recipe = SC.GetStringValue($"{Module}.IdlePurge.IdlePurgeRecipe");
- if (string.IsNullOrEmpty(recipe))
- {
- _trigIdlePurgeFailed.CLK = true;
- LOG.Write($"{Module} Idle purge can not run, recipe is empty");
- ResetClean(true, false, false);
- }
- else if (hasWafer)
- {
- _trigIdlePurgeFailed.CLK = true;
- LOG.Write($"{Module} Idle purge can not run, has wafer");
- ResetClean(true, false, false);
- }
- else
- {
- _trigIdlePurgeFailed.CLK = false;
- LOG.Write($"{Module} Start run idle purge recipe {recipe}");
- IdlePurgeProcess("ALD\\Process\\" + recipe);
- }
- if (_trigIdlePurgeFailed.Q)
- {
- EV.PostWarningLog(Module.ToString(), "Can not run idle purge recipe");
- }
- }
- }
- else
- {
- nextRunTime = 0;
- }
- IdlePurgeNextRunTime = nextRunTime;
- }
- else
- {
- IdlePurgeNextRunTime = 0;
- }
- #endregion
- #region Idle Clean
- IdleCleanTrig.CLK = (IsIdle || _task != TaskType.IdleCleanProcess) && enableClean && !hasWafer;
- if (IdleCleanTrig.R)
- {
- LOG.Write($"{Module} idle clean start calc elapse time");
- IdleCleanTimer.Restart();
- }
- if (IdleCleanTrig.T)
- {
- LOG.Write($"{Module} idle clean stopped calc elapse time");
- ResetClean(false, true, false);
- }
- if (IdleCleanTimer.IsRunning)
- {
- IdleCleanTime = (int)IdleCleanTimer.ElapsedMilliseconds / 1000;
- int idleCleanTimeSetPoint = SC.GetValue<int>($"{Module}.IdleClean.IdleCleanTime");
- var nextRunTime = idleCleanTimeSetPoint - IdleCleanTime;
- if (nextRunTime < 0)
- nextRunTime = 0;
- if (enableClean)
- {
- if (nextRunTime <= 0 && IsAvailable)
- {
- var recipe = SC.GetStringValue($"{Module}.IdleClean.IdleCleanRecipe");
- if (string.IsNullOrEmpty(recipe))
- {
- _trigIdleCleanFailed.CLK = true;
- LOG.Write($"{Module} Idle clean can not run, recipe is empty");
- ResetClean(false, true, false);
- }
- else if (hasWafer)
- {
- _trigIdleCleanFailed.CLK = true;
- LOG.Write($"{Module} Idle clean can not run, has wafer");
- ResetClean(false, true, false);
- }
- else
- {
- _trigIdleCleanFailed.CLK = false;
- LOG.Write($"{Module} Start run idle Clean recipe {recipe}");
- IdleCleanProcess($"{Module}\\" + recipe);
- }
- if (_trigIdleCleanFailed.Q)
- {
- EV.PostWarningLog(Module.ToString(), "Can not run idle clean recipe");
- }
- }
- }
- else
- {
- nextRunTime = 0;
- }
- IdleCleanNextRunTime = nextRunTime;
- }
- else
- {
- IdleCleanNextRunTime = 0;
- }
- #endregion
- #region PreJob Clean
- var enableJobClean = SC.GetValue<bool>($"{Module}.JobClean.IsEnabled");
- var enablePreJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnablePreJobClean");
- var enableCompleteJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnableCompleteJobClean");
- if (enableJobClean && enableCompleteJobClean && _waitCompletejobClean && IsIdle)
- {
- var recipe = SC.GetStringValue($"{Module}.JobClean.CompleteJobCleanRecipe");
- if (string.IsNullOrEmpty(recipe))
- {
- EV.PostWarningLog(Module.ToString(), "complete job clean can not run, recipe is empty");
- }
- else if (hasWafer)
- {
- EV.PostWarningLog(Module.ToString(), "complete job clean can not run, has wafer");
- }
- else
- {
- EV.PostInfoLog(Module.ToString(), $"Start run complete job clean recipe {recipe}");
- CompleteJobProcess($"{Module}\\" + recipe);
- }
- _waitCompletejobClean = false;
- }
- PreJobCleanTrig.CLK = enableJobClean && enablePreJobClean && IsIdle;
- if (PreJobCleanTrig.R)
- {
- PreJobCleanTimer.Restart();
- }
- if (PreJobCleanTrig.T)
- {
- ResetClean(false, false, true);
- }
- if (enableJobClean && enablePreJobClean && _waitPreJobClean && PreJobCleanTimer.IsRunning && IsIdle)
- {
- PreJobCleanTime = (int)PreJobCleanTimer.ElapsedMilliseconds / 1000;
- int PreJobCleanIdleTimeSP = SC.GetValue<int>($"{Module}.JobClean.IdleCleanTime");
- if (PreJobCleanTime >= PreJobCleanIdleTimeSP)
- {
- var recipe = SC.GetStringValue($"{Module}.JobClean.PreJobCleanRecipe");
- if (string.IsNullOrEmpty(recipe))
- {
- EV.PostWarningLog(Module.ToString(), "pre job clean can not run, recipe is empty");
- }
- else if (hasWafer)
- {
- EV.PostWarningLog(Module.ToString(), "pre job clean can not run, has wafer");
- }
- else
- {
- EV.PostInfoLog(Module.ToString(), $"Start run pre job clean recipe {recipe}");
- PreJobProcess($"{Module}\\" + recipe);
- }
- }
- }
- #endregion
- }
- public bool IdlePurgeProcess(string recipeName)
- {
- _task = TaskType.IdlePurgeProcess;
- if (!_pm.Process(recipeName, true, false, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- LogTaskStart(_task, $"recipe: {recipeName}, clean: {true}, with wafer: {false}");
- return true;
- }
- public bool IdleCleanProcess(string recipeName)
- {
- _task = TaskType.IdleCleanProcess;
- if (!_pm.Process(recipeName, true, false, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- LogTaskStart(_task, $"recipe: {recipeName}, clean: {true}, with wafer: {false}");
- return true;
- }
- public void PreJobClean()
- {
- var enableJobClean = SC.GetValue<bool>($"{Module}.JobClean.IsEnabled");
- var enablePreJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnablePreJobClean");
- var enableCompleteJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnableCompleteJobClean");
- _waitPreJobClean = enableJobClean && enablePreJobClean;
- }
- public bool PreJobProcess(string recipeName)
- {
- _task = TaskType.PreJobProcess;
- if (!_pm.Process(recipeName, true, false, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- LogTaskStart(_task, $"recipe: {recipeName}, clean: {true}, with wafer: {false}");
- return true;
- }
- public void CompleteJobClean()
- {
- var enableJobClean = SC.GetValue<bool>($"{Module}.JobClean.IsEnabled");
- var enablePreJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnablePreJobClean");
- var enableCompleteJobClean = SC.GetValue<bool>($"{Module}.JobClean.EnableCompleteJobClean");
- _waitCompletejobClean = enableJobClean && enableCompleteJobClean;
- }
- public bool CompleteJobProcess(string recipeName)
- {
- _task = TaskType.CompleteJobProcess;
- if (!_pm.Process(recipeName, true, false, out string reason))
- {
- LOG.Write(reason);
- return false;
- }
- LogTaskStart(_task, $"recipe: {recipeName}, clean: {true}, with wafer: {false}");
- return true;
- }
- #endregion
- }
- }
|