FIMSLoadRoutine.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. _pmModule?.SetN2PurgeProcess(_isNeedN2Purge);
  64. if (_fimsModule.FIMSDevice.IsLoadCompleted)
  65. {
  66. EV.PostInfoLog(Module, $"{Module} already at load position");
  67. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  68. _fimsModule.FIMSDevice.IsUnloadCompleted = false;
  69. return Result.DONE;
  70. }
  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. _pmModule?.SetN2PurgeProcess(false);
  101. _fimsModule.FIMSDevice.IsLoadCompleted = true;
  102. _fimsModule.Stop();
  103. Notify($"{_fimsModule.Name} {Name} finished");
  104. return Result.DONE;
  105. }
  106. public void Abort()
  107. {
  108. _fimsModule.Stop();
  109. }
  110. private void Load(int id, int timeout)
  111. {
  112. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  113. {
  114. Notify($"{Module} load");
  115. if (!_fimsModule.FIMSDevice.Load(out string reason))
  116. {
  117. Stop(reason);
  118. return false;
  119. }
  120. return true;
  121. }, () =>
  122. {
  123. return true;
  124. }, timeout * 1000);
  125. if (ret.Item1)
  126. {
  127. if (ret.Item2 == Result.FAIL)
  128. {
  129. throw (new RoutineFaildException());
  130. }
  131. else if (ret.Item2 == Result.TIMEOUT) //timeout
  132. {
  133. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  134. throw (new RoutineFaildException());
  135. }
  136. else
  137. throw (new RoutineBreakException());
  138. }
  139. }
  140. private void CheckLoadFinish(int id, int timeout)
  141. {
  142. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  143. {
  144. Notify($"Check {Module} load finish");
  145. return true;
  146. }, () =>
  147. {
  148. if (_fimsModule.FIMSDevice.IsPLCLoadCompleted && !_fimsModule.FIMSDevice.IsRunning)
  149. {
  150. if (_fimsModule.IsWaferOnRobot)
  151. {
  152. _fimsModule.LoadFailAlarm.Set($"The wafer on {Module} has shifted");
  153. _pmModule?.SetN2PurgeProcess(false);
  154. return false;
  155. }
  156. return true;
  157. }
  158. return false;
  159. }, timeout * 1000);
  160. if (ret.Item1)
  161. {
  162. if (ret.Item2 == Result.FAIL)
  163. {
  164. throw (new RoutineFaildException());
  165. }
  166. else if (ret.Item2 == Result.TIMEOUT) //timeout
  167. {
  168. _fimsModule.LoadTimeoutAlarm.Set($"can not complete in {timeout} seconds");
  169. throw (new RoutineFaildException());
  170. }
  171. else
  172. throw (new RoutineBreakException());
  173. }
  174. }
  175. }
  176. }