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