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

216 lines
5.9 KiB
C#

using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using Mainframe.TMs;
using MECF.Framework.Common.Equipment;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mainframe.LLs
{
class LoadLockVentToRoutine : ModuleRoutine, IRoutine
{
enum RoutineStep
{
PumpDownToBase,
SlowVent,
CloseSlowVentValve,
TimeDelay1,
}
private LoadLock _ll;
private SicTM _tm;
private LoadLockPumpRoutine _pumpDownRoutine;
private double _ventTargetPressure;
private int _slowVentTimeout;
private int _fastVentTimeout;
private int _ventDelayTime;
private bool _needPumpDown;
private bool _needBalance;
private bool isAtmMode = false;
public LoadLockVentToRoutine()
{
Module = ModuleName.LoadLock.ToString(); ;
Name = "VentTo";
_ll = DEVICE.GetDevice<SicLoadLock>($"{ Module}.{Module}");
_tm = DEVICE.GetDevice<SicTM>($"{ModuleName.System.ToString()}.{"TM"}");
_pumpDownRoutine = new LoadLockPumpRoutine(ModuleName.LoadLock);
}
public Result Start(params object[] objs)
{
Reset();
_ventTargetPressure = SC.GetValue<double>($"TM.PressureBalance.BalancePressureForLL");
isAtmMode = SC.GetValue<bool>("System.IsATMMode");
string reason;
if (!_ll.SetFastPumpValve(false, out reason)
|| !_ll.SetSlowPumpValve(false, out reason))
{
EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}");
return Result.FAIL;
}
if (!_ll.CheckDoorClose())
{
EV.PostAlarmLog(Module, $"can not vent, lid is open");
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 (!_tm.SetFastPumpValve(false, out reason))
{
EV.PostAlarmLog(Module, $"can not vent, TM fast pump value can not close");
return Result.FAIL;
}
if (!_tm.SetTmToLLVent(false, out _))
{
EV.PostAlarmLog(Module, $"can not vent,can not close v85!");
}
_slowVentTimeout = SC.GetValue<int>("LoadLock.Vent.SlowVentTimeout");
_needPumpDown = !_ll.CheckVacuum();
//_needPumpDown = true;
Notify("Start");
return Result.RUN;
}
public Result Monitor()
{
try
{
if (isAtmMode)
{
return Result.DONE;
}
//抽到真空
if (_needPumpDown)
{
ExecuteRoutine((int)RoutineStep.PumpDownToBase, _pumpDownRoutine);
}
TimeDelay((int)RoutineStep.TimeDelay1, 1);
if (_ventTargetPressure == 0)
{
return Result.DONE;
}
SlowVent((int)RoutineStep.SlowVent, _ll, _ventTargetPressure, _slowVentTimeout);
CloseSlowVentValve((int)RoutineStep.CloseSlowVentValve, _ll);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
Notify("Finished");
return Result.DONE;
}
public void Abort()
{
_ll.SetSlowVentValve(false, out _);
_ll.SetFastVentValve(false, out _);
}
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 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());
}
}
}
}