UnloadFoupRoutine.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
  12. namespace EFEM.RT.Routines.LP
  13. {
  14. internal class UnloadFoupRoutine : CommonRoutine, IRoutine
  15. {
  16. public enum UnloadFoupStep
  17. {
  18. UNLOAD,
  19. WaitUnload,
  20. UnladoLight,
  21. }
  22. public ModuleName Chamber { get; set; }
  23. private SCConfigItem _scLoadTimeout = null;
  24. private int _timeoutUnload = 0;
  25. LoadPortBaseDevice _device = null;
  26. public UnloadFoupRoutine()
  27. {
  28. Name = "Unload";
  29. _scLoadTimeout = SC.GetConfigItem("LoadPort.TimeLimitLoadportUnload");
  30. }
  31. public bool Initalize()
  32. {
  33. IsStopped = true;
  34. return true;
  35. }
  36. public Result Start(params object[] objs)
  37. {
  38. _timeoutUnload = _scLoadTimeout.IntValue;
  39. Reset();
  40. _device = DEVICE.GetDevice<LoadPortBaseDevice>(Chamber.ToString());
  41. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPStart, Chamber.ToString());
  42. string reason = string.Empty;
  43. if (_device.DockState == FoupDockState.Undocked)
  44. {
  45. EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, string.Format("{0} is unload, can't do again", Chamber.ToString()));
  46. return Result.FAIL;
  47. }
  48. if (SC.GetValue<bool>("System.LPRobotActionIntervene"))
  49. {
  50. if(!CheckLoadportMotionInterlock(Chamber, out reason))
  51. {
  52. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPFailed, reason);
  53. return Result.FAIL;
  54. }
  55. }
  56. if (!_device.IsEnableUnload(out reason))
  57. {
  58. EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, reason);
  59. return Result.FAIL;
  60. }
  61. IsStopped = false;
  62. return Result.RUN;
  63. }
  64. public Result Monitor()
  65. {
  66. if (IsStopped) return Result.DONE;
  67. try
  68. {
  69. Unload((int)UnloadFoupStep.UNLOAD, "Unload", _timeoutUnload, Notify, Stop);
  70. WaitLoadportMotion((int)UnloadFoupStep.WaitUnload, _device, "Wait Unload...", _timeoutUnload, Notify, Stop);
  71. }
  72. catch (RoutineBreakException)
  73. {
  74. return Result.RUN;
  75. }
  76. catch (RoutineFaildException)
  77. {
  78. IsStopped = true;
  79. return Result.FAIL;
  80. }
  81. IsStopped = true;
  82. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPEnd, Chamber.ToString());
  83. return Result.DONE;
  84. }
  85. public new void Abort()
  86. {
  87. }
  88. protected void Unload(int id, string name, int time, Action<string> notify, Action<string> error)
  89. {
  90. Tuple<bool, Result> ret = Execute(id, () =>
  91. {
  92. notify(String.Format("{0} Home", _device.Name));
  93. string reason = string.Empty;
  94. return _device.Unload(out reason);
  95. });
  96. if (ret.Item1)
  97. {
  98. if (ret.Item2 == Result.FAIL)
  99. {
  100. throw (new RoutineFaildException());
  101. }
  102. else if (ret.Item2 == Result.TIMEOUT) //timeout
  103. {
  104. error(String.Format("{0} timeout, than {1} seconds", name, time));
  105. throw (new RoutineFaildException());
  106. }
  107. else
  108. throw (new RoutineBreakException());
  109. }
  110. }
  111. public void UnloadLight(int id, LoadPort device, string name, int time, Action<string> notify, Action<string> error)
  112. {
  113. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  114. {
  115. notify(String.Format("{0} unload light", device.Name));
  116. string reason = string.Empty;
  117. return device.SetIndicator(Indicator.UNLOAD, IndicatorState.OFF, out reason);
  118. }, () =>
  119. {
  120. if (device.IsBusy == false)
  121. {
  122. return true;
  123. }
  124. return false;
  125. }, time * 1000);
  126. if (ret.Item1)
  127. {
  128. if (ret.Item2 == Result.FAIL)
  129. {
  130. throw (new RoutineFaildException());
  131. }
  132. else if (ret.Item2 == Result.TIMEOUT) //timeout
  133. {
  134. error(String.Format("{0} timeout, than {1} seconds", name, time));
  135. throw (new RoutineFaildException());
  136. }
  137. else
  138. throw (new RoutineBreakException());
  139. }
  140. }
  141. protected override void Notify(string message)
  142. {
  143. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Unload :{0}", message));
  144. }
  145. /// <summary>
  146. /// prepare process failed
  147. /// </summary>
  148. /// <param name="failReason"></param>
  149. /// <param name="reactor"></param>
  150. protected override void Stop(string failReason)
  151. {
  152. string reason = String.Empty;
  153. EV.PostMessage(Module, EventEnum.UnloadFOUPFailed, failReason);
  154. }
  155. }
  156. }