LoaderFlowTestRoutine.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Routine;
  4. using CyberX8_Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace CyberX8_RT.Devices.Loader
  11. {
  12. public class LoaderFlowTestRoutine : RoutineBase, IRoutine
  13. {
  14. private enum FlowTestStep
  15. {
  16. FirstFlowTest,
  17. FirstFlowTestWait,
  18. SecondFlowTest,
  19. SecondFlowTestWait,
  20. End,
  21. }
  22. #region 内部变量
  23. private LoaderLeakFirstFlowTestRoutine _firstFlowTestRoutine;
  24. private LoaderReLeakFlowTestRoutine _reLeakFlowTestRoutine;
  25. private bool _isNeedReTest;
  26. private LoaderCommonDevice _commonDevice;
  27. #endregion
  28. /// <summary>
  29. /// 构造函数
  30. /// </summary>
  31. /// <param name="module"></param>
  32. public LoaderFlowTestRoutine(string module) : base(module)
  33. {
  34. }
  35. /// <summary>
  36. /// 中止
  37. /// </summary>
  38. public void Abort()
  39. {
  40. Runner.Stop("Manual Abort");
  41. }
  42. /// <summary>
  43. /// 监控
  44. /// </summary>
  45. /// <returns></returns>
  46. public RState Monitor()
  47. {
  48. Runner.Run(FlowTestStep.FirstFlowTest, StartFirstFlowTest, _delay_1ms)
  49. .WaitWithStopCondition(FlowTestStep.FirstFlowTestWait, CheckFirstTestResult, CheckFirstTestFailedResult)
  50. .Run(FlowTestStep.SecondFlowTest, StartSecondFlowTest, _delay_1ms)
  51. .WaitWithStopCondition(FlowTestStep.SecondFlowTestWait, CheckSecondTestResult, CheckSecondTestFailedResult)
  52. .End(FlowTestStep.End, NullFun, _delay_1ms);
  53. return Runner.Status;
  54. }
  55. /// <summary>
  56. /// 启动第一次测试
  57. /// </summary>
  58. /// <returns></returns>
  59. private bool StartFirstFlowTest()
  60. {
  61. bool result = _firstFlowTestRoutine.Start()==RState.Running;
  62. if(result)
  63. {
  64. _commonDevice.CommonData.LeakStatus = "Testing";
  65. }
  66. else
  67. {
  68. _commonDevice.CommonData.LeakStatus = "Failed";
  69. }
  70. return result;
  71. }
  72. /// <summary>
  73. /// 检验第一次测试结果
  74. /// </summary>
  75. /// <returns></returns>
  76. private bool CheckFirstTestResult()
  77. {
  78. RState rState = _firstFlowTestRoutine.Monitor();
  79. if (rState == RState.End)
  80. {
  81. _commonDevice.CommonData.LeakStatus = "PASS";
  82. return true;
  83. }
  84. else
  85. {
  86. if(rState==RState.Timeout)
  87. {
  88. _isNeedReTest = true;
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. /// <summary>
  95. /// 检验第一次失败测试结果
  96. /// </summary>
  97. /// <returns></returns>
  98. private bool CheckFirstTestFailedResult()
  99. {
  100. RState rState = _firstFlowTestRoutine.Monitor();
  101. if(rState==RState.Failed)
  102. {
  103. _commonDevice.CommonData.LeakStatus = "Failed";
  104. _commonDevice.LeakFlowClampOffAction();
  105. _commonDevice.LeakVacuumOffAction();
  106. return true;
  107. }
  108. return false;
  109. }
  110. /// <summary>
  111. /// 启动第一次测试
  112. /// </summary>
  113. /// <returns></returns>
  114. private bool StartSecondFlowTest()
  115. {
  116. if (_isNeedReTest)
  117. {
  118. bool result = _reLeakFlowTestRoutine.Start() == RState.Running;
  119. if (!result)
  120. {
  121. _commonDevice.CommonData.LeakStatus = "Failed";
  122. }
  123. return result;
  124. }
  125. return true;
  126. }
  127. /// <summary>
  128. /// 检验第二次测试结果
  129. /// </summary>
  130. /// <returns></returns>
  131. private bool CheckSecondTestResult()
  132. {
  133. if (_isNeedReTest)
  134. {
  135. RState rState = _reLeakFlowTestRoutine.Monitor();
  136. if (rState == RState.End)
  137. {
  138. _commonDevice.CommonData.LeakStatus = "PASS";
  139. return true;
  140. }
  141. return false;
  142. }
  143. return true;
  144. }
  145. /// <summary>
  146. /// 检验第二次失败测试结果
  147. /// </summary>
  148. /// <returns></returns>
  149. private bool CheckSecondTestFailedResult()
  150. {
  151. if (_isNeedReTest)
  152. {
  153. RState rState = _reLeakFlowTestRoutine.Monitor();
  154. if (rState == RState.Failed||rState==RState.Timeout)
  155. {
  156. _commonDevice.CommonData.LeakStatus = "Failed";
  157. _commonDevice.LeakFlowClampOffAction();
  158. _commonDevice.LeakVacuumOffAction();
  159. return true;
  160. }
  161. return false;
  162. }
  163. return false;
  164. }
  165. /// <summary>
  166. /// 启动
  167. /// </summary>
  168. /// <param name="objs"></param>
  169. /// <returns></returns>
  170. public RState Start(params object[] objs)
  171. {
  172. _isNeedReTest = false;
  173. _reLeakFlowTestRoutine = new LoaderReLeakFlowTestRoutine(Module);
  174. _firstFlowTestRoutine=new LoaderLeakFirstFlowTestRoutine(Module);
  175. _commonDevice = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");
  176. Runner.Start(Module, "Flow Test");
  177. return RState.Running;
  178. }
  179. }
  180. }