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 LoadPortUnclampRoutine : ModuleRoutine, IRoutine { enum RoutineStep { Unclamp, QueryStatus, } private int _timeout = 0; LoadPort _lp = null; private LoadPortModule _lpModule; public LoadPortUnclampRoutine(LoadPortModule lpModule) { _lpModule = lpModule; Module = lpModule.Module; Name = "Unclamp"; _lp = DEVICE.GetDevice($"{Module}"); } public bool Initalize() { return true; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.LoadPort.MotionTimeout"); Notify($"Start"); return Result.RUN; } public Result Monitor() { try { Unclamp((int)RoutineStep.Unclamp, _lp, _timeout); QueryStatus((int)RoutineStep.QueryStatus, _lp, _timeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException ) { //LOG.Error(ex); return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void Unclamp(int id, LoadPort lp, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start unclamp {lp.Name}"); string reason; if (!lp.Unclamp(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("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 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("timeout, can not complete in {0} seconds", timeout)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void Abort() { } } }