PowerSupplierSetCurrentRoutine.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.PowerSupplier
  11. {
  12. public class PowerSupplierSetCurrentRoutine : RoutineBase, IRoutine
  13. {
  14. private enum SetCurrentStep
  15. {
  16. CloseOutput,
  17. SetPoint,
  18. EnableOutput,
  19. Delay,
  20. CheckCurrent,
  21. End
  22. }
  23. #region 内部变量
  24. private double _current = 0;
  25. private CellPowerSupplier _powerSupplier;
  26. #endregion
  27. /// <summary>
  28. /// 构造函数
  29. /// </summary>
  30. /// <param name="module"></param>
  31. public PowerSupplierSetCurrentRoutine(string module) : base(module)
  32. {
  33. }
  34. /// <summary>
  35. /// 中止
  36. /// </summary>
  37. public void Abort()
  38. {
  39. Runner.Stop("Manual Abort");
  40. }
  41. /// <summary>
  42. /// 监控
  43. /// </summary>
  44. /// <returns></returns>
  45. public RState Monitor()
  46. {
  47. Runner.Run(SetCurrentStep.CloseOutput, () => _powerSupplier.DisableOutput(), _delay_1ms)
  48. .Run(SetCurrentStep.SetPoint, SetCurrentPoint, CheckCurrentSetPoint, _delay_2s)
  49. .Run(SetCurrentStep.EnableOutput, () => _powerSupplier.EnableOutput(), _delay_1ms)
  50. .Wait(SetCurrentStep.CheckCurrent, () => { return _powerSupplier.PowerSupplierData.Current > 0; },_delay_2s)
  51. .End(SetCurrentStep.End, NullFun, _delay_1ms);
  52. return Runner.Status;
  53. }
  54. /// <summary>
  55. /// 关闭输出
  56. /// </summary>
  57. /// <returns></returns>
  58. private bool CloseOutput()
  59. {
  60. return _powerSupplier.DisableOutput();
  61. }
  62. /// <summary>
  63. /// 设置电流
  64. /// </summary>
  65. /// <returns></returns>
  66. private bool SetCurrentPoint()
  67. {
  68. return _powerSupplier.SetCurrent(_current);
  69. }
  70. /// <summary>
  71. /// 检验设置电源数值是否成功
  72. /// </summary>
  73. /// <returns></returns>
  74. private bool CheckCurrentSetPoint()
  75. {
  76. return Math.Abs(_powerSupplier.PowerSupplierData.SetPoint - _current) <= Math.Abs(0.1 * _current);
  77. }
  78. /// <summary>
  79. /// 启动
  80. /// </summary>
  81. /// <param name="objs"></param>
  82. /// <returns></returns>
  83. public RState Start(params object[] objs)
  84. {
  85. _current=(double)objs[0];
  86. _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(Module);
  87. return Runner.Start(Module, $"Start Set Point {_current}");
  88. }
  89. }
  90. }