FIMSCycleTest.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using FurnaceRT.Equipments.Systems;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using System;
  9. namespace FurnaceRT.Equipments.FIMSs
  10. {
  11. public class FIMSCycleTest : ModuleRoutine, IRoutine
  12. {
  13. enum RoutineStep
  14. {
  15. Unload,
  16. Unload1,
  17. CheckUnloadFinish,
  18. CheckUnloadFinish1,
  19. Load,
  20. CheckLoadFinish,
  21. Loop,
  22. EndLoop,
  23. Delay1,
  24. Delay2,
  25. Delay3,
  26. Delay4,
  27. }
  28. private int _timeout;
  29. private FIMSModule _fimsModule;
  30. private int _count;
  31. public FIMSCycleTest(FIMSModule fimsModule)
  32. {
  33. Module = fimsModule.Module.ToString();
  34. _fimsModule = fimsModule;
  35. Name = "Cycle";
  36. }
  37. public Result Start(params object[] objs)
  38. {
  39. Reset();
  40. _timeout = SC.GetValue<int>($"FIMS.{Module}.MotionTimeout");
  41. if (!Singleton<EquipmentManager>.Instance.IsAutoMode && !Singleton<EquipmentManager>.Instance.IsReturnWafer)
  42. {
  43. if (!_fimsModule.SensorWaferRobotEX1AxisHomePosition.Value)
  44. {
  45. _fimsModule.UnloadFailAlarm.Set($"wafer robot EX1 axis not at home position");
  46. return Result.FAIL;
  47. }
  48. if (!_fimsModule.SensorWaferRobotEX2AxisHomePosition.Value)
  49. {
  50. _fimsModule.UnloadFailAlarm.Set($"wafer robot EX2 axis not at home position");
  51. return Result.FAIL;
  52. }
  53. }
  54. _count = SC.GetValue<int>($"FIMS.{Module}.CycleCount");
  55. Notify($"{_fimsModule.Name} {Name} start");
  56. _fimsModule.FIMSDevice.IsLoadCompleted = false;
  57. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  58. return Result.RUN;
  59. }
  60. public override Result Monitor()
  61. {
  62. try
  63. {
  64. PauseRountine(_fimsModule.FIMSDevice.IsPause);
  65. if (_fimsModule.FIMSDevice.IsPause)
  66. return Result.RUN;
  67. Loop((int)RoutineStep.Loop, _count);
  68. Unload((int)RoutineStep.Unload, _timeout);
  69. Delay((int)RoutineStep.Delay1, 2);
  70. CheckUnloadFinish((int)RoutineStep.CheckUnloadFinish, _timeout);
  71. Delay((int)RoutineStep.Delay2, 2);
  72. Load((int)RoutineStep.Load, _timeout);
  73. Delay((int)RoutineStep.Delay2, 2);
  74. CheckLoadFinish((int)RoutineStep.CheckLoadFinish, _timeout);
  75. Delay((int)RoutineStep.Delay3, 2);
  76. EndLoop((int)RoutineStep.EndLoop);
  77. Unload((int)RoutineStep.Unload1, _timeout);
  78. Delay((int)RoutineStep.Delay4, 2);
  79. CheckUnloadFinish((int)RoutineStep.CheckUnloadFinish1, _timeout);
  80. }
  81. catch (RoutineBreakException)
  82. {
  83. return Result.RUN;
  84. }
  85. catch (RoutineFaildException ex)
  86. {
  87. return Result.FAIL;
  88. }
  89. Notify("Finished");
  90. return Result.DONE;
  91. }
  92. public void Abort()
  93. {
  94. _fimsModule.Stop();
  95. }
  96. private void Load(int id, int timeout)
  97. {
  98. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  99. {
  100. Notify($"{Module} load");
  101. if (!_fimsModule.FIMSDevice.Load(out string reason))
  102. {
  103. Stop(reason);
  104. return false;
  105. }
  106. return true;
  107. }, () =>
  108. {
  109. return true;
  110. }, timeout * 1000);
  111. if (ret.Item1)
  112. {
  113. if (ret.Item2 == Result.FAIL)
  114. {
  115. throw (new RoutineFaildException());
  116. }
  117. else if (ret.Item2 == Result.TIMEOUT) //timeout
  118. {
  119. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  120. throw (new RoutineFaildException());
  121. }
  122. else
  123. throw (new RoutineBreakException());
  124. }
  125. }
  126. private void CheckLoadFinish(int id, int timeout)
  127. {
  128. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  129. {
  130. Notify($"Check {Module} load finish");
  131. return true;
  132. }, () =>
  133. {
  134. return _fimsModule.FIMSDevice.IsPLCLoadCompleted && !_fimsModule.FIMSDevice.IsRunning;
  135. }, timeout * 1000);
  136. if (ret.Item1)
  137. {
  138. if (ret.Item2 == Result.FAIL)
  139. {
  140. throw (new RoutineFaildException());
  141. }
  142. else if (ret.Item2 == Result.TIMEOUT) //timeout
  143. {
  144. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  145. throw (new RoutineFaildException());
  146. }
  147. else
  148. throw (new RoutineBreakException());
  149. }
  150. }
  151. private void Unload(int id, int timeout)
  152. {
  153. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  154. {
  155. Notify($"{Module} unload");
  156. if (!_fimsModule.FIMSDevice.Unload(out string reason))
  157. {
  158. Stop(reason);
  159. return false;
  160. }
  161. return true;
  162. }, () =>
  163. {
  164. return true;
  165. }, timeout * 1000);
  166. if (ret.Item1)
  167. {
  168. if (ret.Item2 == Result.FAIL)
  169. {
  170. throw (new RoutineFaildException());
  171. }
  172. else if (ret.Item2 == Result.TIMEOUT) //timeout
  173. {
  174. _fimsModule.UnloadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  175. throw (new RoutineFaildException());
  176. }
  177. else
  178. throw (new RoutineBreakException());
  179. }
  180. }
  181. private void CheckUnloadFinish(int id, int timeout)
  182. {
  183. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  184. {
  185. Notify($"Check {Module} unload finish");
  186. return true;
  187. }, () =>
  188. {
  189. return _fimsModule.FIMSDevice.IsPLCUnloadCompleted && !_fimsModule.FIMSDevice.IsRunning;
  190. }, timeout * 1000);
  191. if (ret.Item1)
  192. {
  193. if (ret.Item2 == Result.FAIL)
  194. {
  195. throw (new RoutineFaildException());
  196. }
  197. else if (ret.Item2 == Result.TIMEOUT) //timeout
  198. {
  199. _fimsModule.UnloadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  200. throw (new RoutineFaildException());
  201. }
  202. else
  203. throw (new RoutineBreakException());
  204. }
  205. }
  206. }
  207. }