LoaderSideCycleRoutine.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Routine;
  4. using MECF.Framework.Common.Utilities;
  5. using CyberX8_Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace CyberX8_RT.Devices.Loader
  12. {
  13. public class LoaderSideCycleRoutine : RoutineBase, IRoutine
  14. {
  15. private enum LoaderSideCycleStep
  16. {
  17. LoopStart,
  18. LoopUnload,
  19. LoopUnloadWait,
  20. LoopLoad,
  21. LoopLoadWait,
  22. LoopFlowTest,
  23. LoopFlowTestWait,
  24. LoopEnd,
  25. End
  26. }
  27. #region 内部变量
  28. /// <summary>
  29. /// 面
  30. /// </summary>
  31. private string _side;
  32. /// <summary>
  33. /// Load Routine
  34. /// </summary>
  35. private LoaderLoadRoutine _loadRoutine;
  36. /// <summary>
  37. /// Unload Routine
  38. /// </summary>
  39. private LoaderUnloadRoutine _unloadRoutine;
  40. /// <summary>
  41. /// Common device对象
  42. /// </summary>
  43. private LoaderCommonDevice _commonDevice;
  44. /// <summary>
  45. /// 总次数
  46. /// </summary>
  47. private int _totalCycle;
  48. /// <summary>
  49. /// 忽略leaktest
  50. /// </summary>
  51. private bool _ignoreLeakTest;
  52. #endregion
  53. #region 属性
  54. /// <summary>
  55. /// 当前次数
  56. /// </summary>
  57. public int CurrentCycle { get { return Runner.LoopCounter+1; } }
  58. #endregion
  59. /// <summary>
  60. /// 构造函数
  61. /// </summary>
  62. /// <param name="module"></param>
  63. public LoaderSideCycleRoutine(string module,string side) : base(module)
  64. {
  65. _side = side;
  66. }
  67. /// <summary>
  68. /// 中止
  69. /// </summary>
  70. public void Abort()
  71. {
  72. Runner.Stop("Manual Stop");
  73. if (Runner.CurrentStep.ToString() ==LoaderSideCycleStep.LoopFlowTest.ToString()
  74. || Runner.CurrentStep.ToString() == LoaderSideCycleStep.LoopFlowTestWait.ToString())
  75. {
  76. _commonDevice.StopFlowTestAction();
  77. }
  78. else if (Runner.CurrentStep.ToString() == LoaderSideCycleStep.LoopLoad.ToString()
  79. || Runner.CurrentStep.ToString() == LoaderSideCycleStep.LoopLoadWait.ToString())
  80. {
  81. _loadRoutine.Abort();
  82. }
  83. else if (Runner.CurrentStep.ToString() == LoaderSideCycleStep.LoopUnload.ToString()
  84. || Runner.CurrentStep.ToString() == LoaderSideCycleStep.LoopUnloadWait.ToString())
  85. {
  86. _unloadRoutine.Abort();
  87. }
  88. }
  89. /// <summary>
  90. /// 监控
  91. /// </summary>
  92. /// <returns></returns>
  93. public RState Monitor()
  94. {
  95. Runner.LoopStart(LoaderSideCycleStep.LoopStart, "Loader Cycle", _totalCycle, NullFun, _delay_1ms)
  96. .LoopRun(LoaderSideCycleStep.LoopUnload, StartUnload, _delay_1ms)
  97. .LoopRunWithStopStatus(LoaderSideCycleStep.LoopUnloadWait, () => CommonFunction.CheckRoutineEndState(_unloadRoutine),
  98. () => CommonFunction.CheckRoutineStopState(_unloadRoutine))
  99. .LoopRun(LoaderSideCycleStep.LoopLoad, StartLoad, _delay_1ms)
  100. .LoopRunWithStopStatus(LoaderSideCycleStep.LoopLoadWait, () => CommonFunction.CheckRoutineEndState(_loadRoutine),
  101. () => CommonFunction.CheckRoutineStopState(_loadRoutine))
  102. .LoopRunIf(LoaderSideCycleStep.LoopFlowTest,!_ignoreLeakTest, StartFlowTest, _delay_1ms)
  103. .LoopRunIfWithStopStatus(LoaderSideCycleStep.LoopFlowTestWait, !_ignoreLeakTest,() => _commonDevice.Status == RState.End, () => _commonDevice.Status == RState.Failed)
  104. .LoopEnd(LoaderSideCycleStep.LoopEnd, NullFun, _delay_1ms)
  105. .End(LoaderSideCycleStep.End, NullFun, _delay_1ms);
  106. return Runner.Status;
  107. }
  108. /// <summary>
  109. /// 启动Unload
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool StartUnload()
  113. {
  114. return _unloadRoutine.Start()==RState.Running;
  115. }
  116. /// <summary>
  117. /// 启动Load
  118. /// </summary>
  119. /// <returns></returns>
  120. private bool StartLoad()
  121. {
  122. return _loadRoutine.Start()==RState.Running;
  123. }
  124. /// <summary>
  125. /// 启动Flowtest
  126. /// </summary>
  127. /// <returns></returns>
  128. private bool StartFlowTest()
  129. {
  130. return _commonDevice.StartFlowTestAction();
  131. }
  132. /// <summary>
  133. /// 启动
  134. /// </summary>
  135. /// <param name="objs"></param>
  136. /// <returns></returns>
  137. public RState Start(params object[] objs)
  138. {
  139. _commonDevice = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");
  140. _totalCycle = (int)objs[0];
  141. _ignoreLeakTest=(bool)objs[1];
  142. _loadRoutine = new LoaderLoadRoutine(Module, _side);
  143. _unloadRoutine= new LoaderUnloadRoutine(Module, _side);
  144. Runner.Start(Module, "Start Cycle");
  145. return RState.Running;
  146. }
  147. }
  148. }