LoadFoupRoutine.cs 6.3 KB

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