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 LoadPortDockRoutine : ModuleRoutine, IRoutine { enum RoutineStep { Dock, QueryStatus, } private int _timeout = 0; LoadPort _lp = null; private LoadPortModule _lpModule; public LoadPortDockRoutine(LoadPortModule lpModule) { _lpModule = lpModule; Module = lpModule.Module; Name = "Dock"; _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 { Dock((int)RoutineStep.Dock, _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 Dock(int id, LoadPort lp, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start Dock {lp.Name}"); string reason; if (!lp.Dock(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() { } } }