PMHomeRoutine.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. Home,
  13. }
  14. public PMHomeRoutine(JetPM chamber) : base(chamber)
  15. {
  16. Name = "Homing";
  17. }
  18. public Result Init()
  19. {
  20. return Result.DONE;
  21. }
  22. public Result Start(params object[] objs)
  23. {
  24. Reset();
  25. Notify("Start");
  26. return Result.RUN;
  27. }
  28. public Result Monitor()
  29. {
  30. try
  31. {
  32. if (_chamber != null && _chamber.IsInstalled)
  33. {
  34. SetLiftPinPos((int)RoutineStep.LiftPinOrig, MovementPosition.Origin, 200);
  35. Home((int)RoutineStep.Home, 10);
  36. }
  37. }
  38. catch (RoutineBreakException)
  39. {
  40. return Result.RUN;
  41. }
  42. catch (RoutineFaildException)
  43. {
  44. Stop("Error");
  45. return Result.FAIL;
  46. }
  47. catch (Exception ex)
  48. {
  49. Stop(ex.Message);
  50. return Result.FAIL;
  51. }
  52. Notify("Finish");
  53. return Result.DONE;
  54. }
  55. public override void Abort()
  56. {
  57. }
  58. public void Home(int id, int timeout)
  59. {
  60. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  61. {
  62. Notify($"Run {_chamber.Name} home");
  63. _chamber.Home();
  64. return true;
  65. }, ()=> true, timeout * 1000);
  66. if (ret.Item1)
  67. {
  68. if (ret.Item2 == Result.FAIL)
  69. {
  70. Stop($"{_chamber.Name} error");
  71. throw new RoutineFaildException();
  72. }
  73. else if (ret.Item2 == Result.TIMEOUT) //timeout
  74. {
  75. Stop($"timeout, over {timeout} seconds");
  76. throw new RoutineFaildException();
  77. }
  78. else
  79. throw new RoutineBreakException();
  80. }
  81. }
  82. }
  83. }