FIMSLoadRoutine.cs 6.8 KB

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