CurrentShortTestRoutine.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. bool isSimulator = SC.GetValue<bool>("System.IsSimulatorMode");
  92. if (isSimulator)
  93. {
  94. return true;
  95. }
  96. LOG.WriteLog(eEvent.INFO_METAL, Module, $"current is {current}");
  97. return current < _shortTestThreshold;
  98. }
  99. /// <summary>
  100. /// 设置B电流
  101. /// </summary>
  102. /// <returns></returns>
  103. private bool SetSideBCurrent()
  104. {
  105. return _device.SideBPowerSupplier.SetCurrentAndOutput(CURRENT_1A);
  106. }
  107. /// <summary>
  108. /// 关闭电源
  109. /// </summary>
  110. /// <returns></returns>
  111. private bool ClosePower()
  112. {
  113. _device.SideAPowerSupplier.DisableOperation("", null);
  114. _device.SideBPowerSupplier.DisableOperation("", null);
  115. return true;
  116. }
  117. /// <summary>
  118. /// 启动
  119. /// </summary>
  120. /// <param name="objs"></param>
  121. /// <returns></returns>
  122. public RState Start(params object[] objs)
  123. {
  124. _device = DEVICE.GetDevice<MetalCellDevice>(Module);
  125. _shortTestThreshold = SC.GetValue<double>("Metal.ShortTestThreshold");
  126. return Runner.Start(Module, "Start Current Short Test");
  127. }
  128. }
  129. }