using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Log; 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; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK; namespace EFEM.RT.Routines.LP { internal class UnloadFoupRoutine : CommonRoutine, IRoutine { public enum UnloadFoupStep { UNLOAD, WaitUnload, UnladoLight, } public ModuleName Chamber { get; set; } private SCConfigItem _scLoadTimeout = null; private int _timeoutUnload = 0; LoadPortBaseDevice _device = null; public UnloadFoupRoutine() { Name = "Unload"; _scLoadTimeout = SC.GetConfigItem("LoadPort.TimeLimitLoadportUnload"); } public bool Initalize() { IsStopped = true; return true; } public Result Start(params object[] objs) { _timeoutUnload = _scLoadTimeout.IntValue; Reset(); _device = DEVICE.GetDevice(Chamber.ToString()); EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPStart, Chamber.ToString()); string reason = string.Empty; if (_device.DockState == FoupDockState.Undocked) { EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, string.Format("{0} is unload, can't do again", Chamber.ToString())); return Result.FAIL; } if (SC.GetValue("System.LPRobotActionIntervene")) { if(!CheckLoadportMotionInterlock(Chamber, out reason)) { EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPFailed, reason); return Result.FAIL; } } if (!_device.IsEnableUnload(out reason)) { EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, reason); return Result.FAIL; } IsStopped = false; return Result.RUN; } public Result Monitor() { if (IsStopped) return Result.DONE; try { Unload((int)UnloadFoupStep.UNLOAD, "Unload", _timeoutUnload, Notify, Stop); WaitLoadportMotion((int)UnloadFoupStep.WaitUnload, _device, "Wait Unload...", _timeoutUnload, Notify, Stop); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { IsStopped = true; return Result.FAIL; } IsStopped = true; EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPEnd, Chamber.ToString()); return Result.DONE; } public new void Abort() { } protected void Unload(int id, string name, int time, Action notify, Action error) { Tuple ret = Execute(id, () => { notify(String.Format("{0} Home", _device.Name)); string reason = string.Empty; return _device.Unload(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()); } } public void UnloadLight(int id, LoadPort device, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("{0} unload light", device.Name)); string reason = string.Empty; return device.SetIndicator(Indicator.UNLOAD, IndicatorState.OFF, out reason); }, () => { if (device.IsBusy == false) { 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("{0} timeout, than {1} seconds", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected override void Notify(string message) { EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Unload :{0}", message)); } /// /// prepare process failed /// /// /// protected override void Stop(string failReason) { string reason = String.Empty; EV.PostMessage(Module, EventEnum.UnloadFOUPFailed, failReason); } } }