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