PMHomeRoutine.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using VirgoRT.Devices;
  4. using VirgoCommon;
  5. namespace VirgoRT.Modules.PMs
  6. {
  7. class PMHomeRoutine : PMRoutineBase, IRoutine
  8. {
  9. enum RoutineStep
  10. {
  11. LiftPinOrig,
  12. ResetPlcSignal,
  13. ResetPlcSignalDelay,
  14. Home,
  15. }
  16. public PMHomeRoutine(JetPM chamber) : base(chamber)
  17. {
  18. Name = "Homing";
  19. }
  20. public Result Init()
  21. {
  22. return Result.DONE;
  23. }
  24. public Result Start(params object[] objs)
  25. {
  26. Reset();
  27. Notify("Start");
  28. return Result.RUN;
  29. }
  30. public Result Monitor()
  31. {
  32. try
  33. {
  34. if (_chamber != null && _chamber.IsInstalled)
  35. {
  36. ResetPlcSignal((int)RoutineStep.ResetPlcSignal, 10);
  37. TimeDelay((int)RoutineStep.ResetPlcSignalDelay, 10);
  38. SetLiftPinPos((int)RoutineStep.LiftPinOrig, MovementPosition.Origin, 200);
  39. Home((int)RoutineStep.Home, 10);
  40. }
  41. }
  42. catch (RoutineBreakException)
  43. {
  44. return Result.RUN;
  45. }
  46. catch (RoutineFaildException)
  47. {
  48. Stop("Error");
  49. return Result.FAIL;
  50. }
  51. catch (Exception ex)
  52. {
  53. Stop(ex.Message);
  54. return Result.FAIL;
  55. }
  56. Notify("Finish");
  57. return Result.DONE;
  58. }
  59. public override void Abort()
  60. {
  61. }
  62. public void ResetPlcSignal(int id, int timeout)
  63. {
  64. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  65. {
  66. Notify($"Run {_chamber.Name} ResetPlcSignal");
  67. _chamber.ResetPlcSignal();
  68. return true;
  69. }, () => true, timeout * 1000);
  70. if (ret.Item1)
  71. {
  72. if (ret.Item2 == Result.FAIL)
  73. {
  74. Stop($"{_chamber.Name} ResetPlcSignal error");
  75. throw new RoutineFaildException();
  76. }
  77. else if (ret.Item2 == Result.TIMEOUT) //timeout
  78. {
  79. Stop($"ResetPlcSignal timeout, over {timeout} seconds");
  80. throw new RoutineFaildException();
  81. }
  82. else
  83. throw new RoutineBreakException();
  84. }
  85. }
  86. public void Home(int id, int timeout)
  87. {
  88. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  89. {
  90. Notify($"Run {_chamber.Name} home");
  91. _chamber.Home();
  92. return true;
  93. }, ()=> true, timeout * 1000);
  94. if (ret.Item1)
  95. {
  96. if (ret.Item2 == Result.FAIL)
  97. {
  98. Stop($"{_chamber.Name} error");
  99. throw new RoutineFaildException();
  100. }
  101. else if (ret.Item2 == Result.TIMEOUT) //timeout
  102. {
  103. Stop($"timeout, over {timeout} seconds");
  104. throw new RoutineFaildException();
  105. }
  106. else
  107. throw new RoutineBreakException();
  108. }
  109. }
  110. }
  111. }