WaferMappingRoutine.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using System;
  2. using System.Runtime.Remoting.Messaging;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using EFEM.RT.Devices.LoadPorts.JetOpenCst;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  15. namespace EFEM.RT.Routines
  16. {
  17. public class WaferMappingRoutine : CommonRoutine, IRoutine
  18. {
  19. private enum Mapping
  20. {
  21. CheckLoadPortReadyMap,
  22. CheckRobotMapInterlock,
  23. CheckRobotReadyMap,
  24. QueryRobotParameter,
  25. RobotServoOff,
  26. WaitRobotServoOff,
  27. SetWaferSizeParameter0000,
  28. SetWaferSizeParameter0114,
  29. RobotServoOn,
  30. WaitRobotServoOn,
  31. MapWafer,
  32. WaitMapping,
  33. GetWaferMap,
  34. }
  35. private bool MultiWaferSize = DeviceDefineManager.Instance.GetValue<bool>("MultiWaferSize") ?? false;
  36. private SCConfigItem _scPickTimeout = null;
  37. private int _timeout = 0;
  38. private LoadPortBaseDevice _lp;
  39. public bool IsDeviceNull => _lp == null;
  40. public WaferMappingRoutine()
  41. {
  42. Name = "Wafer Mapping";
  43. _scPickTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitForPickWafer);
  44. }
  45. public bool Initalize()
  46. {
  47. return true;
  48. }
  49. public ModuleName Source { get; set; }
  50. private WaferSize _waferSize;
  51. public Result Start(params object[] objs)
  52. {
  53. Reset();
  54. _timeout = SC.GetValue<int>(SorterCommon.ScPathName.Robot_TimeLimitForPickWafer);
  55. Name = "Wafer Mapping";
  56. Reset();
  57. NeedSetParameter = true;
  58. string module = (string)objs[0];
  59. ModuleName source;
  60. if (string.IsNullOrEmpty(module) || !Enum.TryParse(module, out source))
  61. {
  62. LOG.Write("Start map wafer argument is not valid");
  63. return Result.FAIL;
  64. }
  65. Source = source;
  66. if (ModuleHelper.IsLoadPort(Source))
  67. {
  68. if (SC.GetValue<int>($"LoadPort.{Source}.CstType") == 0)
  69. {
  70. _lp = DEVICE.GetDevice<LoadPortBaseDevice>(Source.ToString());
  71. _waferSize = _lp.GetCurrentWaferSize();
  72. }
  73. else if (SC.GetValue<int>($"LoadPort.{Source}.CstType") == 1)
  74. {
  75. _lp = DEVICE.GetDevice<OpenStageJet>(Source.ToString());
  76. _waferSize = _lp.GetCurrentWaferSize();
  77. }
  78. else if (SC.GetValue<int>($"LoadPort.{Source}.CstType") == 2)
  79. {
  80. _lp = DEVICE.GetDevice<LoadPortBaseDevice>(Source.ToString());
  81. _waferSize = _lp.GetCurrentWaferSize();
  82. }
  83. }
  84. //if (_lp != null)
  85. //{
  86. // var _lpOpen = _lp as OpenStageWithWaferSizeLoadPort;
  87. // _waferSize = _lpOpen.WaferSize;
  88. //}
  89. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Wafer Mapping {0} start.", Source.ToString()));
  90. return Result.RUN;
  91. }
  92. public Result Monitor()
  93. {
  94. try
  95. {
  96. if (ModuleHelper.IsLoadPort(Source))
  97. CheckLoadPortReady((int)Mapping.CheckLoadPortReadyMap, _lp);
  98. if (DeviceDefineManager.Instance.GetValue<bool>("WAFSHEnable") == false)
  99. {
  100. CheckRobotReady((int)Mapping.CheckRobotReadyMap);
  101. //QueryRbParameterAndCompare0114((int)Mapping.QueryRobotParameter, "Query Robot parameters", 0114, "URS", _waferSize,_timeout, Notify, Stop);
  102. MapWafer((int)Mapping.MapWafer);
  103. WaitRobotMotion((int)Mapping.WaitMapping, robot, "Wait robot motion finish", _timeout, Notify, Stop);
  104. GetWaferMap((int)Mapping.GetWaferMap, "Get wafer Mapping", Source, _timeout, Notify, Stop);
  105. }
  106. else
  107. {
  108. GetWaferMap((int)Mapping.GetWaferMap, _lp, _timeout);
  109. }
  110. }
  111. catch (RoutineBreakException)
  112. {
  113. return Result.RUN;
  114. }
  115. catch (RoutineFaildException)
  116. {
  117. return Result.FAIL;
  118. }
  119. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Wafer mapping {0} end.", Source.ToString()));
  120. return Result.DONE;
  121. }
  122. public void CheckLoadPortReady(int id, LoadPortBaseDevice device)
  123. {
  124. Tuple<bool, Result> ret = Check(id, () =>
  125. {
  126. Notify(String.Format("{0} check enable transfer", device.Name));
  127. string reason = null;
  128. bool IsEnableMap = device.IsEnableMapWafer(out reason);
  129. if (!IsEnableMap)
  130. {
  131. EV.PostWarningLog(device.Name, $"{device.Name} can not maping,LP is not ready,{reason}. ");
  132. }
  133. return IsEnableMap;
  134. });
  135. if (ret.Item1)
  136. {
  137. if (ret.Item2 == Result.FAIL)
  138. {
  139. Stop("Load Port not ready to map wafer");
  140. throw (new RoutineFaildException());
  141. }
  142. else
  143. throw (new RoutineBreakException());
  144. }
  145. }
  146. public void CheckRobotReady(int id)
  147. {
  148. string reason = string.Empty;
  149. Tuple<bool, Result> ret = Check(id, () =>
  150. {
  151. Notify(String.Format("check robot ready map"));
  152. return CheckRobotMotionInterlock(out reason);
  153. });
  154. if (ret.Item1)
  155. {
  156. if (ret.Item2 == Result.FAIL)
  157. {
  158. Stop(reason);
  159. throw (new RoutineFaildException());
  160. }
  161. else
  162. throw (new RoutineBreakException());
  163. }
  164. }
  165. protected override void Notify(string message)
  166. {
  167. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Wafer mapping:{0}", message));
  168. }
  169. /// <summary>
  170. /// prepare process failed
  171. /// </summary>
  172. /// <param name="failReason"></param>
  173. /// <param name="reactor"></param>
  174. protected override void Stop(string failReason)
  175. {
  176. string reason = String.Empty;
  177. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, string.Format("Wafer mapping {0} stopped, {1}", Source.ToString(), failReason));
  178. }
  179. public void MapWafer(int id)
  180. {
  181. string reason = string.Empty;
  182. Tuple<bool, Result> ret = Execute(id, () =>
  183. {
  184. Notify(String.Format("Wafer Mapping for {0}", Source));
  185. return robot.WaferMapping(Source, out reason);
  186. });
  187. if (ret.Item1)
  188. {
  189. if (ret.Item2 == Result.FAIL)
  190. {
  191. Stop(reason);
  192. throw (new RoutineFaildException());
  193. }
  194. }
  195. }
  196. protected void GetWaferMap(int id, LoadPortBaseDevice device, int time)
  197. {
  198. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  199. {
  200. Notify(String.Format("Query Mapping"));
  201. string reason = string.Empty;
  202. return device.QueryWaferMap(out reason);
  203. }, () =>
  204. {
  205. if (!device.IsBusy)
  206. {
  207. return true;
  208. }
  209. return false;
  210. }, time * 1000);
  211. if (ret.Item1)
  212. {
  213. if (ret.Item2 == Result.FAIL)
  214. {
  215. throw (new RoutineFaildException());
  216. }
  217. else if (ret.Item2 == Result.TIMEOUT) //timeout
  218. {
  219. Stop(String.Format("Query Mapping time out, using more than {0} seconds", time));
  220. throw (new RoutineFaildException());
  221. }
  222. else
  223. throw (new RoutineBreakException());
  224. }
  225. }
  226. protected void GetWaferMap(int id, string name, ModuleName chamber, int time, Action<string> notify, Action<string> error)
  227. {
  228. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  229. {
  230. notify(String.Format("Query Mapping"));
  231. string reason = string.Empty;
  232. return robot.QueryWaferMap(chamber, out reason);
  233. }, () =>
  234. {
  235. if (robot.RobotState == RobotStateEnum.Idle)
  236. {
  237. return true;
  238. }
  239. return false;
  240. }, time * 1000);
  241. if (ret.Item1)
  242. {
  243. if (ret.Item2 == Result.FAIL)
  244. {
  245. throw (new RoutineFaildException());
  246. }
  247. else if (ret.Item2 == Result.TIMEOUT) //timeout
  248. {
  249. error(String.Format("Query Mapping time out, using more than {0} seconds", time));
  250. throw (new RoutineFaildException());
  251. }
  252. else
  253. throw (new RoutineBreakException());
  254. }
  255. }
  256. }
  257. }