LoadPortLoadRoutine.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Diagnostics;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. namespace VirgoRT.Modules.LPs
  13. {
  14. class LoadPortLoadRoutine : ModuleRoutine, IRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. WaitEFEMReady,
  19. Delay,
  20. Load,
  21. }
  22. private int _timeout = 0;
  23. private int _wait_timeout = 20 * 60 * 1000;
  24. private Stopwatch _robotIdleWatch = new Stopwatch();
  25. private LoadPortModule _lpModule;
  26. public LoadPortLoadRoutine(LoadPortModule lpModule)
  27. {
  28. _lpModule = lpModule;
  29. Module = lpModule.Module;
  30. Name = "Load";
  31. }
  32. public Result Start(params object[] objs)
  33. {
  34. Reset();
  35. _timeout = SC.GetValue<int>("EFEM.LoadPort.MotionTimeout");
  36. if (!_lpModule.LPDevice.HasCassette )
  37. {
  38. EV.PostWarningLog(Module, $"{Module} not found carrier, can not load");
  39. return Result.FAIL;
  40. }
  41. Notify($"Start");
  42. return Result.RUN;
  43. }
  44. public Result Monitor()
  45. {
  46. try
  47. {
  48. //Wait((int)RoutineStep.WaitEFEMReady, WaitEFEMReady, _wait_timeout);
  49. Load((int)RoutineStep.Load, _timeout);
  50. }
  51. catch (RoutineBreakException)
  52. {
  53. return Result.RUN;
  54. }
  55. catch (RoutineFaildException )
  56. {
  57. return Result.FAIL;
  58. }
  59. _robotIdleWatch.Stop();
  60. Notify("Finished");
  61. return Result.DONE;
  62. }
  63. public bool IsRobotAvailable()
  64. {
  65. if(Singleton<RouteManager>.Instance.IsEfemRobotAvailable)
  66. {
  67. if(_robotIdleWatch.IsRunning)
  68. {
  69. if (_robotIdleWatch.ElapsedMilliseconds > 200)
  70. {
  71. _robotIdleWatch.Stop();
  72. return true;
  73. }
  74. }
  75. else
  76. {
  77. _robotIdleWatch.Restart();
  78. }
  79. }
  80. else
  81. {
  82. _robotIdleWatch.Stop();
  83. }
  84. return false;
  85. }
  86. public bool WaitEFEMReady()
  87. {
  88. if( IsRobotAvailable() &&
  89. WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) &&
  90. WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  91. {
  92. return true;
  93. }
  94. else
  95. {
  96. throw (new RoutineBreakException());
  97. }
  98. }
  99. public void Load(int id, int timeout)
  100. {
  101. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  102. {
  103. Notify($"Start Load {_lpModule.Name}");
  104. _lpModule.LPDevice.Load();
  105. return true;
  106. //return Singleton<RouteManager>.Instance.EFEM.CheckToPostMessage((int)EfemEntity.MSG.Load, Module);
  107. }, () =>
  108. {
  109. if (!_lpModule.LPDevice.HasCassette)
  110. {
  111. EV.PostWarningLog(Module, $"{Module} carrier has been removed, can not load");
  112. return true;
  113. }
  114. if (_lpModule.LPDevice.IsError)
  115. return null;
  116. if (_lpModule.LPDevice.IsBusy)
  117. return false;
  118. return true;
  119. }, timeout * 1000);
  120. if (ret.Item1)
  121. {
  122. if (ret.Item2 == Result.FAIL)
  123. {
  124. Stop(string.Format("failed."));
  125. throw (new RoutineFaildException());
  126. }
  127. else if (ret.Item2 == Result.TIMEOUT) //timeout
  128. {
  129. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  130. throw (new RoutineFaildException());
  131. }
  132. else
  133. throw (new RoutineBreakException());
  134. }
  135. }
  136. public void Abort()
  137. {
  138. }
  139. }
  140. }