FIMSLoadRoutine.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 Caliburn.Micro.Core;
  6. using FurnaceRT.Equipments.PMs;
  7. using FurnaceRT.Equipments.Systems;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using System;
  11. namespace FurnaceRT.Equipments.FIMSs
  12. {
  13. public class FIMSLoadRoutine : ModuleRoutine, IRoutine
  14. {
  15. enum RoutineStep
  16. {
  17. Load,
  18. Delay,
  19. CheckLoadFinish,
  20. }
  21. private int _timeout;
  22. private FIMSModule _fimsModule;
  23. private PMModule _pmModule;
  24. private bool _isNeedN2Purge;
  25. public FIMSLoadRoutine(FIMSModule fimsModule)
  26. {
  27. Module = fimsModule.Module.ToString();
  28. _fimsModule = fimsModule;
  29. Name = "Load";
  30. _pmModule = Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule;
  31. }
  32. public Result Init(bool isNeedN2Purge)
  33. {
  34. _isNeedN2Purge = isNeedN2Purge;
  35. return Result.DONE;
  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.LoadFailAlarm.Set($"wafer robot EX1 axis not at home position");
  46. return Result.FAIL;
  47. }
  48. if (!_fimsModule.SensorWaferRobotEX2AxisHomePosition.Value)
  49. {
  50. _fimsModule.LoadFailAlarm.Set($"wafer robot EX2 axis not at home position");
  51. return Result.FAIL;
  52. }
  53. }
  54. if (_isNeedN2Purge)
  55. {
  56. if (SC.ContainsItem("System.FIMSManualCheck") && SC.GetValue<bool>("System.FIMSManualCheck") )
  57. {
  58. if (!(Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule).FIMSLoadCheckLAO2(out string reason))
  59. {
  60. _fimsModule.LoadFailAlarm.Set(reason);
  61. return Result.FAIL;
  62. }
  63. }
  64. _pmModule?.SetN2PurgeParameters();
  65. }
  66. if (_fimsModule.FIMSDevice.IsLoadCompleted)
  67. {
  68. EV.PostInfoLog(Module, $"{Module} already at load position");
  69. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  70. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  71. return Result.DONE;
  72. }
  73. _pmModule?.SetN2PurgeProcess(_isNeedN2Purge);
  74. if (SC.ContainsItem("PM1.N2Purge.FOUPOpenerStableWaitTime"))
  75. {
  76. _timeout = (int)SC.GetValue<double>("PM1.N2Purge.FOUPOpenerStableWaitTime");
  77. }
  78. _fimsModule.FIMSDevice.IsLoadCompleted = false;
  79. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  80. Notify($"{_fimsModule.Name} {Name} start");
  81. return Result.RUN;
  82. }
  83. public override Result Monitor()
  84. {
  85. try
  86. {
  87. PauseRountine(_fimsModule.FIMSDevice.IsPause);
  88. if (_fimsModule.FIMSDevice.IsPause)
  89. return Result.RUN;
  90. Load((int)RoutineStep.Load, _timeout);
  91. Delay((int)RoutineStep.Delay, 3);
  92. CheckLoadFinish((int)RoutineStep.CheckLoadFinish, _timeout);
  93. }
  94. catch (RoutineBreakException)
  95. {
  96. return Result.RUN;
  97. }
  98. catch (RoutineFaildException)
  99. {
  100. _fimsModule.Stop();
  101. return Result.FAIL;
  102. }
  103. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  104. _fimsModule.Stop();
  105. Notify($"{_fimsModule.Name} {Name} finished");
  106. return Result.DONE;
  107. }
  108. public void Abort()
  109. {
  110. _fimsModule.Stop();
  111. }
  112. private void Load(int id, int timeout)
  113. {
  114. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  115. {
  116. Notify($"{Module} load");
  117. if (!_fimsModule.FIMSDevice.Load(out string reason))
  118. {
  119. Stop(reason);
  120. return false;
  121. }
  122. return true;
  123. }, () =>
  124. {
  125. return true;
  126. }, timeout * 1000);
  127. if (ret.Item1)
  128. {
  129. if (ret.Item2 == Result.FAIL)
  130. {
  131. throw (new RoutineFaildException());
  132. }
  133. else if (ret.Item2 == Result.TIMEOUT) //timeout
  134. {
  135. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  136. throw (new RoutineFaildException());
  137. }
  138. else
  139. throw (new RoutineBreakException());
  140. }
  141. }
  142. private void CheckLoadFinish(int id, int timeout)
  143. {
  144. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  145. {
  146. Notify($"Check {Module} load finish");
  147. return true;
  148. }, () =>
  149. {
  150. if (_fimsModule.FIMSDevice.IsPLCLoadCompleted && !_fimsModule.FIMSDevice.IsRunning)
  151. {
  152. if (_fimsModule.IsWaferOnRobot)
  153. {
  154. _fimsModule.LoadFailAlarm.Set($"The wafer on {Module} has shifted");
  155. _pmModule?.SetN2PurgeProcess(false);
  156. return false;
  157. }
  158. return true;
  159. }
  160. return false;
  161. }, timeout * 1000);
  162. if (ret.Item1)
  163. {
  164. if (ret.Item2 == Result.FAIL)
  165. {
  166. throw (new RoutineFaildException());
  167. }
  168. else if (ret.Item2 == Result.TIMEOUT) //timeout
  169. {
  170. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  171. throw (new RoutineFaildException());
  172. }
  173. else
  174. throw (new RoutineBreakException());
  175. }
  176. }
  177. }
  178. }