CurrentShortTestRoutine.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using CyberX8_Core;
  6. using CyberX8_RT.Devices.Metal;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  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.Metal
  15. {
  16. public class CurrentShortTestRoutine : RoutineBase, IRoutine
  17. {
  18. private enum CurrentShortStep
  19. {
  20. SetSideACurrent,
  21. SetSideAWait,
  22. CheckSideA,
  23. SetSideBCurrent,
  24. SetSideBWait,
  25. CheckSideB,
  26. End
  27. }
  28. #region 常量
  29. private const string SIDE_A = "SideA";
  30. /// <summary>
  31. /// 1A
  32. /// </summary>
  33. private const double CURRENT_1A = 1;
  34. #endregion
  35. #region 内部变量
  36. /// <summary>
  37. /// S&H 设备
  38. /// </summary>
  39. private MetalCellDevice _device;
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. private double _shortTestThreshold = 0.1;
  44. #endregion
  45. /// <summary>
  46. /// 构造函数
  47. /// </summary>
  48. /// <param name="module"></param>
  49. public CurrentShortTestRoutine(string module) : base(module)
  50. {
  51. }
  52. /// <summary>
  53. /// 中止
  54. /// </summary>
  55. public void Abort()
  56. {
  57. Runner.Stop("Manual Abort");
  58. }
  59. /// <summary>ru
  60. /// 监控
  61. /// </summary>
  62. /// <returns></returns>
  63. public RState Monitor()
  64. {
  65. Runner.Run(CurrentShortStep.SetSideACurrent, SetSideACurrent, _delay_1ms)
  66. .WaitWithStopCondition(CurrentShortStep.SetSideAWait,()=> { return _device.SideAPowerSupplier.Status == RState.End; }
  67. ,()=>{ return _device.SideAPowerSupplier.Status == RState.Failed; },_delay_5s)
  68. .Wait(CurrentShortStep.CheckSideA, () => CheckCurrent(_device.SideAPowerSupplier.PowerSupplierData.Current), _delay_1s)
  69. .Run(CurrentShortStep.SetSideBCurrent, SetSideBCurrent, _delay_1ms)
  70. .WaitWithStopCondition(CurrentShortStep.SetSideBWait, () => { return _device.SideBPowerSupplier.Status == RState.End; }
  71. , () => { return _device.SideBPowerSupplier.Status == RState.Failed; }, _delay_5s)
  72. .Wait(CurrentShortStep.CheckSideB, () => CheckCurrent(_device.SideBPowerSupplier.PowerSupplierData.Current), _delay_1s)
  73. .End(CurrentShortStep.End, ClosePower, _delay_1ms);
  74. return Runner.Status;
  75. }
  76. /// <summary>
  77. /// 设置A电流
  78. /// </summary>
  79. /// <returns></returns>
  80. private bool SetSideACurrent()
  81. {
  82. return _device.SideAPowerSupplier.SetCurrentAndOutput(CURRENT_1A);
  83. }
  84. /// <summary>
  85. /// 检验电流
  86. /// </summary>
  87. /// <param name="current"></param>
  88. /// <returns></returns>
  89. private bool CheckCurrent(double current)
  90. {
  91. return current >= _shortTestThreshold;
  92. }
  93. /// <summary>
  94. /// 设置B电流
  95. /// </summary>
  96. /// <returns></returns>
  97. private bool SetSideBCurrent()
  98. {
  99. return _device.SideBPowerSupplier.SetCurrentAndOutput(CURRENT_1A);
  100. }
  101. /// <summary>
  102. /// 关闭电源
  103. /// </summary>
  104. /// <returns></returns>
  105. private bool ClosePower()
  106. {
  107. _device.SideAPowerSupplier.DisableOperation("", null);
  108. _device.SideBPowerSupplier.DisableOperation("", null);
  109. return true;
  110. }
  111. /// <summary>
  112. /// 启动
  113. /// </summary>
  114. /// <param name="objs"></param>
  115. /// <returns></returns>
  116. public RState Start(params object[] objs)
  117. {
  118. _device = DEVICE.GetDevice<MetalCellDevice>(Module);
  119. _shortTestThreshold = SC.GetValue<double>("Metal.ShortTestThreshold");
  120. return Runner.Start(Module, "Start Current Short Test");
  121. }
  122. }
  123. }