using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes; namespace FutureEfemLib.Efems { class EfemHomeRoutine : ModuleRoutine, IRoutine { enum RoutineStep { InitEfem, ClearEfemError, InitRobot, HomeRobot, CheckRobotWafer, ResetSignalTowerData, } private int _timeout = 0; private bool _needInitEfem; private IEfemController _efem = null; private EfemModule _efemModule; public EfemHomeRoutine(EfemModule module) { Module = ModuleName.EfemRobot.ToString(); Name = "Home"; _efem = module.EfemDevice; _efemModule = module; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.EfemRobot.HomeTimeout"); _needInitEfem = !_efem.IsInitialized; Notify($"Start"); return Result.RUN; } public Result Monitor() { try { if (_needInitEfem) { InitEfem((int)RoutineStep.InitEfem, _timeout); } ClearEfemError((int)RoutineStep.ClearEfemError, _timeout); InitRobot((int)RoutineStep.InitRobot, _timeout); HomeRobot((int)RoutineStep.HomeRobot, _timeout); CheckRobotWafer((int)RoutineStep.CheckRobotWafer, _timeout); ResetSignalTowerData((int)RoutineStep.ResetSignalTowerData); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void InitEfem(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start initialize EFEM status"); string reason; if (!_efem.Home(out reason)) { Stop(reason); return false; } return true; }, () => { if (!_efem.IsInitialized) return false; if (_efem.CheckIsBusy(ModuleName.System)) 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 ClearEfemError(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start clear EFEM error"); //string reason; (_efem as RorzeEfem).ClearError(); return true; }, () => { if (_efem.CheckIsBusy(ModuleName.System)) return false; //if ((_efem as StripEfem).HasAlarm) // 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 clear error in {0} seconds", timeout)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void InitRobot(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start initialize robot status"); _efemModule.RobotDevice.Abort(); if (!_efemModule.RobotDevice.Home(out string reason)) { Stop(reason); return false; } return true; }, () => { if (!_efemModule.RobotDevice.IsIdle) 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 HomeRobot(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start home robot"); if (!_efemModule.RobotDevice.HomeAllAxes(out string reason)) { Stop(reason); return false; } return true; }, () => { if (_efemModule.RobotDevice.IsError) { return null; } if (!_efemModule.RobotDevice.IsIdle) 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 ResetSignalTowerData(int id ) { Tuple ret = Execute(id, () => { Notify($"reset signal tower"); //_efemModule.SignalTowerDevice.ResetData(); return true; } ); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop(string.Format("Home failed.")); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckRobotWafer(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Start check robot wafer present"); string reason; if (!_efem.QueryRobotWaferPresence(out _, out reason)) { Stop(reason); return false; } return true; }, () => { if (_efem.CheckIsBusy(ModuleName.System)) 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 Abort() { } } }