PMHomeRoutine.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using VirgoRT.Devices;
  4. namespace VirgoRT.Modules.PMs
  5. {
  6. class PMHomeRoutine : PMRoutineBase, IRoutine
  7. {
  8. enum RoutineStep
  9. {
  10. Home,
  11. }
  12. public PMHomeRoutine(JetPM chamber) : base(chamber)
  13. {
  14. Name = "Homing";
  15. }
  16. public Result Init()
  17. {
  18. return Result.DONE;
  19. }
  20. public Result Start(params object[] objs)
  21. {
  22. Reset();
  23. Notify("开始");
  24. return Result.RUN;
  25. }
  26. public Result Monitor()
  27. {
  28. try
  29. {
  30. if (_chamber != null && _chamber.IsInstalled)
  31. {
  32. Home((int)RoutineStep.Home, 10);
  33. }
  34. }
  35. catch (RoutineBreakException)
  36. {
  37. return Result.RUN;
  38. }
  39. catch (RoutineFaildException)
  40. {
  41. Stop("出错");
  42. return Result.FAIL;
  43. }
  44. catch (Exception ex)
  45. {
  46. Stop(ex.Message);
  47. return Result.FAIL;
  48. }
  49. Notify("结束");
  50. return Result.DONE;
  51. }
  52. public override void Abort()
  53. {
  54. }
  55. public void Home(int id, int timeout)
  56. {
  57. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  58. {
  59. Notify($"Run {_chamber.Name} home");
  60. _chamber.Home();
  61. return true;
  62. }, () => true, timeout * 1000);
  63. if (ret.Item1)
  64. {
  65. if (ret.Item2 == Result.FAIL)
  66. {
  67. Stop($"{_chamber.Name} error");
  68. throw new RoutineFaildException();
  69. }
  70. else if (ret.Item2 == Result.TIMEOUT) //timeout
  71. {
  72. Stop($"超时, over {timeout} seconds");
  73. throw new RoutineFaildException();
  74. }
  75. else
  76. throw new RoutineBreakException();
  77. }
  78. }
  79. }
  80. }