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 AlignerHomeRoutine : ModuleRoutine, IRoutine { enum RoutineStep { ClearError, Home, QueryStatus, } private int _timeout = 0; AlignerBase _aligner = null; public AlignerHomeRoutine(AlignerModuleBase module) { Module = module.Module; Name = "Home"; } public bool Initalize() { return true; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.Aligner.HomeTimeout"); _aligner = DEVICE.GetDevice($"{ModuleName.Aligner}.{ModuleName.Aligner}"); Notify($"Start"); return Result.RUN; } public Result Monitor() { try { //ClearError((int)RoutineStep.ClearError, _aligner, _timeout); Home((int)RoutineStep.Home, _aligner, _timeout); QueryStatus((int)RoutineStep.QueryStatus, _aligner, _timeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void ClearError(int id, AlignerBase aligner, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Clear error {aligner.Name}"); //string reason; //if (!aligner.ClearError(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 Home(int id, AlignerBase aligner, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start home {aligner.Name}"); string reason; if (!aligner.Home(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("Home failed.")); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void QueryStatus(int id, AlignerBase aligner, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start query status {aligner.Name}"); string reason; if (!aligner.QueryWaferPresence(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("Query status failed.")); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop(string.Format("Query status timeout, can not complete in {0} seconds", timeout)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void Abort() { } } }