LoadPortHomeRoutine.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  7. namespace FutureEfemLib.LPs
  8. {
  9. class LoadPortHomeRoutine : ModuleRoutine, IRoutine
  10. {
  11. enum RoutineStep
  12. {
  13. ClearError,
  14. Home,
  15. QueryStatus,
  16. }
  17. private int _timeout = 0;
  18. LoadPort _lp = null;
  19. private LoadPortModule _lpModule;
  20. public LoadPortHomeRoutine(LoadPortModule lpModule)
  21. {
  22. _lpModule = lpModule;
  23. Module = lpModule.Module;
  24. Name = "Home";
  25. _lp = DEVICE.GetDevice<LoadPort>($"{Module}");
  26. }
  27. public bool Initalize()
  28. {
  29. return true;
  30. }
  31. public Result Start(params object[] objs)
  32. {
  33. Reset();
  34. _timeout = SC.GetValue<int>("EFEM.LoadPort.HomeTimeout");
  35. Notify($"Start");
  36. return Result.RUN;
  37. }
  38. public Result Monitor()
  39. {
  40. try
  41. {
  42. //ClearError((int)RoutineStep.ClearError, _lp, _timeout);
  43. Home((int)RoutineStep.Home, _lp, _timeout);
  44. //QueryStatus((int)RoutineStep.QueryStatus, _lp, _timeout);
  45. }
  46. catch (RoutineBreakException)
  47. {
  48. return Result.RUN;
  49. }
  50. catch (RoutineFaildException ex)
  51. {
  52. LOG.Write(ex);
  53. return Result.FAIL;
  54. }
  55. Notify("Finished");
  56. return Result.DONE;
  57. }
  58. public void ClearError(int id, LoadPort lp, int timeout)
  59. {
  60. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  61. {
  62. Notify($"Clear error {lp.Name}");
  63. return true;
  64. }, () =>
  65. {
  66. if (_lp.Error)
  67. return false;
  68. if (_lp.IsBusy)
  69. return false;
  70. return true;
  71. }, timeout * 1000);
  72. if (ret.Item1)
  73. {
  74. if (ret.Item2 == Result.FAIL)
  75. {
  76. Stop(string.Format("failed."));
  77. throw (new RoutineFaildException());
  78. }
  79. else if (ret.Item2 == Result.TIMEOUT) //timeout
  80. {
  81. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  82. throw (new RoutineFaildException());
  83. }
  84. else
  85. throw (new RoutineBreakException());
  86. }
  87. }
  88. public void Home(int id, LoadPort lp, int timeout)
  89. {
  90. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  91. {
  92. Notify($"Start home {lp.Name}");
  93. string reason;
  94. if (!lp.Home(out reason))
  95. {
  96. Stop(reason);
  97. return false;
  98. }
  99. return true;
  100. }, () =>
  101. {
  102. if (_lp.Error)
  103. return false;
  104. if (_lp.IsBusy)
  105. return false;
  106. return true;
  107. }, timeout * 1000);
  108. if (ret.Item1)
  109. {
  110. if (ret.Item2 == Result.FAIL)
  111. {
  112. Stop(string.Format("Home failed."));
  113. throw (new RoutineFaildException());
  114. }
  115. else if (ret.Item2 == Result.TIMEOUT) //timeout
  116. {
  117. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  118. throw (new RoutineFaildException());
  119. }
  120. else
  121. throw (new RoutineBreakException());
  122. }
  123. }
  124. public void QueryStatus(int id, LoadPort lp, int timeout)
  125. {
  126. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  127. {
  128. Notify($"Start query status {lp.Name}");
  129. string reason;
  130. if (!lp.QueryState(out reason))
  131. {
  132. Stop(reason);
  133. return false;
  134. }
  135. return true;
  136. }, () =>
  137. {
  138. if (_lp.Error)
  139. return false;
  140. if (_lp.IsBusy)
  141. return false;
  142. return true;
  143. }, timeout * 1000);
  144. if (ret.Item1)
  145. {
  146. if (ret.Item2 == Result.FAIL)
  147. {
  148. Stop(string.Format("Query status failed."));
  149. throw (new RoutineFaildException());
  150. }
  151. else if (ret.Item2 == Result.TIMEOUT) //timeout
  152. {
  153. Stop(string.Format("Query status timeout, can not complete in {0} seconds", timeout));
  154. throw (new RoutineFaildException());
  155. }
  156. else
  157. throw (new RoutineBreakException());
  158. }
  159. }
  160. public void Abort()
  161. {
  162. }
  163. }
  164. }