LoadPortGetMapInfoRoutine.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  6. namespace FutureEfemLib.LPs
  7. {
  8. class LoadPortGetMapInfoRoutine : ModuleRoutine, IRoutine
  9. {
  10. enum RoutineStep
  11. {
  12. OpenDoor,
  13. GetWaferInfo,
  14. QueryStatus,
  15. }
  16. private int _timeout = 0;
  17. private LoadPort _lp = null;
  18. private LoadPortModule _lpModule;
  19. public LoadPortGetMapInfoRoutine(LoadPortModule lpModule)
  20. {
  21. _lpModule = lpModule;
  22. Module = lpModule.Module;
  23. Name = "MapDT";
  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. QueryMapInfo((int)RoutineStep.GetWaferInfo, _lp, _timeout);
  42. QueryStatus((int)RoutineStep.QueryStatus, _lp, _timeout);
  43. }
  44. catch (RoutineBreakException)
  45. {
  46. return Result.RUN;
  47. }
  48. catch (RoutineFaildException )
  49. {
  50. //LOG.Error(ex);
  51. return Result.FAIL;
  52. }
  53. Notify("Finished");
  54. return Result.DONE;
  55. }
  56. public void QueryMapInfo(int id, LoadPort lp, int timeout)
  57. {
  58. Tuple<bool, Result> ret = ExecuteAndWait(id, () => {
  59. Notify($"Start to get wafer info {lp.Name}");
  60. //string reason;
  61. if (!lp.GetMapInfo(out string reason))
  62. {
  63. Stop(reason);
  64. return false;
  65. }
  66. return true;
  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. Notify($"Start query status {lp.Name}");
  94. string reason;
  95. if (!lp.QueryState(out reason))
  96. {
  97. Stop(reason);
  98. return false;
  99. }
  100. return true;
  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("Query status failed."));
  113. throw (new RoutineFaildException());
  114. }
  115. else if (ret.Item2 == Result.TIMEOUT) //timeout
  116. {
  117. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  118. throw (new RoutineFaildException());
  119. }
  120. else
  121. throw (new RoutineBreakException());
  122. }
  123. }
  124. public void Abort()
  125. {
  126. }
  127. }
  128. }