12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Routine;
- using CyberX8_Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CyberX8_RT.Devices.PowerSupplier
- {
- public class PowerSupplierSetCurrentRoutine : RoutineBase, IRoutine
- {
- private enum SetCurrentStep
- {
- CloseOutput,
- SetPoint,
- EnableOutput,
- Delay,
- CheckCurrent,
- End
- }
- #region 内部变量
- private double _current = 0;
- private CellPowerSupplier _powerSupplier;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PowerSupplierSetCurrentRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(SetCurrentStep.CloseOutput, () => _powerSupplier.DisableOutput(), _delay_1ms)
- .Run(SetCurrentStep.SetPoint, SetCurrentPoint, CheckCurrentSetPoint, _delay_2s)
- .Run(SetCurrentStep.EnableOutput, () => _powerSupplier.EnableOutput(), _delay_1ms)
- .Wait(SetCurrentStep.CheckCurrent, () => { return _powerSupplier.PowerSupplierData.Current > 0; },_delay_2s)
- .End(SetCurrentStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 关闭输出
- /// </summary>
- /// <returns></returns>
- private bool CloseOutput()
- {
- return _powerSupplier.DisableOutput();
- }
- /// <summary>
- /// 设置电流
- /// </summary>
- /// <returns></returns>
- private bool SetCurrentPoint()
- {
- return _powerSupplier.SetCurrent(_current);
- }
- /// <summary>
- /// 检验设置电源数值是否成功
- /// </summary>
- /// <returns></returns>
- private bool CheckCurrentSetPoint()
- {
- return Math.Abs(_powerSupplier.PowerSupplierData.SetPoint - _current) <= Math.Abs(0.1 * _current);
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _current=(double)objs[0];
- _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(Module);
- return Runner.Start(Module, $"Start Set Point {_current}");
- }
- }
- }
|