ReadWaferIDRoutine.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. namespace EFEM.RT.Routines.LP
  8. {
  9. internal class ReadWaferIDRoutine : CommonRoutine, IRoutine
  10. {
  11. enum Step
  12. {
  13. ReaderWaferID,
  14. Offline,
  15. LoadJob,
  16. Online,
  17. TryRead,
  18. }
  19. public string JobName { get; set; }
  20. private SCConfigItem _scReaderTimeout = null;
  21. //private int _timeoutAlign = 0;
  22. private int _timeoutReadID = 0;
  23. public ReadWaferIDRoutine(string module, string name)
  24. {
  25. }
  26. public bool Initalize()
  27. {
  28. _scReaderTimeout = SC.GetConfigItem("OcrReader.TimeLimitForWID");
  29. return true;
  30. }
  31. public int Notch { get; set; }
  32. public MoveOption Option { get; set; }
  33. public Result Start(params object[] objs)
  34. {
  35. _timeoutReadID = _scReaderTimeout.IntValue;
  36. Reset();
  37. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignBegins, string.Format("{0:D}",Notch));
  38. return Result.RUN;
  39. }
  40. public Result Monitor()
  41. {
  42. try
  43. {
  44. ReadWaferID((int)Step.ReaderWaferID, "Read wafer ID", _timeoutReadID, Notify, Stop);
  45. Offline((int)Step.Offline, "WIDReader Offline", _timeoutReadID, Notify, Stop);
  46. LoadJob((int)Step.LoadJob, "WIDReader Load option job", JobName, _timeoutReadID, Notify, Stop);
  47. Online((int)Step.Offline, "WIDReader Online", _timeoutReadID, Notify, Stop);
  48. ReadWaferID((int)Step.ReaderWaferID, "Read wafer ID", _timeoutReadID, Notify, Stop);
  49. }
  50. catch (RoutineBreakException)
  51. {
  52. return Result.RUN;
  53. }
  54. catch (RoutineFaildException)
  55. {
  56. return Result.FAIL;
  57. }
  58. if ((Option & MoveOption.ReadID) == MoveOption.ReadID)
  59. {
  60. // if (widreader.ReadOK)
  61. // WaferManager.Instance.UpdateWafer(UnitName.Aligner, 0, widreader.LaserMaker);
  62. }
  63. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignEnds);
  64. return Result.DONE;
  65. }
  66. public new void Abort()
  67. {
  68. }
  69. protected void ReadWaferID(int id, string name, int time, Action<string> notify, Action<string> error)
  70. {
  71. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  72. {
  73. notify(name);
  74. string reason = string.Empty;
  75. widreader.Read(out reason);
  76. return true;
  77. }, () =>
  78. {
  79. if (!widreader.Busy)
  80. {
  81. return true;
  82. }
  83. return false;
  84. }, time * 1000);
  85. if (ret.Item1)
  86. {
  87. if (ret.Item2 == Result.FAIL)
  88. {
  89. throw (new RoutineFaildException());
  90. }
  91. else if (ret.Item2 == Result.TIMEOUT) //timeout
  92. {
  93. error(String.Format("read wafer id timeout, than {0} seconds", time));
  94. throw (new RoutineFaildException());
  95. }
  96. else
  97. throw (new RoutineBreakException());
  98. }
  99. }
  100. protected void LoadJob(int id, string name, string jobName, int time, Action<string> notify, Action<string> error)
  101. {
  102. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  103. {
  104. notify(String.Format("Load Job"));
  105. string reason = string.Empty;
  106. widreader.LoadJob(jobName, out reason);
  107. return true;
  108. }, () =>
  109. {
  110. if (!widreader.Busy)
  111. {
  112. return true;
  113. }
  114. return false;
  115. }, time * 1000);
  116. if (ret.Item1)
  117. {
  118. if (ret.Item2 == Result.FAIL)
  119. {
  120. throw (new RoutineFaildException());
  121. }
  122. else if (ret.Item2 == Result.TIMEOUT) //timeout
  123. {
  124. error(String.Format("Load Job timeout, than {0} seconds", time));
  125. throw (new RoutineFaildException());
  126. }
  127. else
  128. throw (new RoutineBreakException());
  129. }
  130. }
  131. protected void Online(int id, string name, int time, Action<string> notify, Action<string> error)
  132. {
  133. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  134. {
  135. notify(String.Format("Online"));
  136. string reason = string.Empty;
  137. widreader.Online(true, out reason);
  138. return true;
  139. }, () =>
  140. {
  141. if (!widreader.Busy)
  142. {
  143. return true;
  144. }
  145. return false;
  146. }, time * 1000);
  147. if (ret.Item1)
  148. {
  149. if (ret.Item2 == Result.FAIL)
  150. {
  151. throw (new RoutineFaildException());
  152. }
  153. else if (ret.Item2 == Result.TIMEOUT) //timeout
  154. {
  155. error(String.Format("Online timeout, than {0} seconds", time));
  156. throw (new RoutineFaildException());
  157. }
  158. else
  159. throw (new RoutineBreakException());
  160. }
  161. }
  162. protected void Offline(int id, string name, int time, Action<string> notify, Action<string> error)
  163. {
  164. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  165. {
  166. notify(String.Format("Offline"));
  167. string reason = string.Empty;
  168. widreader.Online(false, out reason);
  169. return true;
  170. }, () =>
  171. {
  172. if (!widreader.Busy)
  173. {
  174. return true;
  175. }
  176. return false;
  177. }, time * 1000);
  178. if (ret.Item1)
  179. {
  180. if (ret.Item2 == Result.FAIL)
  181. {
  182. throw (new RoutineFaildException());
  183. }
  184. else if (ret.Item2 == Result.TIMEOUT) //timeout
  185. {
  186. error(String.Format("Offline timeout, than {0} seconds", time));
  187. throw (new RoutineFaildException());
  188. }
  189. else
  190. throw (new RoutineBreakException());
  191. }
  192. }
  193. protected override void Notify(string message)
  194. {
  195. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Read wafer ID:{0}", message));
  196. }
  197. /// <summary>
  198. /// prepare process failed
  199. /// </summary>
  200. /// <param name="failReason"></param>
  201. /// <param name="reactor"></param>
  202. protected override void Stop(string failReason)
  203. {
  204. string reason = String.Empty;
  205. EV.PostMessage(Module, EventEnum.AlignFailed, failReason);
  206. }
  207. }
  208. }