This repository has been archived on 2023-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
Sic02/Modules/Mainframe/TMs/TMPurgeRoutine.cs

173 lines
5.3 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 TMPurgeRoutine : ModuleRoutine, IRoutine
{
enum RoutineStep
{
StartLoop,
LoopPump,
LoopVent,
StopLoop,
}
private TMPumpRoutine _pumpRoutine;
private TMVentRoutine _ventRoutine;
private TM _tm;
private IoSensor _bufferLid;
private IoSensor _tmLid;
private Devices.IoPump _pumpType;
private LoadLock _ll;
private IoInterLock _tmIoInterLock;
private Stopwatch _swTimer = new Stopwatch();
private int _routineTimeOut;
private int _purgeCount;
private bool isAtmMode = false;
public TMPurgeRoutine()
{
Module = ModuleName.TM.ToString();
Name = "Purge";
_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");
_tmIoInterLock = DEVICE.GetDevice<IoInterLock>("TM.IoInterLock");
_pumpRoutine = new TMPumpRoutine();
_ventRoutine = new TMVentRoutine();
}
public Result Start(params object[] objs)
{
Reset();
_purgeCount = SC.GetValue<int>("TM.Purge.CyclePurgeCount");
_routineTimeOut = SC.GetValue<int>("TM.Purge.RoutineTimeOut");
_pumpRoutine.Init(SC.GetValue<double>("TM.Purge.PumpBasePressure"), SC.GetValue<int>("TM.Purge.PumpDelayTime"));
_ventRoutine.Init(SC.GetValue<double>("TM.Purge.VentBasePressure"), SC.GetValue<int>("TM.Purge.VentDelayTime"));
ModuleName[] modules = new ModuleName[] { ModuleName.LoadLock, ModuleName.PM1 };
foreach (var moduleName in modules)
{
if (!_tm.CheckSlitValveClose(moduleName))
{
EV.PostAlarmLog(Module, $"Can not Purge, {moduleName} slit valve not closed");
return Result.FAIL;
}
}
if (!_ll.SetFastPumpValve(false, out string reason))
{
EV.PostAlarmLog(Module, $"Can not Purge,LL fastPump can not close");
return Result.FAIL;
}
if (!_bufferLid.Value)
{
EV.PostAlarmLog(Module, $"Can not Purge,Buffer lid is not open");
return Result.FAIL;
}
if (!_tmLid.Value)
{
EV.PostAlarmLog(Module, $"Can not Purge,TM lid is not 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 (!_tmIoInterLock.SetTMPurgeRoutineRunning(true, out reason))
{
EV.PostAlarmLog(Module, $"can not Purge,{reason}");
return Result.FAIL;
}
isAtmMode = SC.GetValue<bool>("System.IsATMMode");
_swTimer.Restart();
Notify("Start");
return Result.RUN;
}
public Result Monitor()
{
try
{
if (isAtmMode)
{
return Result.DONE;
}
CheckRoutineTimeOut();
Loop((int)RoutineStep.StartLoop, _purgeCount);
ExecuteRoutine((int)RoutineStep.LoopPump, _pumpRoutine);
ExecuteRoutine((int)RoutineStep.LoopVent, _ventRoutine);
EndLoop((int)RoutineStep.StopLoop);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
Notify($"Finished ! Elapsed time: {(int)(_swTimer.ElapsedMilliseconds / 1000)} s");
_tmIoInterLock.DoTmCyclePurgeRoutineRunning = false;
return Result.DONE;
}
public void Abort()
{
_tmIoInterLock.DoTmCyclePurgeRoutineRunning = false;
_pumpRoutine.Abort();
_ventRoutine.Abort();
}
private void CheckRoutineTimeOut()
{
if (_routineTimeOut > 10)
{
if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut)
{
Notify($"Routine TimeOut! over {_routineTimeOut} s");
throw (new RoutineFaildException());
}
}
}
}
}