AlignerHomeRoutine.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners;
  7. using MECF.Framework.RT.ModuleLibrary.AlignerModules;
  8. namespace FutureEfemLib.Aligners
  9. {
  10. class AlignerHomeRoutine : ModuleRoutine, IRoutine
  11. {
  12. enum RoutineStep
  13. {
  14. ClearError,
  15. Home,
  16. QueryStatus,
  17. }
  18. private int _timeout = 0;
  19. AlignerBase _aligner = null;
  20. public AlignerHomeRoutine(AlignerModuleBase module)
  21. {
  22. Module = module.Module;
  23. Name = "Home";
  24. }
  25. public bool Initalize()
  26. {
  27. return true;
  28. }
  29. public Result Start(params object[] objs)
  30. {
  31. Reset();
  32. _timeout = SC.GetValue<int>("EFEM.Aligner.HomeTimeout");
  33. _aligner = DEVICE.GetDevice<AlignerBase>($"{ModuleName.Aligner}.{ModuleName.Aligner}");
  34. Notify($"Start");
  35. return Result.RUN;
  36. }
  37. public Result Monitor()
  38. {
  39. try
  40. {
  41. //ClearError((int)RoutineStep.ClearError, _aligner, _timeout);
  42. Home((int)RoutineStep.Home, _aligner, _timeout);
  43. QueryStatus((int)RoutineStep.QueryStatus, _aligner, _timeout);
  44. }
  45. catch (RoutineBreakException)
  46. {
  47. return Result.RUN;
  48. }
  49. catch (RoutineFaildException)
  50. {
  51. return Result.FAIL;
  52. }
  53. Notify("Finished");
  54. return Result.DONE;
  55. }
  56. public void ClearError(int id, AlignerBase aligner, int timeout)
  57. {
  58. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  59. {
  60. Notify($"Clear error {aligner.Name}");
  61. //string reason;
  62. //if (!aligner.ClearError(out reason))
  63. //{
  64. // Stop(reason);
  65. // return false;
  66. //}
  67. return true;
  68. }, () =>
  69. {
  70. if (aligner.IsError)
  71. return null;
  72. if (aligner.IsBusy)
  73. return false;
  74. return true;
  75. }, timeout * 1000);
  76. if (ret.Item1)
  77. {
  78. if (ret.Item2 == Result.FAIL)
  79. {
  80. Stop(string.Format("failed."));
  81. throw (new RoutineFaildException());
  82. }
  83. else if (ret.Item2 == Result.TIMEOUT) //timeout
  84. {
  85. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  86. throw (new RoutineFaildException());
  87. }
  88. else
  89. throw (new RoutineBreakException());
  90. }
  91. }
  92. public void Home(int id, AlignerBase aligner, int timeout)
  93. {
  94. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  95. {
  96. Notify($"Start home {aligner.Name}");
  97. string reason;
  98. if (!aligner.Home(out reason))
  99. {
  100. Stop(reason);
  101. return false;
  102. }
  103. return true;
  104. }, () =>
  105. {
  106. if (aligner.IsError)
  107. return null;
  108. if (aligner.IsBusy)
  109. return false;
  110. return true;
  111. }, timeout * 1000);
  112. if (ret.Item1)
  113. {
  114. if (ret.Item2 == Result.FAIL)
  115. {
  116. Stop(string.Format("Home failed."));
  117. throw (new RoutineFaildException());
  118. }
  119. else if (ret.Item2 == Result.TIMEOUT) //timeout
  120. {
  121. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  122. throw (new RoutineFaildException());
  123. }
  124. else
  125. throw (new RoutineBreakException());
  126. }
  127. }
  128. public void QueryStatus(int id, AlignerBase aligner, int timeout)
  129. {
  130. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  131. {
  132. Notify($"Start query status {aligner.Name}");
  133. string reason;
  134. if (!aligner.QueryWaferPresence(out reason))
  135. {
  136. Stop(reason);
  137. return false;
  138. }
  139. return true;
  140. }, () =>
  141. {
  142. if (aligner.IsError)
  143. return null;
  144. if (aligner.IsBusy)
  145. return false;
  146. return true;
  147. }, timeout * 1000);
  148. if (ret.Item1)
  149. {
  150. if (ret.Item2 == Result.FAIL)
  151. {
  152. Stop(string.Format("Query status failed."));
  153. throw (new RoutineFaildException());
  154. }
  155. else if (ret.Item2 == Result.TIMEOUT) //timeout
  156. {
  157. Stop(string.Format("Query status timeout, can not complete in {0} seconds", timeout));
  158. throw (new RoutineFaildException());
  159. }
  160. else
  161. throw (new RoutineBreakException());
  162. }
  163. }
  164. public void Abort()
  165. {
  166. }
  167. }
  168. }