SwapRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. using System;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using EFEM.RT.Modules;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  13. using System.Security.Cryptography;
  14. namespace EFEM.RT.Routines
  15. {
  16. public class SwapRoutine : CommonRoutine, IRoutine
  17. {
  18. enum Swap
  19. {
  20. QueryState,
  21. CheckBeforeSwap,
  22. SwapWafer,
  23. WaitSwap,
  24. PickWafer,
  25. WaitPick,
  26. PlaceWafer,
  27. WaitPlace,
  28. CheckAfterSwap,
  29. CoolBufferMoveUP,
  30. WaitCoolBufferMoveUP,
  31. CoolBufferMoveDown,
  32. PostMessage,
  33. RobotBusytoSimifOn,
  34. RobotBusytoSimifOff,
  35. CheckBlade1WaferPrecense,
  36. CheckBlade2WaferPrecense,
  37. CheckBlade1WaferPrecenseAfterSwap,
  38. CheckBlade2WaferPrecenseAfterSwap,
  39. QuerySignalStatus,
  40. WaitCoolBufferMoveDown,
  41. PinDown
  42. }
  43. private SCConfigItem _scSwapTimeout = null;
  44. private int _timeout = 0;
  45. public SwapRoutine(string module, string name)
  46. {
  47. Module = module;
  48. Name = name;
  49. _scSwapTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitForPlaceWafer);
  50. }
  51. public bool Initalize()
  52. {
  53. IsStopped = true;
  54. return true;
  55. }
  56. public ModuleName Source { get; set; }
  57. public int Slot { get; set; }
  58. public Hand PlaceBlade { get; set; }
  59. public LoadPort _lpDevice;
  60. private int _offsetXPick;
  61. private int _offsetYPick;
  62. private int _offsetZPick;
  63. private int _offsetXPlace;
  64. private int _offsetYPlace;
  65. private int _offsetZPLace;
  66. private Hand _pickHand;
  67. private int _alignerdelay = 0;
  68. private int _coolingdelay = 0;
  69. private int delaytime = 0;
  70. public Result Start(params object[] objs)
  71. {
  72. IsStopped = false;
  73. Reset();
  74. _timeout = robot.RobotCommandTimeout; ;
  75. Reset();
  76. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("swap wafer {0}{1:D2} place blade {2} start", Source.ToString(), Slot + 1, PlaceBlade.ToString()));
  77. if (ModuleHelper.IsCoolingBuffer(Source))
  78. delaytime = _coolingdelay * 1000;
  79. else delaytime = _alignerdelay * 1000;
  80. _pickHand = Hand.Blade1;
  81. if (PlaceBlade == Hand.Blade1)
  82. _pickHand = Hand.Blade2;
  83. return Result.RUN;
  84. }
  85. public Result Monitor()
  86. {
  87. try
  88. {
  89. if (IsStopped) return Result.DONE;
  90. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  91. {
  92. var dev = GetCoolBuffer(Source);
  93. if (dev != null)
  94. {
  95. //QueryCoolBufferState((int)Pick.QueryState, GetCoolBuffer(Source));
  96. CoolBufferMoveUP((int)Swap.CoolBufferMoveUP, GetCoolBuffer(Source), WaferManager.Instance.GetWaferSize(Source, Slot), _timeout, Notify, Stop);
  97. WaitCoolBufferMoveUp((int)Swap.WaitCoolBufferMoveUP, GetCoolBuffer(Source), "Wait CoolingBuffer Move Up...", _timeout, Notify, Stop);
  98. }
  99. }
  100. //if (ModuleHelper.IsLoadLock(Source))
  101. //{
  102. // if (Source.Equals("LL1")) ll1.SafeytoPm(true);
  103. // else if (Source.Equals("LL2")) ll2.SafeytoPm(true);
  104. //}
  105. //RobotSignalStatus((int)Swap.QuerySignalStatus, robot, _timeout);
  106. CheckBladeWaferIsExist((int)Swap.CheckBlade1WaferPrecense, robot, Hand.Blade1, _timeout);
  107. CheckBladeWaferIsExist((int)Swap.CheckBlade2WaferPrecense, robot, Hand.Blade2, _timeout);
  108. CheckBeforeSwap((int)Swap.CheckBeforeSwap, "Check wafer information", Source, Slot, _pickHand, Notify, Stop);
  109. //if (ModuleHelper.IsLoadPort(Source))
  110. //{
  111. // RobotBusytoSimif((int)Swap.RobotBusytoSimifOn, Source, true, _timeout, Notify, Stop);
  112. //}
  113. //if (OffsetX == 0 && OffsetY == 0 && OffsetZ == 0)
  114. //{
  115. // PickWafer((int)Swap.PickWafer, "Pick wafer", Source, Slot, _pickHand, _offsetXPick, _offsetYPick, _offsetZPick, Notify, Stop);
  116. // this.WaitRobotMotion((int)Swap.WaitPick, robot, "Wait picked", _timeout, Notify, Stop);
  117. // PlaceWafer((int)Swap.PlaceWafer, "Place wafer", Source, Slot, PlaceBlade, _offsetXPlace, _offsetYPlace, _offsetZPLace, Notify, Stop);
  118. // this.WaitRobotMotion((int)Swap.WaitPlace, robot, "Wait Placed", _timeout, Notify, Stop);
  119. //}
  120. //else
  121. //{
  122. if (!ModuleHelper.IsLoadLock(Source))
  123. {
  124. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  125. {
  126. SwapWafer((int)Swap.SwapWafer, "Swap wafer", Source, Slot, _pickHand, OffsetX, OffsetY, OffsetZ, Notify, Stop);
  127. }
  128. else
  129. {
  130. PickWafer((int)Swap.PickWafer, "Pick wafer", Source, Slot, _pickHand, _offsetXPick, _offsetYPick, _offsetZPick, Notify, Stop);
  131. this.WaitRobotMotion((int)Swap.WaitPick, robot, "Wait picked", _timeout, Notify, Stop);
  132. PlaceWafer((int)Swap.PlaceWafer, "Place wafer", Source, Slot, PlaceBlade, _offsetXPlace, _offsetYPlace, _offsetZPLace, Notify, Stop);
  133. this.WaitRobotMotion((int)Swap.WaitPlace, robot, "Wait Placed", _timeout, Notify, Stop);
  134. }
  135. }
  136. //}
  137. this.WaitRobotMotion((int)Swap.WaitSwap, robot, "Wait swap finish", _timeout, Notify, Stop);
  138. //if (ModuleHelper.IsLoadPort(Source))
  139. //{
  140. // RobotBusytoSimif((int)Swap.RobotBusytoSimifOn, Source, true, _timeout, Notify, Stop);
  141. //}
  142. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  143. {
  144. var dev = GetCoolBuffer(Source);
  145. if (dev != null)
  146. {
  147. TimeDelay((int)Swap.PinDown, delaytime);
  148. CoolBufferMoveDown((int)Swap.CoolBufferMoveDown, GetCoolBuffer(Source), WaferManager.Instance.GetWaferSize(Source, Slot), _timeout, Notify, Stop);
  149. WaitCoolBufferMoveDown((int)Swap.WaitCoolBufferMoveDown, GetCoolBuffer(Source), "Wait CoolingBuffer Move Down...", _timeout, Notify, Stop);
  150. }
  151. }
  152. PostMessage((int)Swap.PostMessage, string.Format("Swap wafer {0}{1:D2} place blade {2}", Source.ToString(), Slot + 1, PlaceBlade.ToString()));
  153. CheckBladeWaferIsExist((int)Swap.CheckBlade1WaferPrecenseAfterSwap, robot, Hand.Blade1, _timeout);
  154. CheckBladeWaferIsExist((int)Swap.CheckBlade2WaferPrecenseAfterSwap, robot, Hand.Blade2, _timeout);
  155. CheckAfterSwap((int)Swap.CheckAfterSwap, "Check wafer information after swap", Source, Slot, PlaceBlade, Notify, Stop);
  156. }
  157. catch (RoutineBreakException)
  158. {
  159. return Result.RUN;
  160. }
  161. catch (RoutineFaildException)
  162. {
  163. IsStopped = true;
  164. return Result.FAIL;
  165. }
  166. IsStopped = true;
  167. return Result.DONE;
  168. }
  169. protected override void Notify(string message)
  170. {
  171. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Swap wafer:{0}", message));
  172. }
  173. /// <summary>
  174. /// prepare process failed
  175. /// </summary>
  176. /// <param name="failReason"></param>
  177. /// <param name="reactor"></param>
  178. protected override void Stop(string failReason)
  179. {
  180. string reason = String.Empty;
  181. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Swap wafer {0}{1:D2} with arm {2} failed, {3}", Source.ToString(), Slot + 1, PlaceBlade.ToString(), failReason));
  182. }
  183. private void SwapWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  184. Action<string> notify, Action<string> error)
  185. {
  186. Tuple<bool, Result> ret = Execute(id, () =>
  187. {
  188. notify(String.Format("Swap wafer {0}{1:D2}", chamber.ToString(), slot));
  189. string reason = string.Empty;
  190. if (x == 0 && y == 0 && z == 0)
  191. return robot.Swap((RobotArmEnum)blade,chamber.ToString(), slot);
  192. return robot.SwapEx((RobotArmEnum)blade, chamber.ToString(), slot, x, y, z,0);
  193. });
  194. if (ret.Item1)
  195. {
  196. if (ret.Item2 == Result.FAIL)
  197. {
  198. throw (new RoutineFaildException());
  199. }
  200. }
  201. }
  202. public void CheckBeforeSwap(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  203. {
  204. Tuple<bool, Result> ret = Execute(id, () =>
  205. {
  206. notify(String.Format("Check target {0}{1:D2} wafer information", chamber.ToString(), slot));
  207. string reason = string.Empty;
  208. if (!CheckRobotMotionInterlock(chamber, slot, out reason))
  209. {
  210. EV.PostMessage(ModuleName.System.ToString(), EventEnum.TransferPrepareFailed, String.Format("target {0}{1:D2},{2}", chamber.ToString(), slot + 1, reason));
  211. return false;
  212. }
  213. if (blade == Hand.Blade1)
  214. {
  215. bool bHasWafer = WaferManager.Instance.CheckWafer(chamber, slot, WaferStatus.Normal);
  216. if (!bHasWafer)
  217. {
  218. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferAbsentWithoutRecord, String.Format("target {0}{1:D2}", chamber.ToString(), slot + 1));
  219. return false;
  220. }
  221. bHasWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade1, WaferStatus.Normal);
  222. if (bHasWafer)
  223. {
  224. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  225. return false;
  226. }
  227. bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade1); //check sensor
  228. if (bHasWafer)
  229. {
  230. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  231. return false;
  232. }
  233. bool bNoWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade2, WaferStatus.Normal);
  234. if (!bNoWafer)
  235. {
  236. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  237. return false;
  238. }
  239. bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade2); //check sensor
  240. if (bNoWafer)
  241. {
  242. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  243. return false;
  244. }
  245. }
  246. else
  247. {
  248. bool bHasWafer = WaferManager.Instance.CheckWafer(chamber, slot, WaferStatus.Normal);
  249. if (!bHasWafer)
  250. {
  251. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferAbsentWithoutRecord, String.Format("target {0}{1:D2}", chamber.ToString(), slot + 1));
  252. return false;
  253. }
  254. bHasWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade2, WaferStatus.Normal);
  255. if (bHasWafer)
  256. {
  257. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  258. return false;
  259. }
  260. bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade2); //check sensor
  261. if (bHasWafer)
  262. {
  263. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  264. return false;
  265. }
  266. bool bNoWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade1, WaferStatus.Normal);
  267. if (!bNoWafer)
  268. {
  269. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  270. return false;
  271. }
  272. bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade1); //check sensor
  273. if (bNoWafer)
  274. {
  275. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  276. return false;
  277. }
  278. }
  279. return true;
  280. });
  281. if (ret.Item1)
  282. {
  283. if (ret.Item2 == Result.FAIL)
  284. {
  285. error(String.Format("Failed to swap, wafer information not correct."));
  286. throw (new RoutineFaildException());
  287. }
  288. }
  289. }
  290. public void CheckAfterSwap(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  291. {
  292. Tuple<bool, Result> ret = Execute(id, () =>
  293. {
  294. notify(name);
  295. if (blade == Hand.Blade1)
  296. {
  297. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade1);
  298. if (!bNoWafer)
  299. {
  300. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  301. return false;
  302. }
  303. bool bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade2);
  304. if (!bHasWafer)
  305. {
  306. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedAfterPick);
  307. return false;
  308. }
  309. }
  310. else
  311. {
  312. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade2);
  313. if (!bNoWafer)
  314. {
  315. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  316. return false;
  317. }
  318. bool bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade1);
  319. if (!bHasWafer)
  320. {
  321. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedAfterPick);
  322. return false;
  323. }
  324. }
  325. return true;
  326. });
  327. if (ret.Item1)
  328. {
  329. if (ret.Item2 == Result.FAIL)
  330. {
  331. error(String.Format("Failed to check information after swap."));
  332. throw (new RoutineFaildException());
  333. }
  334. }
  335. }
  336. }
  337. }