using Aitex.Core.RT.Device;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Routine;
using CyberX8_Core;
using CyberX8_RT.Devices.Metal;
using CyberX8_RT.Devices.PowerSupplier;
using MECF.Framework.Common.CommonData.Metal;
using MECF.Framework.Common.CommonData;
using MECF.Framework.Common.CommonData.PowerSupplier;
using MECF.Framework.Common.Device.PowerSupplier;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.Common.Routine;
using MECF.Framework.Common.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CyberX8_RT.Modules.Metal
{
public class CompactEmbranceRunRecipeRoutine : RoutineBase, IRoutine
{
private enum RecipeStep
{
WaferHolderClampOn,
RunRecipe,
RunRecipeWait,
WaferHolderUnclampOn,
End
}
#region 内部变量
///
/// recipe
///
private DepRecipe _recipe;
///
/// 单面
///
private string _side;
///
/// Metal设备
///
private CompactMembranMetalDevice _device;
///
/// RunRecipe routine
///
private ReservoirRunRecipeRoutine _runRecipeRoutine;
#endregion
#region 属性
///
/// A面电量
///
public double AnodeAUsage { get { return _runRecipeRoutine.AnodeAUsage; } }
///
/// B面电量
///
public double AnodeBUsage { get { return _runRecipeRoutine.AnodeBUsage; } }
///
/// LotTrack数据
///
public List MetalLotTrackDatas { get { return _runRecipeRoutine.MetalLotTrackDatas; } }
///
/// LotTrack文件头数据
///
public LotTrackFileHeaderCommonData MetalLotTrackHeaderDatas { get { return _runRecipeRoutine.MetalLotTrackHeaderDatas; } }
#endregion
///
/// 构造函数
///
///
public CompactEmbranceRunRecipeRoutine(string module) : base(module)
{
_runRecipeRoutine=new ReservoirRunRecipeRoutine(module);
}
///
/// 中止
///
public void Abort()
{
_runRecipeRoutine.Abort();
Runner.Stop("Manual Abort");
}
///
/// 监控
///
///
public RState Monitor()
{
Runner.Run(RecipeStep.WaferHolderClampOn, () => _device.WaferHolderClampOn("", null), () => _device.MetalDeviceData.WHClamp&&!_device.MetalDeviceData.WHUnclamp,_delay_1s)
.Run(RecipeStep.RunRecipe,()=>_runRecipeRoutine.Start(new object[] {_recipe,_side })==RState.Running,_delay_1ms)
.WaitWithStopCondition(RecipeStep.RunRecipeWait,()=>CommonFunction.CheckRoutineEndState(_runRecipeRoutine),CheckRunRecipeStopStatus)
.Run(RecipeStep.WaferHolderUnclampOn, () => _device.WaferHolderUnclampOn("", null), () => _device.MetalDeviceData.WHUnclamp && !_device.MetalDeviceData.WHClamp, _delay_1s)
.End(RecipeStep.End, NullFun, _delay_1ms);
return Runner.Status;
}
///
/// RunRecipe停止状态
///
///
public bool CheckRunRecipeStopStatus()
{
bool result = CommonFunction.CheckRoutineStopState(_runRecipeRoutine);
if (result)
{
AddLotTrackData();
if (_device.SideAPowerSupplier != null)
{
_device.SideAPowerSupplier.DisableOperation("", null);
}
if (_device.SideBPowerSupplier != null)
{
_device.SideBPowerSupplier.DisableOperation("", null);
}
}
return result;
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
_recipe=objs[0] as DepRecipe;
if (_recipe == null)
{
LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
return RState.Failed;
}
if (objs.Length>1)
{
_side = objs[1].ToString();
}
_device = DEVICE.GetDevice(Module);
if(!CheckPreCondition())
{
return RState.Failed;
}
return Runner.Start(Module, "Start run recipe");
}
///
/// 检验前置条件
///
///
private bool CheckPreCondition()
{
if(_recipe==null)
{
LOG.WriteLog(eEvent.ERR_METAL, Module, "Recipe is null");
return false;
}
if(_recipe.CurrentRampProfileSteps.Count==0)
{
LOG.WriteLog(eEvent.ERR_METAL, Module, "Recipe RampProfileSteps count is 0");
return false;
}
return true;
}
///
/// 获取Lot Track数据
///
///
public void AddLotTrackData()
{
_runRecipeRoutine.AddLotTrackData();
}
}
}