WaferMappingRoutine.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. 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. 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. }
  79. //if (_lp != null)
  80. //{
  81. // var _lpOpen = _lp as OpenStageWithWaferSizeLoadPort;
  82. // _waferSize = _lpOpen.WaferSize;
  83. //}
  84. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Wafer Mapping {0} start.", Source.ToString()));
  85. return Result.RUN;
  86. }
  87. public Result Monitor()
  88. {
  89. try
  90. { if(ModuleHelper.IsLoadPort(Source))
  91. CheckLoadPortReady((int)Mapping.CheckLoadPortReadyMap, _lp);
  92. if(DeviceDefineManager.Instance.GetValue<bool>("WAFSHEnable") == false)
  93. {
  94. CheckRobotReady((int)Mapping.CheckRobotReadyMap);
  95. //QueryRbParameterAndCompare0114((int)Mapping.QueryRobotParameter, "Query Robot parameters", 0114, "URS", _waferSize,_timeout, Notify, Stop);
  96. MapWafer((int)Mapping.MapWafer);
  97. WaitRobotMotion((int)Mapping.WaitMapping, robot, "Wait robot motion finish", _timeout, Notify, Stop);
  98. GetWaferMap((int)Mapping.GetWaferMap, "Get wafer Mapping", Source, _timeout, Notify, Stop);
  99. }
  100. else
  101. {
  102. GetWaferMap((int)Mapping.GetWaferMap, _lp, _timeout);
  103. }
  104. }
  105. catch (RoutineBreakException)
  106. {
  107. return Result.RUN;
  108. }
  109. catch (RoutineFaildException)
  110. {
  111. return Result.FAIL;
  112. }
  113. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Wafer mapping {0} end.", Source.ToString()));
  114. return Result.DONE;
  115. }
  116. public void CheckLoadPortReady(int id, LoadPortBaseDevice device)
  117. {
  118. Tuple<bool, Result> ret = Check(id, () =>
  119. {
  120. Notify(String.Format("{0} check enable transfer", device.Name));
  121. string reason = null;
  122. bool IsEnableMap = device.IsEnableMapWafer(out reason);
  123. if(!IsEnableMap)
  124. {
  125. EV.PostWarningLog(device.Name,$"{device.Name} can not maping,LP is not ready,{reason}. ");
  126. }
  127. return IsEnableMap;
  128. } );
  129. if (ret.Item1)
  130. {
  131. if (ret.Item2 == Result.FAIL)
  132. {
  133. Stop("Load Port not ready to map wafer");
  134. throw (new RoutineFaildException());
  135. }
  136. else
  137. throw (new RoutineBreakException());
  138. }
  139. }
  140. public void CheckRobotReady(int id )
  141. {
  142. string reason=string.Empty;
  143. Tuple<bool, Result> ret = Check(id, () =>
  144. {
  145. Notify(String.Format("check robot ready map" ));
  146. return CheckRobotMotionInterlock(out reason) ;
  147. });
  148. if (ret.Item1)
  149. {
  150. if (ret.Item2 == Result.FAIL)
  151. {
  152. Stop(reason);
  153. throw (new RoutineFaildException());
  154. }
  155. else
  156. throw (new RoutineBreakException());
  157. }
  158. }
  159. protected override void Notify(string message)
  160. {
  161. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Wafer mapping:{0}", message));
  162. }
  163. /// <summary>
  164. /// prepare process failed
  165. /// </summary>
  166. /// <param name="failReason"></param>
  167. /// <param name="reactor"></param>
  168. protected override void Stop(string failReason)
  169. {
  170. string reason = String.Empty;
  171. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, string.Format("Wafer mapping {0} stopped, {1}", Source.ToString(), failReason));
  172. }
  173. public void MapWafer(int id )
  174. {
  175. string reason = string.Empty;
  176. Tuple<bool, Result> ret = Execute(id, () =>
  177. {
  178. Notify(String.Format("Wafer Mapping for {0}", Source));
  179. return robot.WaferMapping(Source, out reason);
  180. });
  181. if (ret.Item1)
  182. {
  183. if (ret.Item2 == Result.FAIL)
  184. {
  185. Stop(reason);
  186. throw (new RoutineFaildException());
  187. }
  188. }
  189. }
  190. protected void GetWaferMap(int id, LoadPortBaseDevice device, int time)
  191. {
  192. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  193. {
  194. Notify(String.Format("Query Mapping"));
  195. string reason = string.Empty;
  196. return device.QueryWaferMap(out reason);
  197. }, () =>
  198. {
  199. if (!device.IsBusy)
  200. {
  201. return true;
  202. }
  203. return false;
  204. }, time * 1000);
  205. if (ret.Item1)
  206. {
  207. if (ret.Item2 == Result.FAIL)
  208. {
  209. throw (new RoutineFaildException());
  210. }
  211. else if (ret.Item2 == Result.TIMEOUT) //timeout
  212. {
  213. Stop(String.Format("Query Mapping time out, using more than {0} seconds", time));
  214. throw (new RoutineFaildException());
  215. }
  216. else
  217. throw (new RoutineBreakException());
  218. }
  219. }
  220. protected void GetWaferMap(int id, string name, ModuleName chamber, int time, Action<string> notify, Action<string> error)
  221. {
  222. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  223. {
  224. notify(String.Format("Query Mapping"));
  225. string reason = string.Empty;
  226. return robot.QueryWaferMap(chamber, out reason);
  227. }, () =>
  228. {
  229. if (robot.RobotState == RobotStateEnum.Idle)
  230. {
  231. return true;
  232. }
  233. return false;
  234. }, time * 1000);
  235. if (ret.Item1)
  236. {
  237. if (ret.Item2 == Result.FAIL)
  238. {
  239. throw (new RoutineFaildException());
  240. }
  241. else if (ret.Item2 == Result.TIMEOUT) //timeout
  242. {
  243. error(String.Format("Query Mapping time out, using more than {0} seconds", time));
  244. throw (new RoutineFaildException());
  245. }
  246. else
  247. throw (new RoutineBreakException());
  248. }
  249. }
  250. }
  251. }