LoadPortHomeRoutine.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 VirgoRT.Modules.LPs
  8. {
  9. class LoadPortHomeRoutine : ModuleRoutine, IRoutine
  10. {
  11. enum RoutineStep
  12. {
  13. Home,
  14. QueryStatus,
  15. }
  16. private int _timeout = 0;
  17. private LoadPortModule _lpModule;
  18. public LoadPortHomeRoutine(LoadPortModule lpModule)
  19. {
  20. _lpModule = lpModule;
  21. Module = lpModule.Module;
  22. Name = "Home";
  23. }
  24. public Result Start(params object[] objs)
  25. {
  26. Reset();
  27. _timeout = SC.GetValue<int>("EFEM.LoadPort.HomeTimeout");
  28. Notify($"Start");
  29. return Result.RUN;
  30. }
  31. public Result Monitor()
  32. {
  33. try
  34. {
  35. Home((int)RoutineStep.Home, _timeout);
  36. QueryStatus((int)RoutineStep.QueryStatus, _timeout);
  37. }
  38. catch (RoutineBreakException)
  39. {
  40. return Result.RUN;
  41. }
  42. catch (RoutineFaildException )
  43. {
  44. return Result.FAIL;
  45. }
  46. Notify("Finished");
  47. return Result.DONE;
  48. }
  49. public void Home(int id, int timeout)
  50. {
  51. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  52. {
  53. Notify($"Start home {_lpModule.Name}");
  54. _lpModule.LPDevice.Home();
  55. return true;
  56. }, () =>
  57. {
  58. if (_lpModule.LPDevice.IsError)
  59. return null;
  60. if (_lpModule.LPDevice.IsBusy)
  61. return false;
  62. return true;
  63. }, timeout * 1000);
  64. if (ret.Item1)
  65. {
  66. if (ret.Item2 == Result.FAIL)
  67. {
  68. Stop(string.Format("Home failed."));
  69. throw (new RoutineFaildException());
  70. }
  71. else if (ret.Item2 == Result.TIMEOUT) //timeout
  72. {
  73. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  74. throw (new RoutineFaildException());
  75. }
  76. else
  77. throw (new RoutineBreakException());
  78. }
  79. }
  80. public void QueryStatus(int id, int timeout)
  81. {
  82. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  83. {
  84. Notify($"Start SIGSTAT {_lpModule.Name}");
  85. _lpModule.LPDevice.SIGSTAT();
  86. return true;
  87. }, () =>
  88. {
  89. if (_lpModule.LPDevice.IsError)
  90. return null;
  91. if (_lpModule.LPDevice.IsBusy)
  92. return false;
  93. return true;
  94. }, timeout * 1000);
  95. if (ret.Item1)
  96. {
  97. if (ret.Item2 == Result.FAIL)
  98. {
  99. Stop(string.Format("SIGSTAT failed."));
  100. throw (new RoutineFaildException());
  101. }
  102. else if (ret.Item2 == Result.TIMEOUT) //timeout
  103. {
  104. Stop(string.Format("SIGSTAT timeout, can not complete in {0} seconds", timeout));
  105. throw (new RoutineFaildException());
  106. }
  107. else
  108. throw (new RoutineBreakException());
  109. }
  110. }
  111. public void Abort()
  112. {
  113. }
  114. }
  115. }