FIMSLoadRoutine.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 (!(Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule).FIMSLoadCheckLAO2(out string reason))
  57. {
  58. _fimsModule.LoadFailAlarm.Set(reason);
  59. return Result.FAIL;
  60. }
  61. _pmModule?.SetN2PurgeParameters();
  62. }
  63. if (_fimsModule.FIMSDevice.IsLoadCompleted)
  64. {
  65. EV.PostInfoLog(Module, $"{Module} already at load position");
  66. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  67. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  68. return Result.DONE;
  69. }
  70. _pmModule?.SetN2PurgeProcess(_isNeedN2Purge);
  71. if (SC.ContainsItem("PM1.N2Purge.FOUPOpenerStableWaitTime"))
  72. {
  73. _timeout = (int)SC.GetValue<double>("PM1.N2Purge.FOUPOpenerStableWaitTime");
  74. }
  75. _fimsModule.FIMSDevice.IsLoadCompleted = false;
  76. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  77. Notify($"{_fimsModule.Name} {Name} start");
  78. return Result.RUN;
  79. }
  80. public override Result Monitor()
  81. {
  82. try
  83. {
  84. PauseRountine(_fimsModule.FIMSDevice.IsPause);
  85. if (_fimsModule.FIMSDevice.IsPause)
  86. return Result.RUN;
  87. Load((int)RoutineStep.Load, _timeout);
  88. Delay((int)RoutineStep.Delay, 3);
  89. CheckLoadFinish((int)RoutineStep.CheckLoadFinish, _timeout);
  90. }
  91. catch (RoutineBreakException)
  92. {
  93. return Result.RUN;
  94. }
  95. catch (RoutineFaildException)
  96. {
  97. _fimsModule.Stop();
  98. return Result.FAIL;
  99. }
  100. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  101. _fimsModule.Stop();
  102. Notify($"{_fimsModule.Name} {Name} finished");
  103. return Result.DONE;
  104. }
  105. public void Abort()
  106. {
  107. _fimsModule.Stop();
  108. }
  109. private void Load(int id, int timeout)
  110. {
  111. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  112. {
  113. Notify($"{Module} load");
  114. if (!_fimsModule.FIMSDevice.Load(out string reason))
  115. {
  116. Stop(reason);
  117. return false;
  118. }
  119. return true;
  120. }, () =>
  121. {
  122. return true;
  123. }, timeout * 1000);
  124. if (ret.Item1)
  125. {
  126. if (ret.Item2 == Result.FAIL)
  127. {
  128. throw (new RoutineFaildException());
  129. }
  130. else if (ret.Item2 == Result.TIMEOUT) //timeout
  131. {
  132. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  133. throw (new RoutineFaildException());
  134. }
  135. else
  136. throw (new RoutineBreakException());
  137. }
  138. }
  139. private void CheckLoadFinish(int id, int timeout)
  140. {
  141. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  142. {
  143. Notify($"Check {Module} load finish");
  144. return true;
  145. }, () =>
  146. {
  147. if (_fimsModule.FIMSDevice.IsPLCLoadCompleted && !_fimsModule.FIMSDevice.IsRunning)
  148. {
  149. if (_fimsModule.IsWaferOnRobot)
  150. {
  151. _fimsModule.LoadFailAlarm.Set($"The wafer on {Module} has shifted");
  152. _pmModule?.SetN2PurgeProcess(false);
  153. return false;
  154. }
  155. return true;
  156. }
  157. return false;
  158. }, timeout * 1000);
  159. if (ret.Item1)
  160. {
  161. if (ret.Item2 == Result.FAIL)
  162. {
  163. throw (new RoutineFaildException());
  164. }
  165. else if (ret.Item2 == Result.TIMEOUT) //timeout
  166. {
  167. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  168. throw (new RoutineFaildException());
  169. }
  170. else
  171. throw (new RoutineBreakException());
  172. }
  173. }
  174. }
  175. }