using System.Diagnostics; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Devices; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs; using SicModules.LLs; using SicModules.TMs.Routines.Base; using IoInterLock = SicModules.Devices.IoInterLock; namespace SicModules.TMs.Routines { public class TMPurgeRoutine : TMBaseRoutine { enum RoutineStep { StartLoop, LoopPump, LoopVent, StopLoop, //Pump CloseV77, CloseV80, SlowPump, FastPump, VaccumDelay, CloseValves, CLoseSlowValue, //Vent CloseV81, CloseV82, SetMFC1, SetMFC2, OpenSlowVent, OpenFastVent, OpenVent, TimeStayATM, CloseSlowVent } //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 double _slowFastPumpSwitchPressure; private double _pumpDelayTime; private double _pumpBasePressure; private int _pumpTimeOut; private double _ventBasePressure; private double _slowFastVentSwitchPressure; private int _ventTimeOut; private double _mfc60Default1; private double _mfc60Default2; private IoMFC _mfc60; private double _ventDelayTime; public TMPurgeRoutine() { Module = ModuleName.TM.ToString(); Name = "Purge"; _tm = DEVICE.GetDevice($"{ ModuleName.System.ToString()}.{ Module}"); _ll = DEVICE.GetDevice($"LoadLock.LoadLock"); _bufferLid = DEVICE.GetDevice($"Buffer.BufferLidClosed"); _tmLid = DEVICE.GetDevice($"TM.TMLidClosed"); _pumpType = DEVICE.GetDevice($"TM.TMPump1"); _tmIoInterLock = DEVICE.GetDevice("TM.IoInterLock"); _mfc60 = DEVICE.GetDevice($"TM.Mfc60"); //_pumpRoutine = new TMPumpRoutine(); //_ventRoutine = new TMVentRoutine(); } public override Result Start(params object[] objs) { Reset(); if (objs.Length == 2 && int.TryParse(objs[0].ToString(), out int purgeCount) && int.TryParse(objs[1].ToString(), out int pumpDelayTime)) { _purgeCount = purgeCount; _pumpDelayTime = pumpDelayTime; _ventBasePressure = SC.GetValue("TM.PressureBalance.BalancePressure"); } else { _purgeCount = SC.GetValue("TM.Purge.CyclePurgeCount"); _pumpDelayTime = SC.GetValue("TM.Purge.PumpDelayTime"); _ventBasePressure = SC.GetValue("TM.Purge.VentBasePressure"); } _routineTimeOut = SC.GetValue("TM.Purge.RoutineTimeOut"); _slowFastPumpSwitchPressure = SC.GetValue("TM.Purge.SlowFastPumpSwitchPressure"); _pumpBasePressure = SC.GetValue("TM.Purge.PumpBasePressure"); _pumpTimeOut = SC.GetValue("TM.Purge.PumpTimeOut"); _ventDelayTime = SC.GetValue("TM.Purge.VentDelayTime"); _mfc60Default1 = SC.GetValue("TM.Purge.Mfc60Default1"); _mfc60Default2 = SC.GetValue("TM.Purge.Mfc60Default2"); _slowFastVentSwitchPressure = SC.GetValue("TM.Purge.SlowFastVentSwitchPressure"); _ventTimeOut = SC.GetValue("TM.Purge.VentTimeout"); ModuleName[] modules = new ModuleName[] { ModuleName.LoadLock, ModuleName.PM1, ModuleName.PM2, ModuleName.UnLoad }; foreach (var moduleName in modules) { if (!_tm.CheckSlitValveClose(moduleName)) { EV.PostAlarmLog(Module, $"Can not Purge, {moduleName} slit valve not closed"); 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 string reason)) { EV.PostAlarmLog(Module, $"can not Purge,{reason}"); return Result.FAIL; } if (SC.GetValue("System.IsATMMode")) { return Result.DONE; } _swTimer.Restart(); Notify("Start"); return Result.RUN; } public override Result Monitor() { try { CheckRoutineTimeOut(); Loop((int)RoutineStep.StartLoop, _purgeCount); //ExecuteRoutine((int)RoutineStep.LoopPump, _pumpRoutine); //ExecuteRoutine((int)RoutineStep.LoopVent, _ventRoutine); //先Pump { //关闭V77 CloseTMVent((int)RoutineStep.CloseV77); //关闭V80 //CloseBufferVent((int)RoutineStep.CloseV80); //打开V82,等待压力低于200mbar(可配置) OpenSlowPump((int)RoutineStep.SlowPump, _tm, _slowFastPumpSwitchPressure, _pumpTimeOut); //打开V81,压力达到0mbar(可配置) OpenFastPump((int)RoutineStep.FastPump, _tm, _pumpBasePressure, _pumpTimeOut); //等待5s(可配置) TimeDelay((int)RoutineStep.VaccumDelay, _pumpDelayTime); //关闭 CloseFastPump((int)RoutineStep.CloseValves, _tm); CloseSlowPump((int)RoutineStep.CLoseSlowValue, _tm); } //再Vent { //关闭V80 //CloseBufferVent((int)RoutineStep.CloseV80); //关闭V81 CloseFastPump((int)RoutineStep.CloseV81); //关闭V82 CloseSlowPump((int)RoutineStep.CloseV82); //设定MFC60慢充流量 SetMFCToSetPoint((int)RoutineStep.SetMFC1, _mfc60, _mfc60Default1); ////打开V77,等待压力大于200mbar //OpenSlowVent((int)RoutineStep.OpenSlowVent, _tm, _slowFastVentSwitchPressure, _slowVentTimeout); ////设定MFC60快充流量 //SetMFCToSetPoint((int)RoutineStep.SetMFC2, _mfc60, _mfc60Default2); //等待压力大于1020mbar //OpenFastVent((int)RoutineStep.OpenFastVent, _tm, _ventBasePressure, _fastVentTime); //充气过程中检查是否到达打开快充流量的条件 OpenVent((int)RoutineStep.OpenVent, _tm, _ventBasePressure, _slowFastVentSwitchPressure, _mfc60Default2, _ventTimeOut); //等待5s TimeDelay((int)RoutineStep.TimeStayATM, _ventDelayTime); //关闭V77 CloseSlowVentValve((int)RoutineStep.CloseSlowVent, _tm); } EndLoop((int)RoutineStep.StopLoop); //关闭V81 CloseFastPump((int)RoutineStep.CloseV81); //关闭V82 CloseSlowPump((int)RoutineStep.CloseV82); //关闭V77 CloseSlowVentValve((int)RoutineStep.CloseSlowVent, _tm); } 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 override void Abort() { _tmIoInterLock.DoTmCyclePurgeRoutineRunning = false; //_pumpRoutine.Abort(); //_ventRoutine.Abort(); base.Abort(); } private void CheckRoutineTimeOut() { if (_routineTimeOut > 10) { if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut) { EV.PostAlarmLog(Module, $"Routine TimeOut! over {_routineTimeOut} s"); throw (new RoutineFaildException()); } } } } }