using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Sorter.Common; using FutureEfemLib.LPs; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.ModuleLibrary.LPModules; using MECF.Framework.RT.ModuleLibrary.SystemModules; namespace FutureEfemLib.Efems { public class EfemMapRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckTargetEnableMap, Map, } private int _mapTimeout; private ModuleName _target; private int _thicknessIndex; //private Hand _hand; //private bool _autoHand; private EfemModule _efemModule; public EfemMapRoutine(EfemModule efemModule) { Module = "EFEM"; Name = "Map"; _efemModule = efemModule; } public Result Start(params object[] objs) { _mapTimeout = SC.GetValue("EFEM.EfemRobot.MapTimeout"); Reset(); _thicknessIndex = 0; //if (ModuleHelper.IsLoadPort(_target)) //{ // LoadPortModule lp = Singleton.Instance.Modules[_target] as LoadPortModule; // _thicknessIndex = lp.LPDevice.GetThicknessIndex(); //} Notify($"Start map {_target}"); return Result.RUN; } public void Init(ModuleName source) { //_autoHand = true; _target = source; } public void Abort() { Notify($"Abort map {_target}"); } public Result Monitor() { try { CheckTargetEnableMap((int)RoutineStep.CheckTargetEnableMap, _target); Map((int)RoutineStep.Map, _target, _thicknessIndex, _mapTimeout); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify($"Complete map {_target}"); return Result.DONE; } public void CheckTargetEnableMap(int id, ModuleName target) { Tuple ret = Execute(id, () => { Notify($"Check {target} enable map"); if (!_efemModule.RobotDevice.IsReady()) { Stop($"Can not map {target}, EfemRobot is not ready"); return false; } if (!ModuleHelper.IsLoadPort(target) && !ModuleHelper.IsLoadLock(target)) { Stop($"Can not map {target}, only LP or Buf supported"); return false; } if (target == ModuleName.LLA && DEVICE.GetDevice($"System.SensorBufferABigWaferProtrusion").Value) { Stop($"Can not map {target}, SensorBufferABigWaferProtrusion is on"); return false; } if (target == ModuleName.LLB && DEVICE.GetDevice($"System.SensorBufferBBigWaferProtrusion").Value) { Stop($"Can not map {target}, SensorBufferBBigWaferProtrusion is on"); return false; } if (ModuleHelper.IsLoadPort(target)) { LoadPortModuleBase lp = EquipmentManager.Modules[target] as LoadPortModuleBase; if (!lp.CheckReadyForMap(ModuleName.EfemRobot, Hand.Blade1, out string reason)) { Stop(reason); return false; } } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } public void Map(int id, ModuleName target, int thicknessIndex, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Robot start map {target}"); string reason; if (!_efemModule.RobotDevice.Map(target, thicknessIndex, out reason)) { Stop(reason); return false; } return true; }, () => { if (_efemModule.RobotDevice.IsError) return null; if (_efemModule.RobotDevice.IsIdle) return true; return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { 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()); } } } }