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

451 lines
15 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.Robot.MAG7;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
namespace Mainframe.LLs
{
public class LoadLockPurgeRoutine : ModuleRoutine, IRoutine
{
enum RoutineStep
{
SlowPump, FastPump, PumpDelay, CloseFastValve, CloseSlowValve,
SlowVent, FastVent, VentDelay, CloseFastVentValve, CloseSlowVentValve,
StartLoop,
LoopPump,
LoopVent,
StopLoop,
TimeDelay1,
TimeDelay2
}
private int _purgeCount;
private int _routineTimeOut;
private double _pumpSwitchPressure;
private double _pumpBasePressure;
private int _pumpDelayTime;
private int _pumpTimeOut;
private double _ventSwitchPressure;
private double _ventBasePressure;
private int _ventDelayTime;
private int _ventTimeOut;
private LoadLockPumpRoutine _pumpRoutine;
private LoadLockVentRoutine _ventRoutine;
private Devices.IoPump _pumpType;
private LoadLock _ll;
private SicTM _tm;
private IoInterLock _tmIoInterLock;
private bool _needfastVent = true;
private bool _needfastPump = true;
private Stopwatch _swTimer = new Stopwatch();
public LoadLockPurgeRoutine(ModuleName module )
{
Module = module.ToString();
Name = "Purge";
_pumpType = DEVICE.GetDevice<Devices.IoPump>($"TM.TMPump");
_ll = DEVICE.GetDevice<SicLoadLock>($"{ Module}.{Module}");
_tm = DEVICE.GetDevice<SicTM>($"{ModuleName.System}.TM");
_tmIoInterLock = DEVICE.GetDevice<IoInterLock>("TM.IoInterLock");
}
public void Init()
{
}
public Result Start(params object[] objs)
{
Reset();
_purgeCount = SC.GetValue<int>("LoadLock.Purge.CyclePurgeCount");
_routineTimeOut = SC.GetValue<int>("LoadLock.Purge.RoutineTimeOut");
_pumpSwitchPressure = SC.GetValue<double>("LoadLock.Pump.SlowFastPumpSwitchPressure");
_pumpBasePressure = SC.GetValue<double>("LoadLock.Purge.PumpBasePressure");
_pumpDelayTime = SC.GetValue<int>("LoadLock.Purge.PumpDelayTime");
_pumpTimeOut = SC.GetValue<int>("LoadLock.Purge.PumpTimeOut");
_ventSwitchPressure= SC.GetValue<double>("LoadLock.Vent.SlowFastVentSwitchPressure");
_ventBasePressure = SC.GetValue<double>("LoadLock.Purge.VentBasePressure");
_ventDelayTime = SC.GetValue<int>("LoadLock.Purge.VentDelayTime");
_ventTimeOut = _pumpTimeOut;
_needfastVent = _ventBasePressure > _ventSwitchPressure;
_needfastPump = _pumpBasePressure < _pumpSwitchPressure;
if (!_ll.CheckDoorClose())
{
EV.PostAlarmLog(Module, $"can not purge, lid is open");
return Result.FAIL;
}
if (_pumpType.IsAlarm)
{
EV.PostAlarmLog(Module, $"can not purge,TM pump alarm");
return Result.FAIL;
}
if (!_pumpType.IsRunning)
{
EV.PostAlarmLog(Module, $"can not purge,TM pump is not running");
return Result.FAIL;
}
if (!_tm.SetFastPumpValve(false, out string reason))
{
EV.PostAlarmLog(Module, $"can not purge, TM fast pump value can not close");
return Result.FAIL;
}
if (!_tm.CheckSlitValveClose(ModuleHelper.Converter(_ll.Module)))
{
EV.PostAlarmLog(Module, $"Can not purge, slit valve is open");
return Result.FAIL;
}
if (!_tm.SetTmToLLVent(false, out _))
{
EV.PostAlarmLog(Module, $"can not vent,can not close v85!");
}
if (!_tmIoInterLock.SetLLPurgeRoutineRunning(true, out reason))
{
EV.PostAlarmLog(Module, $"can not purge,{reason}");
return Result.FAIL;
}
_swTimer.Restart();
Notify("Start");
return Result.RUN;
}
public Result Monitor()
{
try
{
CheckRoutineTimeOut();
Loop((int)RoutineStep.StartLoop, _purgeCount);
SlowPump((int)RoutineStep.SlowPump, _ll, _pumpSwitchPressure, _pumpTimeOut);
FastPump((int)RoutineStep.FastPump, _ll, _pumpBasePressure, _pumpTimeOut);
TimeDelay((int)RoutineStep.PumpDelay, _pumpDelayTime);
CloseFastPumpValve((int)RoutineStep.CloseFastValve, _ll);
CloseSlowPumpValve((int)RoutineStep.CloseSlowValve, _ll);
TimeDelay((int)RoutineStep.TimeDelay1, 1);
if (_needfastVent)
{
SlowVent((int)RoutineStep.SlowVent, _ll, _ventSwitchPressure, _ventTimeOut);
FastVent((int)RoutineStep.FastVent, _ll, _ventBasePressure, _ventTimeOut);
CloseFastVentValve((int)RoutineStep.CloseFastVentValve, _ll);
CloseSlowVentValve((int)RoutineStep.CloseSlowVentValve, _ll);
}
else
{
SlowVent((int)RoutineStep.SlowVent, _ll, _ventBasePressure, _ventTimeOut);
CloseSlowVentValve((int)RoutineStep.CloseSlowVentValve, _ll);
}
TimeDelay((int)RoutineStep.VentDelay, _ventDelayTime);
EndLoop((int)RoutineStep.StopLoop);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
Notify($"Finished ! Elapsed time: {(int)(_swTimer.ElapsedMilliseconds / 1000)} s");
_tmIoInterLock.DoLLCyclePurgeRoutineRunning = false;
return Result.DONE;
}
public void Abort()
{
_tmIoInterLock.DoLLCyclePurgeRoutineRunning = 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 SlowPump(int id, LoadLock ll, double switchPressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {ll.Name} slow pump valve to {switchPressure} mbar");
if (!_ll.SetSlowPumpValve(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.SetSlowPumpValve(false, out string _);
Stop($"{ll.Name} pressure can not pump to {switchPressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void FastPump(int id, LoadLock ll, double basePressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {ll.Name} fast pump valve to {basePressure} mbar");
if (!_ll.SetFastPumpValve(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.SetSlowPumpValve(false, out string _);
_ll.SetFastPumpValve(false, out string _);
Stop($"{ll.Name} pressure can not pump to {basePressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void CloseSlowPumpValve(int id, LoadLock ll)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {ll.Name} slow pump valve");
if (!_ll.SetSlowPumpValve(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 CloseFastPumpValve(int id, LoadLock ll)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {ll.Name} fast pump valve");
if (!_ll.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 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());
}
}
}
}