123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Utilities;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using CyberX8_Core;
- using CyberX8_RT.Devices.Resistivity;
- using CyberX8_RT.Devices.Rinse;
- namespace CyberX8_RT.Modules.Rinse
- {
- public class RinseThirdStepRoutine : RoutineBase, IRoutine
- {
- private enum RinseThirdStep
- {
- Recipe_StartThirdRinseCycle,
- Recipe_ThirdRinseStartFilling,
- Recipe_ThirdRinseRecordStartWaterLevel,
- Recipe_ThirdRinseStartFillingWait,
- Recipe_ThirdRinseWaitFillingDetected,
- Recipe_ThirdRinseWaitFull,
- Recipe_ThirdRinseWaitEndFillTime,
- Recipe_ThirdRinseWaitResistivityStart,
- Recipe_ThirdRinseResistivityAveraging,
- Recipe_ThirdRinseCheckResistivity,
- Recipe_StartThirdRinseClampCycle,
- Recipe_ThirdRinseWaitClampTime,
- Recipe_ThirdRinseCycleClampOff,
- Recipe_ThirdRinseCycleClampOn,
- Recipe_ThirdRinseCycleWaitSlowDrainTime,
- Recipe_ThirdRinseCycleEnd,
- Recipe_ThirdRinseWaitDrain,
- Recipe_ThirdRinseCheckDrain,
- Recipe_ThirdRinseWaitDrainExtraTime,
- Recipe_ThirdRinseComplete,
- Recipe_Complete,
- }
- #region 内部变量
-
-
-
- private RinseDevice _device;
-
-
-
- private QdrRecipe _recipe;
-
-
-
- private double _fillingDetectStartWaterLevel;
-
-
-
- private int _concurrentFillTimeSeconds;
-
-
-
- private double _fillingStartedDelta;
-
-
-
- private int _sensorReadingFull;
-
-
-
- private int _sensorReadingEmpty;
-
-
-
- private DateTime _startFillTime;
-
-
-
- private double _clampCycleTimeSeconds;
-
-
-
- private int _normalDrainTimeSeconds;
-
-
-
- private int _numberClampCyclesToComplete;
-
-
-
- private List<double> _resistivitySample = new List<double>();
-
-
-
- private int _checkIsFillingTimeSeconds;
-
-
-
- private int _checkIsFullTimeSeconds;
-
-
- private int _readResistivityCount = 0;
-
-
-
- private string _currentStateMachine;
-
-
-
- private DateTime _startSampleTime = DateTime.Now;
-
-
-
- private DateTime _sampeIntervalTime = DateTime.Now;
-
-
-
- private bool _startSample = false;
- #endregion
-
-
-
-
- public RinseThirdStepRoutine(string module) : base(module)
- {
- }
-
-
-
-
-
- public RState Start(params object[] objects)
- {
- _startSample = false;
- _resistivitySample.Clear();
- _device = DEVICE.GetDevice<RinseDevice>(Module);
- _recipe = objects[0] as QdrRecipe;
- _concurrentFillTimeSeconds = SC.GetValue<int>("QDR.ConcurrentFillTimeSeconds");
- _fillingDetectStartWaterLevel = 0;
- _fillingStartedDelta = SC.GetValue<double>("QDR.FillingStartedDelta");
- _sensorReadingFull = SC.GetValue<int>("QDR.SensorReadingFull");
- _sensorReadingEmpty = SC.GetValue<int>("QDR.SensorReadingEmpty");
- _clampCycleTimeSeconds = SC.GetValue<double>("QDR.ClampCycleTimeSeconds");
- _numberClampCyclesToComplete = SC.GetValue<int>("QDR.NumberClampCyclesToComplete");
- _normalDrainTimeSeconds = SC.GetValue<int>("QDR.NominalDrainTimeSeconds");
- _checkIsFillingTimeSeconds = SC.GetValue<int>("QDR.NominalCheckFillWaterTimeSeconds");
- _checkIsFullTimeSeconds = SC.GetValue<int>("QDR.NominalCheckFillFullTimeSeconds");
-
- if (_checkIsFillingTimeSeconds + _checkIsFullTimeSeconds > _concurrentFillTimeSeconds)
- {
- NotifyError(eEvent.ERR_RINSE, $"configuration item 'QDR.NominalCheckFillWaterTimeSeconds' plus 'QDR.NominalCheckFillFullTimeSeconds' is large than QDR.ConcurrentFillTimeSeconds", 0);
- return RState.Failed;
- }
- if (_normalDrainTimeSeconds > _recipe.DumpTimeSeconds)
- {
- NotifyError(eEvent.ERR_RINSE, $"configuration item 'QDR.NominalDrainTimeSeconds' is large than 'recipe.DumpTimeSeconds", 0);
- return RState.Failed;
- }
- return Runner.Start(Module, "Start Rinse Third Step");
- }
-
-
-
-
- public RState Monitor()
- {
- _currentStateMachine = Runner.CurrentStep.ToString();
- _device.UpdateStateMachine(_currentStateMachine);
-
- Runner.Run(RinseThirdStep.Recipe_StartThirdRinseCycle, OpenN2ValveAndCloseDumpValve, _delay_1ms)
-
- .Run(RinseThirdStep.Recipe_ThirdRinseStartFilling, () => _device.FillValveOn(), _delay_1ms)
- .Run(RinseThirdStep.Recipe_ThirdRinseRecordStartWaterLevel, CheckFillValveOn, _delay_1ms)
- .RunDelay(RinseThirdStep.Recipe_ThirdRinseStartFillingWait, CheckFillNormalStatus, _checkIsFillingTimeSeconds * 1000)
-
- .RunDelay(RinseThirdStep.Recipe_ThirdRinseWaitFillingDetected, CheckFillFullStatus, _checkIsFullTimeSeconds * 1000)
-
-
- .Delay(RinseThirdStep.Recipe_ThirdRinseWaitEndFillTime, (_concurrentFillTimeSeconds - _checkIsFillingTimeSeconds - _checkIsFullTimeSeconds) * 1000)
-
- .Run(RinseThirdStep.Recipe_ThirdRinseWaitResistivityStart, ResistivityStart, _recipe.ResistivityStartTimeSeconds * 1000)
-
- .Run(RinseThirdStep.Recipe_ThirdRinseResistivityAveraging, ResistivityAveraging, _delay_1ms)
-
- .Wait(RinseThirdStep.Recipe_ThirdRinseCheckResistivity, ResitivitySampleResitivity, _recipe.ResistivityDurationSeconds * 1000)
-
- .Delay(RinseThirdStep.Recipe_ThirdRinseWaitClampTime, (_recipe.FinalRinsePulseClampTime - _recipe.ResistivityStartTimeSeconds - _recipe.ResistivityDurationSeconds) * 1000)
- .LoopStart(RinseThirdStep.Recipe_StartThirdRinseClampCycle, "Clamp On/Off Cycle", _numberClampCyclesToComplete, NullFun, _delay_1ms)
-
- .LoopRun(RinseThirdStep.Recipe_ThirdRinseCycleClampOff, () => _device.WaferHolderClampValveOff(), (int)(_clampCycleTimeSeconds * 1000))
-
- .LoopRun(RinseThirdStep.Recipe_ThirdRinseCycleClampOn, () => _device.WaferHolderClampValveOn(), (int)(_clampCycleTimeSeconds * 1000))
- .LoopEnd(RinseThirdStep.Recipe_ThirdRinseCycleEnd, NullFun, _delay_1ms)
-
- .Delay(RinseThirdStep.Recipe_ThirdRinseCycleWaitSlowDrainTime, (int)((_recipe.FinalRinseSlowDrainTime - _recipe.FinalRinsePulseClampTime - _clampCycleTimeSeconds * 2 * _numberClampCyclesToComplete) * 1000))
-
- .Run(RinseThirdStep.Recipe_ThirdRinseWaitDrain, StartOpenDumpValve, _delay_1ms)
- .RunDelay(RinseThirdStep.Recipe_ThirdRinseCheckDrain, CheckWaterLevelEmpty, _normalDrainTimeSeconds * 1000)
-
- .RunIf(RinseThirdStep.Recipe_ThirdRinseWaitDrainExtraTime, _recipe.DumpTimeSeconds - _normalDrainTimeSeconds > 0, NullFun, (_recipe.DumpTimeSeconds - _normalDrainTimeSeconds) * 1000)
-
- .Run(RinseThirdStep.Recipe_ThirdRinseComplete, () => _device.WasteValveOff(), _delay_1ms)
- .End(RinseThirdStep.Recipe_Complete, NullFun, _delay_1ms);
- return Runner.Status;
- }
-
-
-
-
- private bool OpenN2ValveAndCloseDumpValve()
- {
- bool result = true;
- if (_recipe.Step2N2BubbleOn)
- {
- result = _device.N2ValveOn();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "Open N2 Valve error", 0);
- return false;
- }
- }
- result = _device.DrainValveOff();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "Close Dump Valve error", 0);
- }
- return result;
- }
-
-
-
-
- private bool CheckFillValveOn()
- {
- _startFillTime = DateTime.Now;
- _fillingDetectStartWaterLevel = _device.RinseData.WaterLevel;
- LOG.WriteLog(eEvent.INFO_RINSE, Module, $"Start Fill Valve WaterLevel {_fillingDetectStartWaterLevel}");
- return true;
- }
-
-
-
-
- private bool CheckFillNormalStatus()
- {
- double currentWaterLevel = _device.RinseData.WaterLevel;
- return (currentWaterLevel - _fillingDetectStartWaterLevel) > _fillingStartedDelta;
- }
-
-
-
-
- private bool CheckFillFullStatus()
- {
- double currentWaterLevel = _device.RinseData.WaterLevel;
- bool result = currentWaterLevel > _sensorReadingFull;
- return result;
- }
-
-
-
-
- private bool StartOpenDumpValve()
- {
- CheckNeedCloseMetalDrain();
- bool result = _device.DrainValveOn();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "Open Dump valve error", 0);
- return false;
- }
- return result;
- }
-
-
-
-
- private bool CheckWaterLevelEmpty()
- {
- double currentWaterLevel = _device.RinseData.WaterLevel;
- bool reseult = currentWaterLevel < _sensorReadingEmpty;
- if (!reseult)
- {
- NotifyError(eEvent.ERR_RINSE, $"current water level: {currentWaterLevel} is large than sensorReadingEmpty: {_sensorReadingEmpty}", 0);
- }
- return reseult;
- }
-
-
-
-
- private void CheckNeedCloseMetalDrain()
- {
-
- if (_recipe.Step1NumberOfRinse + _recipe.Step2NumberOfRinse + 1 > _recipe.Step1NumberOfDumpToMetalDrain)
- {
- bool result = _device.WasteValveOn();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "Close Metal Drain Valve error", 0);
- }
- }
- }
-
-
-
-
- private bool ResistivityStart()
- {
- bool result = true;
- result = _device.FillValveOff();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "Fill Valve Off error", 0);
- return false;
- }
- if (_recipe.Step2N2BubbleOn)
- {
- result = _device.N2ValveOff();
- if (!result)
- {
- NotifyError(eEvent.ERR_RINSE, "N2 Valve Off error", 0);
- return false;
- }
- }
- return result;
- }
-
-
-
-
- private bool ResistivityAveraging()
- {
- if (_recipe.ResistivityDurationSeconds == 0)
- {
- _resistivitySample.Add(GetResitivity());
- }
- else
- {
- _startSampleTime = DateTime.Now;
- _sampeIntervalTime = DateTime.Now;
- _startSample = true;
- }
- return true;
- }
-
-
-
-
- private bool ResitivitySampleResitivity()
- {
- if (!_startSample)
- {
- return true;
- }
- int sampleTotalCount = (int)Math.Ceiling(_recipe.ResistivityDurationSeconds / 0.1);
-
- if (DateTime.Now.Subtract(_sampeIntervalTime).TotalMilliseconds >= 100)
- {
- _sampeIntervalTime = DateTime.Now;
- _readResistivityCount++;
- _resistivitySample.Add(GetResitivity());
- }
-
- if (DateTime.Now.Subtract(_startSampleTime).TotalMilliseconds >= _recipe.ResistivityDurationSeconds * 1000 - 100)
- {
- bool result = CheckResistivity();
- if (!result)
- {
- Runner.Stop("Sample Resitiviy abormal", true);
- }
- return result;
- }
- return false;
- }
-
- private double GetResitivity()
- {
- double resistivity = 0;
- ResistivityController resistivityController = DEVICE.GetDevice<ResistivityController>(_device.RinseItem.ResistivityID);
- if (resistivityController != null)
- {
- try
- {
- resistivity = double.Parse(resistivityController.ResisitivityValue.Trim());
- }
- catch
- {
- resistivity = 0;
- }
- }
- return resistivity;
- }
-
-
-
-
- private bool CheckResistivity()
- {
- if (_recipe.ResistivityMegaOhms == 0)
- {
- _resistivitySample.Clear();
- return true;
- }
- double resistivityAverageValue = _resistivitySample.Average();
- if ((_resistivitySample.Count == 1 && _resistivitySample[0] < _recipe.ResistivityMegaOhms) || resistivityAverageValue < _recipe.ResistivityMegaOhms)
- {
- NotifyError(eEvent.ERR_RINSE, $"The detected resistivity value is abnormal,: {resistivityAverageValue}", 0);
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_RINSE, Module, $"The detected resistivity value is : {resistivityAverageValue}");
- }
- _resistivitySample.Clear();
- return true;
- }
-
-
-
- public void Abort()
- {
- Runner.Stop("Manual abort");
- }
- }
- }
|