Sic02-new/Modules/Mainframe/LLs/LoadLockVentRoutine.cs

388 lines
12 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.TMs;
using MECF.Framework.Common.Equipment;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
namespace Mainframe.LLs
{
public class LoadLockVentRoutine : ModuleRoutine, IRoutine
{
enum RoutineStep
{
SlowVent,
FastVent,
VentDelay,
CloseSlowVentValve,
CloseFastVentValve,
CloseValveDelay,
//Equal,
//CloseEqualValve,
}
private double _ventBasePressure;
private double _ventSwitchPressure;
private int _slowVentTimeout;
private int _fastVentTimeout;
private int _ventDelayTime;
private int _routineTimeOut;
private LoadLock _ll;
private SicTM _tm;
private Devices.IoPump _pumpType;
private IoInterLock _tmIoInterLock;
private bool _useSettingValue;
private Stopwatch _swTimer = new Stopwatch();
public LoadLockVentRoutine(ModuleName module)
{
Module = module.ToString();
Name = "Vent";
_ll = DEVICE.GetDevice<SicLoadLock>($"{ Module}.{Module}");
_tm = DEVICE.GetDevice<SicTM>($"{ModuleName.System.ToString()}.{"TM"}");
_pumpType = DEVICE.GetDevice<Devices.IoPump>($"TM.TMPump");
_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 Result Start(params object[] objs)
{
Reset();
string reason;
if (_ll.CheckAtm())
{
EV.PostInfoLog(Module, $"{_ll.Module} in atm, vent skipped");
return Result.DONE;
}
if (!_tm.CheckSlitValveClose(ModuleHelper.Converter(_ll.Module)))
{
EV.PostAlarmLog(Module, $"can not vent, slit valve is open");
return Result.FAIL;
}
if (!_ll.CheckDoorClose())
{
EV.PostAlarmLog(Module, $"can not vent, lid is 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.SetFastPumpValve(false, out reason))
{
EV.PostAlarmLog(Module, $"can not vent, TM fast pump value can not close");
return Result.FAIL;
}
if (!_ll.SetFastPumpValve(false, out reason)
|| !_ll.SetSlowPumpValve(false, out reason))
{
EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}");
return Result.FAIL;
}
if (!_tm.SetTmToLLVent(false, out _))
{
EV.PostAlarmLog(Module, $"can not vent,can not close v85!");
}
if (!_tmIoInterLock.SetLLVentRoutineRunning(true, out reason))
{
EV.PostAlarmLog(Module, $"can not vent,{reason}");
return Result.FAIL;
}
_ventSwitchPressure = SC.GetValue<double>("LoadLock.Vent.SlowFastVentSwitchPressure");
_slowVentTimeout = SC.GetValue<int>("LoadLock.Vent.SlowVentTimeout");
_fastVentTimeout = SC.GetValue<int>("LoadLock.Vent.FastVentTimeout");
if (!_useSettingValue)
{
_ventBasePressure = SC.GetValue<double>("LoadLock.Vent.VentBasePressure");
_ventDelayTime = SC.GetValue<int>("LoadLock.Vent.VentDelayTime");
}
_routineTimeOut = SC.GetValue<int>("LoadLock.Vent.RoutineTimeOut");
_swTimer.Restart();
Notify("Start");
return Result.RUN;
}
public Result Monitor()
{
try
{
CheckRoutineTimeOut();
SlowVent((int)RoutineStep.SlowVent, _ll, _ventSwitchPressure, _slowVentTimeout);
FastVent((int)RoutineStep.FastVent, _ll, _ventBasePressure, _fastVentTimeout);
TimeDelay((int)RoutineStep.VentDelay, _ventDelayTime);
CloseFastVentValve((int)RoutineStep.CloseFastVentValve, _ll);
CloseSlowVentValve((int)RoutineStep.CloseSlowVentValve, _ll);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
_ll.SetSlowVentValve(false, out _);
_ll.SetFastVentValve(false, out _);
return Result.FAIL;
}
Notify($"Finished ! Elapsed time: {(int)(_swTimer.ElapsedMilliseconds / 1000)} s");
_tmIoInterLock.DoLLVentUpRoutineRunning = false;
return Result.DONE;
}
public void Abort()
{
_tmIoInterLock.DoLLVentUpRoutineRunning = false;
_ll.SetFastPumpValve(false, out string reason);
_ll.SetSlowPumpValve(false, out reason);
_ll.SetFastVentValve(false, out reason);
_ll.SetSlowVentValve(false, out reason);
}
private void CheckRoutineTimeOut()
{
if (_routineTimeOut > 10)
{
if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut)
{
Notify($"Routine TimeOut! over {_routineTimeOut} s");
throw (new RoutineFaildException());
}
}
}
public void SlowVent(int id, LoadLock ll, double switchPressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {ll.Name} slow vent valve to {switchPressure} mbar");
if (!_ll.SetSlowVentValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return ll.ChamberPressure >= switchPressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
_ll.SetSlowVentValve(false, out string _);
Stop($"{ll.Name} pressure can not vent to {switchPressure} mbar in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void FastVent(int id, LoadLock ll, double basePressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {ll.Name} fast vent valve to {basePressure} mbar");
if (!_ll.SetFastVentValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return ll.ChamberPressure >= basePressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
_ll.SetSlowVentValve(false, out string _);
_ll.SetFastVentValve(false, out string _);
Stop($"{ll.Name} pressure can not vent to {basePressure} mbar in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void CloseSlowVentValve(int id, LoadLock ll)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {ll.Name} slow vent valve");
if (!_ll.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 CloseFastVentValve(int id, LoadLock ll)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {ll.Name} fast vent valve");
if (!_ll.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 OpenEqualValve(int id, LoadLock ll, int time)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {ll.Name} equal vent valve");
if (!_ll.SetEqualVentValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return true;
}, time * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
throw (new RoutineBreakException());
}
else
throw (new RoutineBreakException());
}
}
public void CloseEqualValve(int id, LoadLock ll, int time)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Close {ll.Name} equal vent valve");
if (!_ll.SetEqualVentValve(false, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return true;
}, time * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
throw (new RoutineBreakException());
}
else
throw (new RoutineBreakException());
}
}
}
}