using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; namespace FutureEfemLib.LPs { class LoadPortHomeRoutine : ModuleRoutine, IRoutine { enum RoutineStep { ClearError, Home, QueryStatus, } private int _timeout = 0; LoadPort _lp = null; private LoadPortModule _lpModule; public LoadPortHomeRoutine(LoadPortModule lpModule) { _lpModule = lpModule; Module = lpModule.Module; Name = "Home"; _lp = DEVICE.GetDevice($"{Module}"); } public bool Initalize() { return true; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.LoadPort.HomeTimeout"); Notify($"Start"); return Result.RUN; } public Result Monitor() { try { //ClearError((int)RoutineStep.ClearError, _lp, _timeout); Home((int)RoutineStep.Home, _lp, _timeout); //QueryStatus((int)RoutineStep.QueryStatus, _lp, _timeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException ex) { LOG.Write(ex); return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void ClearError(int id, LoadPort lp, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Clear error {lp.Name}"); return true; }, () => { if (_lp.Error) return false; if (_lp.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, LoadPort lp, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start home {lp.Name}"); string reason; if (!lp.Home(out reason)) { Stop(reason); return false; } return true; }, () => { if (_lp.Error) return false; if (_lp.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, LoadPort lp, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start query status {lp.Name}"); string reason; if (!lp.QueryState(out reason)) { Stop(reason); return false; } return true; }, () => { if (_lp.Error) return false; if (_lp.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() { } } }