478 lines
14 KiB
C#
478 lines
14 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Aitex.Core.RT.Device;
|
|
using Aitex.Core.RT.Device.Unit;
|
|
using Aitex.Core.RT.Event;
|
|
using Aitex.Core.RT.Routine;
|
|
using Aitex.Core.RT.SCCore;
|
|
using Mainframe.Devices;
|
|
using Mainframe.LLs;
|
|
using MECF.Framework.Common.Equipment;
|
|
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
|
|
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
|
|
|
|
namespace Mainframe.TMs
|
|
{
|
|
public class TMVentRoutine : ModuleRoutine, IRoutine
|
|
{
|
|
enum RoutineStep
|
|
{
|
|
SetMFC,
|
|
OpenFastVent,
|
|
OpenSlowVent,
|
|
TimeStayATM,
|
|
CloseFastVent,
|
|
CloseSlowVent,
|
|
|
|
CloseTurboPumpValves, //Fast pump, backing valve, iso valve
|
|
CloseValveDelay,
|
|
|
|
TurboPumpOff,
|
|
|
|
Vent,
|
|
VentDelay,
|
|
|
|
CloseVentValves,
|
|
CloseVentValveDelay,
|
|
TimeDelay,
|
|
}
|
|
|
|
private double _ventBasePressure;
|
|
private double _slowFastVentSwitchPressure;
|
|
private int _slowVentTimeout;
|
|
private int _fastVentTime;
|
|
private int _ventDelayTime;
|
|
private bool _useSettingValue;
|
|
private int _routineTimeOut;
|
|
|
|
private SicTM _tm;
|
|
private IoSensor _bufferLid;
|
|
private IoSensor _tmLid;
|
|
private Devices.IoPump _pumpType;
|
|
private LoadLock _ll;
|
|
private IoSensor _preHeatLid;
|
|
private SicPM.Devices.IoMFC _mfc40;
|
|
private IoInterLock _tmIoInterLock;
|
|
|
|
private double _mfcTargetSetPoint;
|
|
|
|
private Stopwatch _swTimer = new Stopwatch();
|
|
public TMVentRoutine( )
|
|
{
|
|
Module = ModuleName.TM.ToString();
|
|
Name = "Vent";
|
|
_tm = DEVICE.GetDevice<SicTM>($"{ ModuleName.System.ToString()}.{ Module}");
|
|
_ll = DEVICE.GetDevice<SicLoadLock>($"LoadLock.LoadLock");
|
|
_bufferLid = DEVICE.GetDevice<IoSensor>($"TM.BufferLidClosed");
|
|
_tmLid = DEVICE.GetDevice<IoSensor>($"TM.TMLidClosed");
|
|
_pumpType = DEVICE.GetDevice<Devices.IoPump>($"TM.TMPump");
|
|
_preHeatLid = DEVICE.GetDevice<IoSensor>($"TM.PreHeatStationLidClosed");
|
|
_mfc40 = DEVICE.GetDevice<SicPM.Devices.IoMFC>($"TM.Mfc40");
|
|
_tmIoInterLock = DEVICE.GetDevice<IoInterLock>("TM.IoInterLock");
|
|
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
_useSettingValue = false;
|
|
}
|
|
|
|
public void Init(double basePressure, int ventDelayTime)
|
|
{
|
|
_ventBasePressure = basePressure;
|
|
_ventDelayTime = ventDelayTime;
|
|
_useSettingValue = true;
|
|
}
|
|
|
|
|
|
public bool Initalize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public Result Start(params object[] objs)
|
|
{
|
|
Reset();
|
|
|
|
|
|
|
|
string reason;
|
|
if (!_tm.SetSlowPumpValve(false, out reason) || !_tm.SetFastPumpValve(false, out reason) )
|
|
{
|
|
EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}");
|
|
return Result.FAIL;
|
|
}
|
|
|
|
if (_tm.CheckAtm())
|
|
{
|
|
EV.PostInfoLog(Module, $"{_tm.Module} in atm, vent skipped");
|
|
return Result.DONE;
|
|
}
|
|
|
|
ModuleName[] modules = new ModuleName[] { ModuleName.LoadLock, ModuleName.PM1 };
|
|
foreach (var moduleName in modules)
|
|
{
|
|
if (!_tm.CheckSlitValveClose(moduleName))
|
|
{
|
|
EV.PostAlarmLog(Module, $"Can not vent, {moduleName} slit valve not closed");
|
|
return Result.FAIL;
|
|
}
|
|
}
|
|
|
|
_routineTimeOut = SC.GetValue<int>("TM.Vent.RoutineTimeOut");
|
|
_mfcTargetSetPoint = SC.GetValue<double>("TM.Vent.MfcFlow40");
|
|
_slowFastVentSwitchPressure = SC.GetValue<double>("TM.Vent.SlowFastVentSwitchPressure");
|
|
_slowVentTimeout = SC.GetValue<int>("TM.Vent.SlowVentTimeout");
|
|
_fastVentTime = SC.GetValue<int>("TM.Vent.FastVentTimeout");
|
|
if (!_useSettingValue)
|
|
{
|
|
_ventBasePressure = SC.GetValue<double>("TM.Vent.VentBasePressure");
|
|
_ventDelayTime = SC.GetValue<int>("TM.Vent.VentDelayTime");
|
|
}
|
|
if (!_ll.SetFastPumpValve(false, out reason))
|
|
{
|
|
EV.PostAlarmLog(Module, $"Can not vent,LL fastPump can not close");
|
|
return Result.FAIL;
|
|
}
|
|
if (!_bufferLid.Value)
|
|
{
|
|
EV.PostAlarmLog(Module, $"Can not vent,Buffer lid is not open");
|
|
return Result.FAIL;
|
|
}
|
|
if (!_tmLid.Value)
|
|
{
|
|
EV.PostAlarmLog(Module, $"Can not vent,TM lid is not open");
|
|
return Result.FAIL;
|
|
}
|
|
if (_pumpType.IsAlarm)
|
|
{
|
|
EV.PostAlarmLog(Module, $"can not vent,TM pump alarm");
|
|
return Result.FAIL;
|
|
}
|
|
if (!_pumpType.IsRunning)
|
|
{
|
|
EV.PostAlarmLog(Module, $"can not vent,TM pump is not running");
|
|
return Result.FAIL;
|
|
}
|
|
if (!_tm.SetTmToLLVent(false, out _))
|
|
{
|
|
EV.PostAlarmLog(Module, $"can not vent,can not close v85!");
|
|
}
|
|
if (!_tm.SetTMRoughBypass(false, out _))
|
|
{
|
|
EV.PostAlarmLog(Module, $"can not vent,can not close v121!");
|
|
}
|
|
if (!_tmIoInterLock.SetTMVentRoutineRunning(true, out reason))
|
|
{
|
|
EV.PostAlarmLog(Module, $"can not vent,{reason}");
|
|
return Result.FAIL;
|
|
}
|
|
|
|
_swTimer.Restart();
|
|
Notify("Start");
|
|
return Result.RUN;
|
|
}
|
|
|
|
public Result Monitor()
|
|
{
|
|
try
|
|
{
|
|
CheckRoutineTimeOut();
|
|
|
|
SetMFCToSetPoint((int)RoutineStep.SetMFC, _mfc40, _mfcTargetSetPoint);
|
|
|
|
OpenSlowVent((int)RoutineStep.OpenSlowVent, _tm, _slowFastVentSwitchPressure, _slowVentTimeout);
|
|
|
|
OpenFastVent((int)RoutineStep.OpenFastVent, _tm, _ventBasePressure, _fastVentTime);
|
|
TimeDelay((int)RoutineStep.TimeStayATM, _ventDelayTime);
|
|
|
|
CloseFastVent((int)RoutineStep.CloseFastVent, _tm);
|
|
|
|
CloseSlowVentValve((int)RoutineStep.CloseSlowVent, _tm);
|
|
|
|
|
|
}
|
|
catch (RoutineBreakException)
|
|
{
|
|
return Result.RUN;
|
|
}
|
|
catch (RoutineFaildException)
|
|
{
|
|
_tm.SetFastVentValve(false, out _);
|
|
_tm.SetSlowVentValve(false, out _);
|
|
return Result.FAIL;
|
|
}
|
|
|
|
|
|
Notify($"Finished ! Elapsed time: {(int)(_swTimer.ElapsedMilliseconds / 1000)} s");
|
|
_tmIoInterLock.DoTmVentUpRoutineRunning = false;
|
|
|
|
return Result.DONE;
|
|
}
|
|
|
|
public void Abort()
|
|
{
|
|
_tmIoInterLock.DoTmVentUpRoutineRunning = false;
|
|
_tm.SetFastVentValve(false, out _);
|
|
_tm.SetSlowVentValve(false, out _);
|
|
}
|
|
|
|
|
|
private void CheckRoutineTimeOut()
|
|
{
|
|
if (_routineTimeOut > 10)
|
|
{
|
|
if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut)
|
|
{
|
|
Notify($"Routine TimeOut! over {_routineTimeOut} s");
|
|
throw (new RoutineFaildException());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetMFCToSetPoint(int id, SicPM.Devices.IoMFC _mfc,double setPoint)
|
|
{
|
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|
{
|
|
Notify($"Set MFC value to default");
|
|
_mfc.Ramp(setPoint, 0);
|
|
return true;
|
|
});
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void OpenFastVent(int id, TM tm, double basePressure, int timeout)
|
|
{
|
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|
{
|
|
Notify($"Open {tm.Name} slow vent valve");
|
|
|
|
if (!tm.SetFastVentValve(true, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}, () =>
|
|
{
|
|
return tm.ChamberPressure >= basePressure;
|
|
|
|
}, timeout * 1000);
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|
{
|
|
tm.SetFastVentValve(false, out string _);
|
|
|
|
Stop($"{tm.Name} pressure can not vent to {basePressure} in {timeout} seconds");
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void CloseFastPumpValve(int id, TM tm)
|
|
{
|
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|
{
|
|
Notify($"Close {tm.Name} fast pump valve");
|
|
|
|
if (!tm.SetFastPumpValve(false, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void OpenSlowVent(int id, TM tm, double basePressure, int timeout)
|
|
{
|
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|
{
|
|
Notify($"Open {tm.Name} slow vent valve");
|
|
|
|
if (!tm.SetSlowVentValve(true, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}, () =>
|
|
{
|
|
return tm.ChamberPressure >= basePressure;
|
|
|
|
}, timeout * 1000);
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|
{
|
|
tm.SetFastVentValve(false, out string _);
|
|
|
|
Stop($"{tm.Name} pressure can not vent to {basePressure} in {timeout} seconds");
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void CloseSlowVentValve(int id, TM tm)
|
|
{
|
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|
{
|
|
Notify($"Close {tm.Name} fast pump valve");
|
|
|
|
if (!tm.SetSlowVentValve(false, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void CloseFastVent(int id, TM tm)
|
|
{
|
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|
{
|
|
Notify($"Close {tm.Name} vent valves");
|
|
|
|
if (!tm.SetFastVentValve(false, out string reason) )
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void CloseTurboPumpValves(int id, TM tm)
|
|
{
|
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|
{
|
|
Notify($"Close {tm.Name} turbo backing valve and iso valve");
|
|
|
|
if (!tm.SetTurboPumpBackingValve(false, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
if (!tm.SetTurboPumpIsoValve(false, out reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
public void TurboPumpOff(int id, TM tm, int timeout)
|
|
{
|
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|
{
|
|
Notify($"turn off {tm.Name} turbo pump");
|
|
|
|
if (!tm.TurboPumpOff())
|
|
{
|
|
Stop("Can not turn off turbo pump");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}, () =>
|
|
{
|
|
if (tm.CheckTurboPumpError())
|
|
{
|
|
Stop($"{tm.Name} can not turn off turbo pump, pump error");
|
|
return null;
|
|
}
|
|
return tm.CheckTurboPumpOff();
|
|
|
|
}, timeout * 1000);
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|
{
|
|
Stop($"{tm.Name} can not turn off turbo pump in {timeout} seconds");
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
}
|
|
}
|