LoadPortReadCarrierIdRoutine.cs 4.1 KB

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