CycleRobotCycleRoutine.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using CyberX8_Core;
  4. using CyberX8_RT.Devices.EFEM;
  5. using CyberX8_RT.Modules.Rinse;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.Utilities;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CyberX8_RT.Modules.EFEM
  15. {
  16. public class CycleRobotCycleRoutine : ModuleRoutineBase, IRoutine
  17. {
  18. private enum CycleRobotCycleStep
  19. {
  20. LoopStart,
  21. LoopRunRobotCycle,
  22. LoopRunRobotCycleWait,
  23. LoopEnd,
  24. End
  25. }
  26. /// <summary>
  27. /// Cycle次数
  28. /// </summary>
  29. private int _cycleTimes;
  30. /// <summary>
  31. /// 当前处于第几次Cycle
  32. /// </summary>
  33. private int _currentCycle;
  34. private object[] param;
  35. private RobotCycleRoutine _robotCycleRoutine;
  36. public CycleRobotCycleRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  37. {
  38. _robotCycleRoutine = new RobotCycleRoutine(efem);
  39. }
  40. public RState Start(params object[] objs)
  41. {
  42. param = objs;
  43. _currentCycle = 1;//初始化当前Cycle次数
  44. if (objs.Length >= 6)
  45. {
  46. _cycleTimes = (int)objs[4];
  47. if (_cycleTimes < 1)
  48. {
  49. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
  50. return RState.Failed;
  51. }
  52. }
  53. return Runner.Start(Module, "Start CycleRobotCycleRoutine");
  54. }
  55. public RState Monitor()
  56. {
  57. Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
  58. .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _robotCycleRoutine.Start(param) == RState.Running,_delay_1ms)
  59. .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_robotCycleRoutine); },
  60. () => CheckRoutineStopStatus(_robotCycleRoutine, "CycleRobotCycleRoutine failed"))
  61. .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  62. .End(CycleRobotCycleStep.End, AchievedCycleCount, _delay_1ms);
  63. return Runner.Status;
  64. }
  65. private bool CheckRoutineStopStatus(IRoutine routine, string error)
  66. {
  67. bool result = CommonFunction.CheckRoutineStopState(routine);
  68. if (result)
  69. {
  70. Stop($"{error}");
  71. }
  72. return result;
  73. }
  74. /// <summary>
  75. /// Abort
  76. /// </summary>
  77. public void Abort()
  78. {
  79. Runner.Stop("CycleRobotCycleRoutine Abort");
  80. }
  81. /// <summary>
  82. /// 统计完成的Cycle次数
  83. /// </summary>
  84. /// <returns></returns>
  85. private bool UpdateCycleCount()
  86. {
  87. _currentCycle += 1;
  88. return true;
  89. }
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <returns></returns>
  94. private bool AchievedCycleCount()
  95. {
  96. _currentCycle -= 1;
  97. return true;
  98. }
  99. /// <summary>
  100. /// 获取当前Cycle次数
  101. /// </summary>
  102. /// <returns></returns>
  103. public int GetCurrentCycle()
  104. {
  105. return _currentCycle;
  106. }
  107. }
  108. }