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.Facilities;
using CyberX8_RT.Devices.Resistivity;
using CyberX8_RT.Devices.Rinse;
using MECF.Framework.Common.CommonData.Rinse;
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.Rinse
{
public class RinseKeepwetRoutine : RoutineBase, IRoutine
{
private const int LOTTRACK_TIME = 1000;
private const string DI_WATER_PRESSURE_VALUE = "DiWaterPressure";
private enum KeepwetStep
{
CloseDumpValve,
KeepWetStart,
KeepWetWait,
CloseFillValve,
KeepWetSlowDrain,
End
}
#region 内部变量
///
/// 低于Clamp的水位
///
private double _belowClampWaterLevel = 0;
///
/// 设备对象
///
private RinseDevice _device;
///
/// 注满数值
///
private int _sensorReadingFull;
///
/// lock track time
///
private DateTime _lotTackTime = DateTime.Now;
///
/// LotTrack数据
///
private List _datas = new List();
///
/// LotTrack数据
///
public List RinseLotTrackDatas { get { return _datas; } }
///
/// Facilities
///
private SystemFacilities _facilities;
#endregion
///
/// 构造函数
///
///
public RinseKeepwetRoutine(string module) : base(module)
{
}
///
/// 中止
///
public void Abort()
{
_device.FillValveOff();
_device.DrainValveOn();
Runner.Stop("Manual Abort");
}
///
/// 监控
///
///
public RState Monitor()
{
LottrackRecord();
Runner.Run(KeepwetStep.CloseDumpValve, () => _device.DrainValveOff(), _delay_1ms)
.Run(KeepwetStep.KeepWetStart, () => _device.FillValveOn(), _delay_1ms)
.Wait(KeepwetStep.KeepWetWait, CheckFillFullStatus)
.Run(KeepwetStep.CloseFillValve, () => _device.FillValveOff(), _delay_1ms)
.Wait(KeepwetStep.KeepWetSlowDrain, CheckDrainStatus)
.End(KeepwetStep.End, NullFun, _delay_1ms);
return Runner.Status;
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
_belowClampWaterLevel = SC.GetValue("QDR.QDRKeepWetBelowClampWaterLevel");
_sensorReadingFull = SC.GetValue("QDR.SensorReadingFull");
_device = DEVICE.GetDevice(Module);
_facilities = DEVICE.GetDevice("System.Facilities");
if (_facilities == null)
{
LOG.WriteLog(eEvent.ERR_RINSE, Module, "Facility is null");
return RState.Failed;
}
_datas.Clear();
return Runner.Start(Module, "Start Rinse Keepwet");
}
/// 记录Lottrack
///
private void LottrackRecord()
{
//记录Lottrack
if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
{
AddLotTrackData();
_lotTackTime = DateTime.Now;
}
}
///
/// 检验是否注满
///
///
private bool CheckFillFullStatus()
{
double currentWaterLevel = _device.RinseData.WaterLevel;
bool result = currentWaterLevel > _sensorReadingFull;
return result;
}
///
/// 检验是否排空
///
///
private bool CheckDrainStatus()
{
double currentWaterLevel = _device.RinseData.WaterLevel;
bool result = currentWaterLevel < _belowClampWaterLevel;
return result;
}
///
/// 获取Lot Track数据
///
///
private void AddLotTrackData()
{
RinseLotTrackData data = new RinseLotTrackData();
data.TimeStamp = DateTime.Now;
data.WaterLevel = _device.RinseData.WaterLevel;
data.DIFillEnabled = _device.RinseData.FillValve;
data.DumpEnabled = _device.RinseData.DrainValve;
data.WaterPressure = _facilities.GetCommonLimitDataByName(DI_WATER_PRESSURE_VALUE).Value;
ResistivityController resistivityController = DEVICE.GetDevice(_device.RinseItem.ResistivityID);
if (resistivityController != null)
{
try
{
data.Resistivity = double.Parse(resistivityController.ResisitivityValue.Trim());
}
catch
{
data.Resistivity = 0;
}
}
_datas.Add(data);
}
}
}