using Aitex.Core.RT.Device;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using CyberX8_Core;
using CyberX8_RT.Devices.Metal;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.Common.Routine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CyberX8_RT.Modules.Metal
{
public class CurrentShortTestRoutine : RoutineBase, IRoutine
{
private enum CurrentShortStep
{
SetSideACurrent,
SetSideAWait,
CheckSideA,
SetSideBCurrent,
SetSideBWait,
CheckSideB,
End
}
#region 常量
private const string SIDE_A = "SideA";
///
/// 1A
///
private const double CURRENT_1A = 1;
#endregion
#region 内部变量
///
/// S&H 设备
///
private MetalCellDevice _device;
///
///
///
private double _shortTestThreshold = 0.1;
#endregion
///
/// 构造函数
///
///
public CurrentShortTestRoutine(string module) : base(module)
{
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("Manual Abort");
}
/// ru
/// 监控
///
///
public RState Monitor()
{
Runner.Run(CurrentShortStep.SetSideACurrent, SetSideACurrent, _delay_1ms)
.WaitWithStopCondition(CurrentShortStep.SetSideAWait,()=> { return _device.SideAPowerSupplier.Status == RState.End; }
,()=>{ return _device.SideAPowerSupplier.Status == RState.Failed; },_delay_5s)
.Wait(CurrentShortStep.CheckSideA, () => CheckCurrent(_device.SideAPowerSupplier.PowerSupplierData.Current), _delay_1s)
.Run(CurrentShortStep.SetSideBCurrent, SetSideBCurrent, _delay_1ms)
.WaitWithStopCondition(CurrentShortStep.SetSideBWait, () => { return _device.SideBPowerSupplier.Status == RState.End; }
, () => { return _device.SideBPowerSupplier.Status == RState.Failed; }, _delay_5s)
.Wait(CurrentShortStep.CheckSideB, () => CheckCurrent(_device.SideBPowerSupplier.PowerSupplierData.Current), _delay_1s)
.End(CurrentShortStep.End, ClosePower, _delay_1ms);
return Runner.Status;
}
///
/// 设置A电流
///
///
private bool SetSideACurrent()
{
return _device.SideAPowerSupplier.SetCurrentAndOutput(CURRENT_1A);
}
///
/// 检验电流
///
///
///
private bool CheckCurrent(double current)
{
return current >= _shortTestThreshold;
}
///
/// 设置B电流
///
///
private bool SetSideBCurrent()
{
return _device.SideBPowerSupplier.SetCurrentAndOutput(CURRENT_1A);
}
///
/// 关闭电源
///
///
private bool ClosePower()
{
_device.SideAPowerSupplier.DisableOperation("", null);
_device.SideBPowerSupplier.DisableOperation("", null);
return true;
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
_device = DEVICE.GetDevice(Module);
_shortTestThreshold = SC.GetValue("Metal.ShortTestThreshold");
return Runner.Start(Module, "Start Current Short Test");
}
}
}