EfemMapRoutine.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using FutureEfemLib.LPs;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.RT.ModuleLibrary.LPModules;
  11. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  12. namespace FutureEfemLib.Efems
  13. {
  14. public class EfemMapRoutine : ModuleRoutine, IRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. CheckTargetEnableMap,
  19. Map,
  20. }
  21. private int _mapTimeout;
  22. private ModuleName _target;
  23. private int _thicknessIndex;
  24. //private Hand _hand;
  25. //private bool _autoHand;
  26. private EfemModule _efemModule;
  27. public EfemMapRoutine(EfemModule efemModule)
  28. {
  29. Module = "EFEM";
  30. Name = "Map";
  31. _efemModule = efemModule;
  32. }
  33. public Result Start(params object[] objs)
  34. {
  35. _mapTimeout = SC.GetValue<int>("EFEM.EfemRobot.MapTimeout");
  36. Reset();
  37. _thicknessIndex = 0;
  38. //if (ModuleHelper.IsLoadPort(_target))
  39. //{
  40. // LoadPortModule lp = Singleton<EquipmentManager>.Instance.Modules[_target] as LoadPortModule;
  41. // _thicknessIndex = lp.LPDevice.GetThicknessIndex();
  42. //}
  43. Notify($"Start map {_target}");
  44. return Result.RUN;
  45. }
  46. public void Init(ModuleName source)
  47. {
  48. //_autoHand = true;
  49. _target = source;
  50. }
  51. public void Abort()
  52. {
  53. Notify($"Abort map {_target}");
  54. }
  55. public Result Monitor()
  56. {
  57. try
  58. {
  59. CheckTargetEnableMap((int)RoutineStep.CheckTargetEnableMap, _target);
  60. Map((int)RoutineStep.Map, _target, _thicknessIndex, _mapTimeout);
  61. }
  62. catch (RoutineBreakException)
  63. {
  64. return Result.RUN;
  65. }
  66. catch (RoutineFaildException)
  67. {
  68. return Result.FAIL;
  69. }
  70. Notify($"Complete map {_target}");
  71. return Result.DONE;
  72. }
  73. public void CheckTargetEnableMap(int id, ModuleName target)
  74. {
  75. Tuple<bool, Result> ret = Execute(id, () =>
  76. {
  77. Notify($"Check {target} enable map");
  78. if (!_efemModule.RobotDevice.IsReady())
  79. {
  80. Stop($"Can not map {target}, EfemRobot is not ready");
  81. return false;
  82. }
  83. if (!ModuleHelper.IsLoadPort(target) && !ModuleHelper.IsLoadLock(target))
  84. {
  85. Stop($"Can not map {target}, only LP or Buf supported");
  86. return false;
  87. }
  88. if (target == ModuleName.LLA && DEVICE.GetDevice<IoSensor>($"System.SensorBufferABigWaferProtrusion").Value)
  89. {
  90. Stop($"Can not map {target}, SensorBufferABigWaferProtrusion is on");
  91. return false;
  92. }
  93. if (target == ModuleName.LLB && DEVICE.GetDevice<IoSensor>($"System.SensorBufferBBigWaferProtrusion").Value)
  94. {
  95. Stop($"Can not map {target}, SensorBufferBBigWaferProtrusion is on");
  96. return false;
  97. }
  98. if (ModuleHelper.IsLoadPort(target))
  99. {
  100. LoadPortModuleBase lp = EquipmentManager.Modules[target] as LoadPortModuleBase;
  101. if (!lp.CheckReadyForMap(ModuleName.EfemRobot, Hand.Blade1, out string reason))
  102. {
  103. Stop(reason);
  104. return false;
  105. }
  106. }
  107. return true;
  108. });
  109. if (ret.Item1)
  110. {
  111. if (ret.Item2 == Result.FAIL)
  112. {
  113. throw (new RoutineFaildException());
  114. }
  115. }
  116. }
  117. public void Map(int id, ModuleName target, int thicknessIndex, int timeout)
  118. {
  119. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  120. {
  121. Notify($"Robot start map {target}");
  122. string reason;
  123. if (!_efemModule.RobotDevice.Map(target, thicknessIndex, out reason))
  124. {
  125. Stop(reason);
  126. return false;
  127. }
  128. return true;
  129. }, () =>
  130. {
  131. if (_efemModule.RobotDevice.IsError)
  132. return null;
  133. if (_efemModule.RobotDevice.IsIdle)
  134. return true;
  135. return false;
  136. }, timeout * 1000);
  137. if (ret.Item1)
  138. {
  139. if (ret.Item2 == Result.FAIL)
  140. {
  141. throw (new RoutineFaildException());
  142. }
  143. else if (ret.Item2 == Result.TIMEOUT) //timeout
  144. {
  145. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  146. throw (new RoutineFaildException());
  147. }
  148. else
  149. throw (new RoutineBreakException());
  150. }
  151. }
  152. }
  153. }