using Aitex.Core.RT.Device;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using MECF.Framework.Common.Routine;
using CyberX8_Core;
using CyberX8_RT.Devices.AXIS;
using CyberX8_RT.Devices.PUF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MECF.Framework.Common.Utilities;
namespace CyberX8_RT.Modules.PUF
{
public class PufPlaceVacuumCheckRoutine : RoutineBase, IRoutine
{
private enum PlaceVacuumStep
{
ChuckOut,
CheckChuckOut,
VacuumOff,
VacuumDelay,
ChuckIn,
CheckChuckIn,
VacuumOn,
Delay,
VacuumCheck,
End
}
#region 常量
private const string SideA = "SideA";
private const string SideB = "SideB";
private const string WAFER_ABSENT = "WaferAbsent";
#endregion
#region 内部变量
private PufVacuum _vacuum;
private PufChuckRoutine _chuckRoutine;
private string _side = "SideA";
///
/// 是否显示Routine错误
///
private bool _showError = true;
///
/// 第几次
///
private int _times=1;
///
/// 延迟时间
///
private int _chuckValveSwitchingTimeDelayInMilliSeconds = 100;
///
/// 是否处于模拟器
///
private bool _isSimulator = false;
#endregion
///
/// 构造函数
///
///
public PufPlaceVacuumCheckRoutine(string module) : base(module)
{
_isSimulator = SC.GetValue("System.IsSimulatorMode");
_chuckRoutine = new PufChuckRoutine(module);
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("Manual abort");
}
///
/// 监控
///
///
public RState Monitor()
{
Runner.Run(PlaceVacuumStep.ChuckOut, () => { return _chuckRoutine.Start(true) == RState.Running; }, NullFun, 100)
.WaitWithStopCondition(PlaceVacuumStep.CheckChuckOut, () => CommonFunction.CheckRoutineEndState(_chuckRoutine), () => CommonFunction.CheckRoutineStopState(_chuckRoutine))
.Run(PlaceVacuumStep.VacuumOff, VacuumOff, _delay_1ms)
.Delay(PlaceVacuumStep.VacuumDelay,500)
.Run(PlaceVacuumStep.ChuckIn, () => { return _chuckRoutine.Start(false) == RState.Running; }, NullFun, 100)
.WaitWithStopCondition(PlaceVacuumStep.CheckChuckIn, () => CommonFunction.CheckRoutineEndState(_chuckRoutine), () => CommonFunction.CheckRoutineStopState(_chuckRoutine))
.Run(PlaceVacuumStep.VacuumOn, VacuumOn, _delay_1ms)
.Delay(PlaceVacuumStep.Delay, _chuckValveSwitchingTimeDelayInMilliSeconds)
.Run(PlaceVacuumStep.VacuumCheck, CheckWaferPresent,NullFun, _delay_1ms,_showError)
.End(PlaceVacuumStep.End, NullFun, _delay_1ms);
return Runner.Status;
}
///
/// 关闭Vacuum
///
///
private bool VacuumOff()
{
if (_side == SideA)
{
return _vacuum.VacuumAOff();
}
else if (_side == SideB)
{
return _vacuum.VacuumBOff();
}
return false;
}
///
/// 打开Vacuum
///
///
private bool VacuumOn()
{
if (_side == SideA)
{
return _vacuum.VacuumAOn();
}
else if (_side == SideB)
{
return _vacuum.VacuumBOn();
}
return false;
}
///
/// 检验存在Wafer
///
///
private bool CheckWaferPresent()
{
if(_isSimulator)
{
return true;
}
if (_side == SideA)
{
return _vacuum.ChuckAVacuumStatus == WAFER_ABSENT;
}
else if (_side == SideB)
{
return _vacuum.ChuckBVacuumStatus == WAFER_ABSENT;
}
else
{
return false;
}
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
_side = objs[0].ToString();
_showError = objs.Length > 1 ? (bool)objs[1] : true;
_times = objs.Length > 2 ? (int)objs[2] : 1;
_vacuum = DEVICE.GetDevice($"{Module}.Vacuum");
_chuckValveSwitchingTimeDelayInMilliSeconds = SC.GetValue($"{Module}.ChuckValveSwitchingTimeDelayInMilliSeconds");
return Runner.Start(Module, $"Start {_times} Place Vacuum Check");
}
}
}