using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners; using MECF.Framework.RT.ModuleLibrary.AlignerModules; namespace FutureEfemLib.Aligners { class AlignerAlignRoutine : ModuleRoutine, IRoutine { enum Align { Align, } private int _timeout = 0; private double _angle = 0.0; private AlignerBase _aligner; public AlignerAlignRoutine(AlignerModuleBase module) { Module = module.Module; Name = "Align"; _aligner = DEVICE.GetDevice($"{ModuleName.Aligner}.{ModuleName.Aligner}"); _angle = SC.GetValue("EFEM.Aligner.DefaultNotchDegree"); } public bool Initalize() { return true; } public void Init(double notch) { _angle = notch; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.Aligner.AlignTimeout"); Notify($"Start align to {_angle} degree"); //AlignersState.IsAligning = true; return Result.RUN; } public Result Monitor() { //AlignersState.IsAligning = true; try { AlignWafer((int)Align.Align, _angle, _timeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { _stepName = ""; return Result.FAIL; } Notify("Finished"); // AlignersState.IsAligning = false; return Result.DONE; } public void AlignWafer(int id, double angle, int timeout) { Tuple ret = ExecuteAndWait(id, () => { //Notify($"Start align to {angle} degree"); string reason; if (!_aligner.Align(angle, out reason)) { Stop(reason); return false; } return true; }, () => { if (_aligner.IsError) return null; if (_aligner.IsBusy) return false; return true; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop(string.Format("failed.")); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop(string.Format("timeout, can not complete in {0} seconds", timeout)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void Abort() { //AlignersState.IsAligning = false; Notify("Abort"); } } }