using System; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Schedulers; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots; using MECF.Framework.RT.EquipmentLibrary.LogicUnits; using MECF.Framework.RT.ModuleLibrary.PMModules; using MECF.Framework.RT.ModuleLibrary.SystemModules; namespace FutureEfemLib.Efems { class EfemRetractRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckBeforeRetract, Retract, WaitCloseSlitValveInterlock, CloseSlitValve, PostTransfer } private ModuleName _source; private int _sourceSlot; private Hand _blade; private int _timeout; // private TMSlitValveRoutine _closeSlitValveRoutine = new TMSlitValveRoutine(); private EfemModule _robotModule; //private RobotPostionEnum postiontype; private ITransferTarget _target; public EfemRetractRoutine(EfemModule robotModule) { Module = "EfemRobot"; Name = "Retract"; _robotModule = robotModule; } private string _type; public void Init(ModuleName source, int sourceSlot, string blade,string type) { _source = source; _sourceSlot = sourceSlot; _blade = (Hand)Enum.Parse(typeof(Hand), blade); _type = type; //_closeSlitValveRoutine.Init(source.ToString(), false); } public void Init(ModuleName source, int sourceSlot, int blade) { Init(source, sourceSlot, blade); } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue("EFEM.EfemRobot.PickTimeout"); //if (ModuleHelper.IsLoadLock(_source)) //{ // LoadLock ll = DEVICE.GetDevice(_source.ToString()); // if (!ll.CheckEnableTransfer(EnumTransferType.Extend)) // { // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer"); // return Result.FAIL; // } //} if (ModuleHelper.IsPm(_source)) { if (_type=="Pick") { //postiontype = RobotPostionEnum.PickRetracted;// _blade == Hand.Blade1 ?RobotPostionEnum.PickRetractLow: RobotPostionEnum.PickRetractUp; } else { //postiontype = RobotPostionEnum.PlaceRetract;//_blade == Hand.Blade1 ? RobotPostionEnum.PlaceRetractLow : RobotPostionEnum.PlaceRetractUp; } // PMModuleBase pm = DEVICE.GetDevice(_source.ToString()+"."+ _source.ToString()); _target = EquipmentManager.Modules[_source] as ITransferTarget; //if (!pm.CheckReadyForTransfer(ModuleName.EfemRobot, _blade, _sourceSlot, EnumTransferType.Retract, out _)) //{ // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer"); // return Result.FAIL; //} } Notify($"Start, retract from {_source} slot {_sourceSlot + 1} with {_blade}"); return Result.RUN; } public void Abort() { Notify("Abort"); } public Result Monitor() { try { RobotRetract((int)RoutineStep.Retract,_source, _sourceSlot, _blade, _timeout); //WaitSlitValveCloseInterlock((int)RoutineStep.WaitCloseSlitValveInterlock, TMDevice.GetSlitValve(_source), _timeout); //ExecuteRoutine((int)RoutineStep.CloseSlitValve, _closeSlitValveRoutine); if (ModuleHelper.IsPm(_source)) { PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Retract, _timeout); } } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify($"Finish, retract from {_source} slot {_sourceSlot + 1} with {_blade}"); return Result.DONE; } public void RobotRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("robot execute goto command"); //string reason; //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, postiontype, out reason)) //{ // Stop(reason); // return false; //} return true; }, () => { if (_robotModule.RobotDevice.IsError) return null; if (_robotModule.RobotDevice.IsIdle) return true; return false; }, 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 PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"{pm.Name} post transfer "); if (!pm.PostTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, out string reason)) { Stop(reason); return false; } return true; }, () => { if (pm.IsError) { return null; } return pm.IsReady; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop($"{pm.Name} error"); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} post transfer timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } } }