using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; namespace EFEM.RT.Routines.LP { internal class LoadFoupRoutine : CommonRoutine, IRoutine { public enum LoadFoup { LOAD, WaitLoad, GetMap, } public ModuleName Chamber { get; set; } private SCConfigItem _scLoadTimeout = null; private int _timeoutLoad = 0; LoadPortBaseDevice _device = null; public bool IsDeviceNull => _device == null; public LoadFoupRoutine(string module, string name) { _scLoadTimeout = SC.GetConfigItem("LoadPort.TimeLimitLoadportLoad"); } public bool Initalize() { IsStopped = true; return true; } public Result StartRoutine(ModuleName lp) { Chamber = lp; _timeoutLoad = _scLoadTimeout.IntValue; Reset(); _device = DEVICE.GetDevice(Chamber.ToString()); if (_device.DockState == FoupDockState.Docked) { EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, string.Format("{0} is load already, can't do again", Chamber.ToString())); return Result.FAIL; } string reason = string.Empty; if (SC.GetValue("System.LPRobotActionIntervene")) { if (!CheckLoadportMotionInterlock(Chamber, out reason)) { EV.PostMessage(Chamber.ToString(), EventEnum.LoadFOUPFailed, reason); return Result.FAIL; } } if (!_device.IsEnableLoad(out reason)) { EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, reason); return Result.FAIL; } EV.PostMessage(Chamber.ToString(), EventEnum.LoadFOUPStart, Chamber.ToString()); IsStopped = false; return Result.RUN; } public Result Start(params object[] objs) { _timeoutLoad = _scLoadTimeout.IntValue; Reset(); _device = DEVICE.GetDevice(Chamber.ToString()); if (_device.DockState == FoupDockState.Docked) { EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, string.Format("{0} is load already, can't do again", Chamber.ToString())); return Result.FAIL; } EV.PostMessage(Chamber.ToString(), EventEnum.LoadFOUPStart, Chamber.ToString()); IsStopped = false; return Result.RUN; } public Result Monitor() { if (IsStopped) return Result.DONE; try { MapLoadFoup((int)LoadFoup.LOAD, "Mapping&Load", _timeoutLoad, Notify, Stop); WaitLoadportMotion((int)LoadFoup.WaitLoad, _device, "Wait Load...", _timeoutLoad, Notify, Stop); // GetWaferMap((int)LoadFoup.GetMap, "Get Mapping", _timeoutLoad, Notify, Stop); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { IsStopped = true; return Result.FAIL; } IsStopped = true; EV.PostMessage(Chamber.ToString(), EventEnum.LoadFOUPEnd, Chamber.ToString()); return Result.DONE; } public new void Abort() { } protected void MapLoadFoup(int id, string name, int time, Action notify, Action error) { Tuple ret = Execute(id, () => { notify(String.Format("{0} Load", _device.Name)); string reason = string.Empty; return _device.Load(out reason); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("{0} timeout, than {1} seconds", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void GetWaferMap(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Query Mapping")); string reason = string.Empty; return _device.QueryWaferMap(out reason); }, () => { if (!_device.IsBusy) { return true; } return false; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("Query Mapping time out, using more than {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected override void Notify(string message) { EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Load Foup:{0}", message)); } /// /// prepare process failed /// /// /// protected override void Stop(string failReason) { string reason = String.Empty; EV.PostMessage(Module, EventEnum.LoadFOUPFailed, failReason); } } }