LoadPortClampRoutine.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 LoadPortClampRoutine : ModuleRoutine, IRoutine
  10. {
  11. enum RoutineStep
  12. {
  13. Clamp,
  14. QueryStatus,
  15. }
  16. private int _timeout = 0;
  17. LoadPort _lp = null;
  18. private LoadPortModule _lpModule;
  19. public LoadPortClampRoutine(LoadPortModule lpModule)
  20. {
  21. _lpModule = lpModule;
  22. Module = lpModule.Module;
  23. Name = "Clamp";
  24. _lp = DEVICE.GetDevice<LoadPort>($"{Module}");
  25. }
  26. public bool Initalize()
  27. {
  28. return true;
  29. }
  30. public Result Start(params object[] objs)
  31. {
  32. Reset();
  33. _timeout = SC.GetValue<int>("EFEM.LoadPort.MotionTimeout");
  34. Notify($"Start");
  35. return Result.RUN;
  36. }
  37. public Result Monitor()
  38. {
  39. try
  40. {
  41. Clamp((int)RoutineStep.Clamp, _lp, _timeout);
  42. QueryStatus((int)RoutineStep.QueryStatus, _lp, _timeout);
  43. }
  44. catch (RoutineBreakException)
  45. {
  46. return Result.RUN;
  47. }
  48. catch (RoutineFaildException ex)
  49. {
  50. LOG.Write(ex);
  51. return Result.FAIL;
  52. }
  53. Notify("Finished");
  54. return Result.DONE;
  55. }
  56. public void Clamp(int id, LoadPort lp, int timeout)
  57. {
  58. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  59. {
  60. Notify($"Start clamp {lp.Name}");
  61. string reason;
  62. if (!lp.Clamp(out reason))
  63. {
  64. Stop(reason);
  65. return false;
  66. }
  67. return true;
  68. }, () =>
  69. {
  70. if (_lp.Error)
  71. return false;
  72. if (_lp.IsBusy)
  73. return false;
  74. return true;
  75. }, timeout * 1000);
  76. if (ret.Item1)
  77. {
  78. if (ret.Item2 == Result.FAIL)
  79. {
  80. Stop(string.Format("failed."));
  81. throw (new RoutineFaildException());
  82. }
  83. else if (ret.Item2 == Result.TIMEOUT) //timeout
  84. {
  85. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  86. throw (new RoutineFaildException());
  87. }
  88. else
  89. throw (new RoutineBreakException());
  90. }
  91. }
  92. public void QueryStatus(int id, LoadPort lp, int timeout)
  93. {
  94. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  95. {
  96. Notify($"Start query status {lp.Name}");
  97. string reason;
  98. if (!lp.QueryState(out reason))
  99. {
  100. Stop(reason);
  101. return false;
  102. }
  103. return true;
  104. }, () =>
  105. {
  106. if (lp.Error)
  107. return false;
  108. if (lp.IsBusy)
  109. return false;
  110. return true;
  111. }, timeout * 1000);
  112. if (ret.Item1)
  113. {
  114. if (ret.Item2 == Result.FAIL)
  115. {
  116. Stop(string.Format("Query status failed."));
  117. throw (new RoutineFaildException());
  118. }
  119. else if (ret.Item2 == Result.TIMEOUT) //timeout
  120. {
  121. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  122. throw (new RoutineFaildException());
  123. }
  124. else
  125. throw (new RoutineBreakException());
  126. }
  127. }
  128. public void Abort()
  129. {
  130. }
  131. }
  132. }