using System; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; namespace FutureEfemLib.Efems { public class EfemGotoRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckBeforeGoto, RobotGoto, } private int _gotoTimeout; private ModuleName _source; private int _sourceSlot; private Hand _hand; private EfemModule _robotModule; public EfemGotoRoutine(EfemModule robotModule) { Module = "EfemRobot"; Name = "Goto"; _robotModule = robotModule; } public Result Start(params object[] objs) { _gotoTimeout = SC.GetValue("EFEM.EfemRobot.GotoTimeout"); Reset(); Notify($"Start, Goto {_source} slot {_sourceSlot + 1}, by {_hand}"); return Result.RUN; } public void Init(ModuleName source, int slot, Hand hand) { _source = source; _sourceSlot = slot; _hand = hand; } public void Abort() { Notify("Abort"); } public Result Monitor() { try { CheckBeforeGoto((int)RoutineStep.CheckBeforeGoto, _source, _sourceSlot, _hand); RobotGoto((int)RoutineStep.RobotGoto, _source, _sourceSlot, _hand, _gotoTimeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify($"Finish, robot move to {_source} slot {_sourceSlot + 1}, by {_hand}"); return Result.DONE; } public void CheckBeforeGoto(int id, ModuleName source, int slot, Hand blade) { Tuple ret = Execute(id, () => { Notify("Check robot goto motion is enabled"); string reason = string.Empty; return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } public void RobotGoto(int id, ModuleName chamber, int slot, Hand hand, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("robot execute goto command"); string reason; if (!_robotModule.RobotDevice.Goto(chamber, hand, slot, 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()); } } } }