LoadPortOpenDoorRoutine.cs 4.1 KB

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