| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 | 
							- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Routine;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.Routine;
 
- using CyberX8_Core;
 
- using CyberX8_RT.Devices.AXIS;
 
- using CyberX8_RT.Devices.Loader;
 
- using System;
 
- using System.Collections.Generic;
 
- using Aitex.Core.RT.Log;
 
- using MECF.Framework.Common.CommonData.Loader;
 
- using MECF.Framework.Common.WaferHolder;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- namespace CyberX8_RT.Modules.Loader
 
- {
 
-     public class LoaderLoadSideRoutine : RoutineBase, IRoutine
 
-     {
 
-         private enum LoadStep
 
-         {
 
-             SideLoad,
 
-             SideAllLoadWait,
 
-             LeakTest,
 
-             LeakTestWait,
 
-             RotationGoToTRNPA,
 
-             RotationGoToTRNPAWait,
 
-             UnclampWaferHolder,
 
-             End
 
-         }
 
-         #region 常量
 
-         private const string SIDE_A = "SideA";
 
-         private const string SIDE_B = "SideB";
 
-         private const int LOTTRACK_TIME = 1000;
 
-         #endregion
 
-         #region 内部变量
 
-         private JetAxisBase _rotationAxis;
 
-         private LoaderLoadRoutine _sideLoadRoutine;
 
-         private LoaderCommonDevice _loaderCommonDevice;
 
-         private bool _isSideLoaded = false;
 
-         private bool _isSideStop = false;
 
-         /// <summary>
 
-         /// lotTrack time
 
-         /// </summary>
 
-         private DateTime _lotTackTime = DateTime.Now;
 
-         /// <summary>
 
-         /// Loader Common
 
-         /// </summary>
 
-         private LoaderCommonDevice _loaderCommon;
 
-         /// <summary>
 
-         /// LoaderSide 
 
-         /// </summary>
 
-         private LoaderSideDevice _loaderSide;
 
-         /// <summary>
 
-         /// Loader LotTrackData
 
-         /// </summary>
 
-         private List<LoaderLotTrackData> _datas = new List<LoaderLotTrackData>();
 
-         /// <summary>
 
-         /// Flow LotTrackData
 
-         /// </summary>
 
-         private List<LoaderFlowLotTrackData> _flowDatas = new List<LoaderFlowLotTrackData>();
 
-         /// <summary>
 
-         /// Loader Start and Finish Time
 
-         /// </summary>
 
-         private List<DateTime> _loadTimeList = new List<DateTime>();
 
-         /// <summary>
 
-         /// 
 
-         /// </summary>
 
-         private string _side = "";
 
-         /// <summary>
 
-         /// WaferSize
 
-         /// </summary>
 
-         private int _waferSize;
 
-         /// <summary>
 
-         /// load是否完成
 
-         /// </summary>
 
-         private bool _loadComplete = false;
 
-         /// <summary>
 
-         /// 完成后运行
 
-         /// </summary>
 
-         private string _completeSide = "TRNPA";
 
-         /// <summary>
 
-         /// Wafer组
 
-         /// </summary>
 
-         private string _waferGroup = "";
 
-         #endregion
 
-         #region 属性
 
-         /// <summary>
 
-         /// UnLoad LotTrackData
 
-         /// </summary>
 
-         public List<LoaderLotTrackData> LoadLotTrackDatas { get { return _datas; } }
 
-         /// <summary>
 
-         /// Flow LotTrackData
 
-         /// </summary>
 
-         public List<LoaderFlowLotTrackData> FlowLotTrackDatas { get { return _flowDatas; } }
 
-         /// <summary>
 
-         /// LoadTimeList
 
-         /// </summary>
 
-         public List<DateTime> LoadTimeList { get { return _loadTimeList; } }
 
-         /// <summary>
 
-         /// Wafer组
 
-         /// </summary>
 
-         public string WaferGroup { get { return _waferGroup; } }
 
-         /// <summary>
 
-         /// is SideA
 
-         /// </summary>
 
-         public bool IsSideA { get { return _side == SIDE_A ? true : false; } }
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         /// <param name="module"></param>
 
-         public LoaderLoadSideRoutine(string module) : base(module)
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// 中止
 
-         /// </summary>
 
-         public void Abort()
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// 监控
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public RState Monitor()
 
-         {
 
-             //记录Lot track
 
-             LottrackRecord();
 
-             Runner.Run(LoadStep.SideLoad, () => StartLoadRoutine(_sideLoadRoutine,_isSideLoaded), _delay_1ms)
 
-                 .WaitWithStopCondition(LoadStep.SideAllLoadWait, CheckLoadAllRoutineEndStatus,CheckLoadAllRoutineStopStatus)
 
-                 .Run(LoadStep.LeakTest, StartFlowTest, _delay_1ms)
 
-                 .WaitWithStopCondition(LoadStep.LeakTestWait, CheckFlowTestEndStatus, CheckFlowTestStopStatus)
 
-                 .RunIf(LoadStep.RotationGoToTRNPA,_loadComplete,RotationGotoTransporterA,_delay_1s)
 
-                 .WaitWithStopConditionIf(LoadStep.RotationGoToTRNPAWait,_loadComplete, CheckRotationPositionStatus,CheckRotationPositionRunStop)
 
-                 .RunIf(LoadStep.UnclampWaferHolder,_loadComplete, WaferHolderClampOffAction,_delay_1ms)
 
-                 .End(LoadStep.End, UpdateWaferHolderUse, _delay_1ms);
 
-             return Runner.Status;
 
-         }
 
-         /// <summary>
 
-         /// 检验Rotation移动状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckRotationPositionStatus()
 
-         {
 
-             return _rotationAxis.Status == RState.End;
 
-         }
 
-         /// <summary>
 
-         /// 检验Rotation是否还在运动
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckRotationPositionRunStop()
 
-         {
 
-             bool result= _rotationAxis.Status == RState.Failed||_rotationAxis.Status==RState.Timeout;
 
-             if (result)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, "rotation goto position failed", 2);
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 启动load routine
 
-         /// </summary>
 
-         /// <param name="loadRoutine"></param>
 
-         /// <returns></returns>
 
-         private bool StartLoadRoutine(LoaderLoadRoutine loadRoutine,bool isSideLoaded)
 
-         {
 
-             if (isSideLoaded)
 
-             {
 
-                 return true;
 
-             }
 
-             bool result= loadRoutine.Start()==RState.Running;
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, loadRoutine.ErrorMsg, 0);
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 检验LoadAll完成状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckLoadAllRoutineEndStatus()
 
-         {
 
-             bool sideResult = true;
 
-             if (!_isSideLoaded)
 
-             {
 
-                 sideResult = CheckLoadRoutineEndStatus(_sideLoadRoutine);
 
-             }
 
-             if (sideResult)
 
-             {
 
-                 _loadTimeList.Add(DateTime.Now);
 
-             }
 
-             return sideResult;
 
-         }
 
-         /// <summary>
 
-         /// 检验LoadAll停止状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckLoadAllRoutineStopStatus()
 
-         {
 
-             bool sideComplete = false;
 
-             if(!_isSideLoaded&&!_isSideStop)
 
-             {
 
-                 RState ret = _sideLoadRoutine.Monitor();
 
-                 _isSideStop = ret == RState.Failed || ret == RState.Timeout;
 
-                 sideComplete = (ret != RState.Running);
 
-                 if (_isSideStop)
 
-                 {
 
-                     NotifyError(eEvent.ERR_LOADER, $"load A failed\r\n{_sideLoadRoutine.ErrorMsg}", 0);
 
-                 }
 
-             }
 
-             return _isSideStop;
 
-         }
 
-         /// <summary>
 
-         /// 检验routine完成状态
 
-         /// </summary>
 
-         /// <param name="loadRoutine"></param>
 
-         /// <returns></returns>
 
-         private bool CheckLoadRoutineEndStatus(LoaderLoadRoutine loadRoutine)
 
-         {
 
-             return loadRoutine.Monitor() == RState.End;
 
-         }
 
-         /// <summary>
 
-         /// 启动Flowtest
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool StartFlowTest()
 
-         {
 
-             bool result= _loaderCommonDevice.StartFlowTestAction();
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, "Start Flow Test failed", 1);
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 检验FlowTest停止状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckFlowTestStopStatus()
 
-         {
 
-             if (_loaderCommonDevice.Status == RState.Failed || _loaderCommonDevice.Status == RState.Timeout)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, "Flow Test failed",1);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验FlowTest完成状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckFlowTestEndStatus()
 
-         {
 
-             bool result = _loaderCommonDevice.Status == RState.End;
 
-             if (result)
 
-             {
 
-                 _flowDatas = _loaderCommonDevice.FlowLotTrackDatas;
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// Rotation 运动至TRNPA
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool RotationGotoTransporterA()
 
-         {
 
-             bool result = _rotationAxis.PositionStation(_completeSide, false);
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, $"rotation start goto {_completeSide} failed", 2);
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// Wafer Holder Clamp Off
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WaferHolderClampOffAction()
 
-         {
 
-             bool result = _loaderCommonDevice.WaferHolderClampOffAction();
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Clamp Off failed", 2);
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 更新WaferHolder总用量
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool UpdateWaferHolderUse()
 
-         {
 
-             WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder("Loader");
 
-             if(waferHolderInfo != null)
 
-             {
 
-                 waferHolderInfo.TotalUses += 1;
 
-                 WaferHolderManager.Instance.UpdateWaferHolderInfo(waferHolderInfo);
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 启动
 
-         /// </summary>
 
-         /// <param name="objs"></param>
 
-         /// <returns></returns>
 
-         public RState Start(params object[] objs)
 
-         {
 
-             _side = objs[0].ToString();
 
-             _loadComplete=(bool)objs[1];
 
-             if (objs.Length > 2)
 
-             {
 
-                 _completeSide= objs[2].ToString();
 
-             }
 
-             if (objs.Length > 3)
 
-             {
 
-                 _waferGroup= objs[3].ToString();
 
-             }
 
-             LoaderEntity loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
 
-             if (_side == SIDE_A)
 
-             {
 
-                 _waferSize = loaderEntity.SideAWaferSize;
 
-             }
 
-             else
 
-             {
 
-                 _waferSize = loaderEntity.SideBWaferSize;
 
-             }
 
-             InitializeParameters();
 
-             _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");
 
-             _loaderSide = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.{_side}");
 
-             //清除lotTrack数据
 
-             _datas.Clear();
 
-             _flowDatas.Clear();
 
-             _loadTimeList.Clear();
 
-             _loadTimeList.Add(DateTime.Now);
 
-             
 
-             return Runner.Start(Module, "Start LoadAll");
 
-         }
 
-         /// <summary>
 
-         /// 初始化参数
 
-         /// </summary>
 
-         private void InitializeParameters()
 
-         {
 
-             _isSideLoaded = false;
 
-             _isSideStop = false;
 
-             _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
 
-             _sideLoadRoutine = new LoaderLoadRoutine(ModuleName.Loader1.ToString(), _side);
 
-             _loaderCommonDevice = DEVICE.GetDevice<LoaderCommonDevice>($"{ModuleName.Loader1}.Common");
 
-         }
 
-         /// <summary>
 
-         /// 重试
 
-         /// </summary>
 
-         /// <param name="step"></param>
 
-         public RState Retry(int step)
 
-         {
 
-             InitializeParameters();
 
-             List<Enum> preStepIds = new List<Enum>();
 
-             _datas.Clear();
 
-             if (step == 0 || step == -1)
 
-             {
 
-                 string side = _side == SIDE_A ? "A" : "B";
 
-                 _isSideLoaded = CheckSideLoadCondition(side, step,false);
 
-                 return Runner.Retry(LoadStep.SideLoad, preStepIds, Module, "LoadAll Retry");
 
-             }
 
-             else if (step == 1)
 
-             {
 
-                 AddPreSteps(LoadStep.LeakTest, preStepIds);
 
-                 return Runner.Retry(LoadStep.LeakTest, preStepIds, Module, $"LoadAll step {LoadStep.LeakTest} start Retry");
 
-             }
 
-             else
 
-             {
 
-                 AddPreSteps(LoadStep.RotationGoToTRNPA, preStepIds);
 
-                 return Runner.Retry(LoadStep.RotationGoToTRNPA, preStepIds, Module, $"LoadAll step {LoadStep.RotationGoToTRNPA} start Retry");
 
-             }           
 
-         }
 
-         /// <summary>
 
-         /// 忽略前
 
-         /// </summary>
 
-         /// <param name="step"></param>
 
-         /// <param name="preStepIds"></param>
 
-         private void AddPreSteps(LoadStep step, List<Enum> preStepIds)
 
-         {
 
-             for (int i = 0; i < (int)step; i++)
 
-             {
 
-                 preStepIds.Add((LoadStep)i);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 检验前面Unload完成状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool CheckCompleteCondition(int index)
 
-         {
 
-             string side = _side == SIDE_A ? "A" : "B";
 
-             if (!CheckSideLoadCondition(side, index,true))
 
-             {
 
-                 return false;
 
-             }
 
-             JetAxisBase loaderRotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
 
-             double loaderRotationPosition = loaderRotationAxis.MotionData.MotorPosition;
 
-             if (!loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPA"))
 
-             {
 
-                 NotifyError(eEvent.ERR_LOADER, $"loader rotation {loaderRotationPosition} not in TRNPA", index);
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 检验Side Unload情况 
 
-         /// </summary>
 
-         /// <param name="side"></param>
 
-         /// <param name="index"></param>
 
-         /// <returns></returns>
 
-         private bool CheckSideLoadCondition(string side, int index,bool showError)
 
-         {
 
-             JetAxisBase shuttleAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Shuttle{side}");
 
-             double shuttlePosition = shuttleAxis.MotionData.MotorPosition;
 
-             if (!shuttleAxis.CheckPositionInStationIgnoreWaferSize(shuttlePosition, "MID"))
 
-             {
 
-                 if (showError)
 
-                 {
 
-                     NotifyError(eEvent.ERR_LOADER, $"shuttle{side} {shuttlePosition} is not in mid", index);
 
-                 }
 
-                 return false;
 
-             }
 
-             JetAxisBase tiltAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Tilt{side}");
 
-             double tiltPosition = tiltAxis.MotionData.MotorPosition;
 
-             if (tiltAxis.CheckPositionIsInStation(tiltPosition, "VERT"))
 
-             {
 
-                 if (showError)
 
-                 {
 
-                     NotifyError(eEvent.ERR_LOADER, $"tilt{side} {tiltPosition} is not in VERT", index);
 
-                 }
 
-                 return false;
 
-             }
 
-             JetAxisBase crsAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.LS{side}");
 
-             double crsPosition = crsAxis.MotionData.MotorPosition;
 
-             if (!crsAxis.CheckPositionIsInStation(crsPosition, "Setup"))
 
-             {
 
-                 if (showError)
 
-                 {
 
-                     NotifyError(eEvent.ERR_LOADER, $"LS{side} {crsPosition} is not in Setup", index);
 
-                 }
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 记录Lottrack
 
-         /// </summary>
 
-         private void LottrackRecord()
 
-         {
 
-             //记录Lottrack
 
-             if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
 
-             {
 
-                 AddLotTrackData();
 
-                 _lotTackTime = DateTime.Now;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 获取Lot Track数据
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private void AddLotTrackData()
 
-         {
 
-             LoadStep step = (LoadStep)Runner.CurrentStep;
 
-             if (step <= LoadStep.SideAllLoadWait)
 
-             {
 
-                 LoaderLotTrackData data = new LoaderLotTrackData();
 
-                 data.TimeStamp = DateTime.Now;
 
-                 if (_side == SIDE_A)
 
-                 {
 
-                     data.LoaderABernoulliBladderEnable = _loaderSide.SideData.BernoulliBladder;
 
-                     data.LoaderABernoulliBladderPressure = _loaderSide.SideData.BernoulliBladderPressure;
 
-                     data.LoaderABernoulliN2Pressure = _loaderSide.SideData.BernoulliPressure;
 
-                     data.LoaderACRSVacuum = _loaderSide.SideData.CRSVacuum;
 
-                     data.LoaderACRSVacuumAnlg = _loaderSide.SideData.CRSVacuumValue;
 
-                     data.LoaderAWHPressure = _loaderSide.SideData.WHBladderPressure;
 
-                 }
 
-                 else
 
-                 {
 
-                     data.LoaderBBernoulliBladderEnable = _loaderSide.SideData.BernoulliBladder;
 
-                     data.LoaderBBernoulliBladderPressure = _loaderSide.SideData.BernoulliBladderPressure;
 
-                     data.LoaderBBernoulliN2Pressure = _loaderSide.SideData.BernoulliPressure;
 
-                     data.LoaderBCRSVacuum = _loaderSide.SideData.CRSVacuum;
 
-                     data.LoaderBCRSVacuumAnlg = _loaderSide.SideData.CRSVacuumValue;
 
-                     data.LoaderBWHPressure = _loaderSide.SideData.WHBladderPressure;
 
-                 }
 
-                 data.LoaderWHClamped = _loaderCommon.CommonData.WaferHolderClamp;
 
-                 _datas.Add(data);
 
-             }            
 
-         }
 
-         
 
-     }
 
- }
 
 
  |