FIMSLoadRoutine.cs 6.3 KB

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