using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; namespace VirgoRT.Modules.LPs { class LoadPortUnloadRoutine : ModuleRoutine, IRoutine { enum RoutineStep { Unload, } private int _timeout = 0; private LoadPortModule _lpModule; public LoadPortUnloadRoutine(LoadPortModule lpModule) { _lpModule = lpModule; Module = lpModule.Module; Name = "Unload"; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.LoadPort.MotionTimeout"); //if (!_lp.IsPresent || !_lp.IsPlacement) //{ // EV.PostWarningLog(Module, $"{Module} not found carrier, can not load"); // return Result.FAIL; //} Notify($"Start"); return Result.RUN; } public Result Monitor() { try { Unload((int)RoutineStep.Unload, _timeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException ) { return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void Unload(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start Unload {_lpModule.Name}"); _lpModule.LPDevice.Unload(); return true; }, () => { if (_lpModule.LPDevice.IsError) return null; if (_lpModule.LPDevice.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 Abort() { } } }