123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using CyberX12_RT.Modules.VpwCell;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.ProcessCell;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.RT.Core.Equipments;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.PlatingCell;
- using PunkHPX8_RT.Devices.PowerSupplier;
- using PunkHPX8_RT.Devices.Reservoir;
- using PunkHPX8_RT.Devices.Temperature;
- using PunkHPX8_RT.Modules.Reservoir;
- using PunkHPX8_RT.Modules.VpwCell;
- using PunkHPX8_RT.Modules.VpwMain;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Modules.PlatingCell
- {
- public class PlatingCellEntity : Entity, IEntity, IModuleEntity
- {
- public enum PlatingCellMsg
- {
- NONE,
- Error,
- ResumeError,
- Initialize,
- Manual,
- Auto,
- CloseFlowValve,
- OpenFlowValve,
- RunRecipe,
- Abort,
- Init,
- CCR,
- CCRAbort
- }
- #region 常量
- private const string STRATUS = "Stratus";
- private const string AUTO = "Auto";
- private const string MANUAL = "Manual";
- private const string DISABLED = "Disabled";
- private const string ENGINEERING = "Engineering";
- private const string PRODUCTION = "Production";
- #endregion
- #region 内部变量
- /// <summary>
- /// 持久化数值
- /// </summary>
- private PlatingCellPersistentValue _persistentValue;
- /// <summary>
- /// 当前recipe
- /// </summary>
- private DepRecipe _currentRecipe;
- /// <summary>
- /// recipe时间
- /// </summary>
- private int _recipeTime;
- /// <summary>
- /// c&m Initialize routine
- /// </summary>
- private PlatingCellInitializeRoutine _initializeRoutine;
- /// <summary>
- /// CCR routine
- /// </summary>
- private PlatingCellCCRRoutine _platingCellCRRoutine;
- /// <summary>
- /// Run recipe routine
- /// </summary>
- private PlatingCellRunRecipeRoutine _runRecipeRoutine;
- #endregion
- #region 属性
- /// <summary>
- /// 模块名称
- /// </summary>
- public ModuleName Module { get; private set; }
- /// <summary>
- /// 是否Init
- /// </summary>
- public bool IsInit
- {
- get { return fsm.State == (int)PlatingCellState.Init; }
- }
- /// <summary>
- /// 是否Idle
- /// </summary>
- public bool IsIdle
- {
- get
- {
- return fsm.State == (int)PlatingCellState.Idle;
- }
- }
- /// <summary>
- /// 是否错误
- /// </summary>
- public bool IsError
- {
- get { return fsm.State == (int)PlatingCellState.Error; }
- }
- /// <summary>
- /// 正在忙碌
- /// </summary>
- public bool IsBusy
- {
- get { return fsm.State == (int)PlatingCellState.Initializing; }
- }
- /// <summary>
- /// 化学液
- /// </summary>
- public string Chemistry
- {
- get { return _currentRecipe != null ? _currentRecipe.Chemistry : ""; }
- }
- /// <summary>
- /// 是否禁用
- /// </summary>
- public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
- /// <summary>
- /// 自动模式
- /// </summary>
- public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
- /// <summary>
- /// 自动模式
- /// </summary>
- public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
- /// <summary>
- /// 是否为工程模式
- /// </summary>
- public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
- /// <summary>
- /// 是否为产品模式
- /// </summary>
- public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
- /// <summary>
- /// 状态机状态
- /// </summary>
- public PlatingCellState State { get { return (PlatingCellState)fsm.State; } }
- /// <summary>
- /// 是否初始化完成
- /// </summary>
- public bool IsInitialized { get { return fsm.State >= (int)PlatingCellState.Initialized; } }
- /// <summary>
- /// Reservoir项
- /// </summary>
- private ReservoirItem _reservoirItem;
- /// <summary>
- /// Wafer信息
- /// </summary>
- public WaferInfo WaferInfo { get { return WaferManager.Instance.GetWafer(Module,0); } }
- /// <summary>
- /// 当前Metal设置的WaferSize
- /// </summary>
- public int MetalWaferSize { get { return _persistentValue.PlatingCellWaferSize; } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellEntity(ModuleName module)
- {
- this.Module = module;
- InitialFsm();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- protected override bool Init()
- {
- WaferManager.Instance.SubscribeLocation(Module, 1);
- InitializeRoutine();
- InitializeDATA();
- InitializeOperation();
- InitializeParameter();
- return true;
- }
- /// <summary>
- /// 初始化参数
- /// </summary>
- private void InitializeParameter()
- {
- _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module.ToString());
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Persistent Value Object is not exist");
- }
- }
-
- /// <summary>
- /// 初始化Routine
- /// </summary>
- private void InitializeRoutine()
- {
- _initializeRoutine = new PlatingCellInitializeRoutine(Module.ToString());
- _platingCellCRRoutine = new PlatingCellCCRRoutine(Module.ToString());
- }
- /// <summary>
- /// 初始化DATA
- /// </summary>
- private void InitializeDATA()
- {
- DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.TimeRemain", () => _recipeTime != 0 && _runRecipeRoutine != null ? (_recipeTime - Math.Round((double)_runRecipeRoutine.ElapsedMilliseconds / 1000, 0)) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Chemistry", () => _currentRecipe != null ? _currentRecipe.Chemistry : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化Operation
- /// </summary>
- private void InitializeOperation()
- {
- OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.Initialize); });
- OP.Subscribe($"{Module}.ManualCCRStart", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCR); });
- OP.Subscribe($"{Module}.ManualCCRStop", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCRAbort); });
- }
- /// 初始化状态机
- /// </summary>
- private void InitialFsm()
- {
- fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Idle, 100);
- fsm.EnableRepeatedMsg(true);
- AnyStateTransition(PlatingCellMsg.Error, NullFunc, PlatingCellState.Error);
- //Initialized
- Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
- Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
- Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
- Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
- //CCR
- Transition(PlatingCellState.Idle, PlatingCellMsg.CCR, ManualCCRStart, PlatingCellState.CCRing);
- Transition(PlatingCellState.CCRing, FSM_MSG.TIMER, CCRMonitor, PlatingCellState.Idle);
- Transition(PlatingCellState.CCRing, PlatingCellMsg.CCRAbort, CCRAbort, PlatingCellState.Init);
- //Cycle Manual Process
- Transition(PlatingCellState.Idle, PlatingCellMsg.RunRecipe, CycleManualProcess, PlatingCellState.RunReciping);
- Transition(PlatingCellState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PlatingCellState.Idle);
- Transition(PlatingCellState.RunReciping, VPWCellMsg.Abort, RunRecipeAbort, PlatingCellState.Idle);
- //直接进入Idle
- Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
- //Enter Init
- Transition(PlatingCellState.Idle, PlatingCellMsg.Init, NullFunc, PlatingCellState.Init);
- EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
- EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
- }
- /// <summary>
- /// 手动CCR
- /// </summary>
- /// <returns></returns>
- private bool ManualCCRStart(object[] param)
- {
- bool result = _platingCellCRRoutine.Start() == RState.Running;
- return result;
- }
- /// <summary>
- /// CCR 监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CCRMonitor(object[] param)
- {
- RState rsstate = RState.Running;
- rsstate = _platingCellCRRoutine.Monitor();
- if (rsstate == RState.End)
- {
- return true;
- }
- else if (rsstate == RState.Failed || rsstate == RState.Timeout)
- {
- PostMsg(PlatingCellMsg.Error);
- return false;
- }
- return false;
- }
- /// <summary>
- /// CCR abort
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CCRAbort(object[] param)
- {
- if(_platingCellCRRoutine.Monitor() == RState.Running)
- {
- _platingCellCRRoutine.Abort();
- }
- return true;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- private bool InitializeAll(object[] param)
- {
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
- return false;
- }
- if (fsm.State == (int)PlatingCellState.Initializing)
- {
- LOG.WriteLog(eEvent.WARN_PLATINGCELL, Module.ToString(), "state is Initializing,cannot do initialize");
- return false;
- }
- if (!CheckReservoirInitialized())
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not initialized");
- return false;
- }
- if (!MetalUsageMointor(Module.ToString()))
- {
- return false;
- }
- if ("Auto".Equals(_persistentValue.OperatingMode))
- {
- if (!CheckReservoirIsAuto())
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not in Auto OperationMode");
- return false;
- }
- }
- bool result = _initializeRoutine.Start(_persistentValue) == RState.Running;
- return result;
-
- }
- /// <summary>
- /// 检验Reservoir是否Auto
- /// </summary>
- /// <returns></returns>
- private bool CheckReservoirIsAuto()
- {
- string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
- ReservoirsPersistentValue reservoirsPersistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(reservoir);
- if ("Auto".Equals(reservoirsPersistentValue.OperatingMode))
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 检验Reservoir是否Initialized
- /// </summary>
- /// <returns></returns>
- private bool CheckReservoirInitialized()
- {
- string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
- if (reservoirEntity != null)
- {
- return reservoirEntity.IsInitialized;
- }
- return false;
- }
- /// <summary>
- /// 监控 PM Counter Metal用量
- /// </summary>
- private bool MetalUsageMointor(string Module)
- {
- return true;
- }
- /// <summary>
- /// Initialize 监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeAllMonitor(object[] param)
- {
- RState rsstate = RState.Running;
- rsstate = _initializeRoutine.Monitor();
- if (rsstate == RState.End)
- {
- return true;
- }
- else if (rsstate == RState.Failed || rsstate == RState.Timeout)
- {
- PostMsg(PlatingCellMsg.Error);
- return false;
- }
- return false;
- }
- /// <summary>
- /// EnterInit
- /// </summary>
- public void EnterInit()
- {
- if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
- else
- {
- CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
- }
- }
- #region cycle manual process
- /// <summary>
- /// process
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CycleManualProcess(object[] param)
- {
- bool result = _runRecipeRoutine.Start(param) == RState.Running;
- if (result)
- {
- }
- return result;
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CycleManualMonitor(object[] param)
- {
- RState state = _runRecipeRoutine.Monitor();
- if (state == RState.Failed || state == RState.Timeout)
- {
- return false;
- }
- bool result = state == RState.End;
- if (result)
- {
- }
- return result;
- }
- /// <summary>
- /// 中止
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool RunRecipeAbort(object[] param)
- {
- _runRecipeRoutine.Abort();
- VpwMainEntity vpwMainEntity = Singleton<RouteManager>.Instance.GetModule<VpwMainEntity>("VPWMain1");
- if (vpwMainEntity != null)
- {
- //把main的状态置为暂停
- vpwMainEntity.PostMsg(VPWMainMsg.Abort);
- }
- return true;
- }
- #endregion
- public bool Check(int msg, out string reason, params object[] args)
- {
- reason = "";
- return true;
- }
- public bool CheckAcked(int msg)
- {
- throw new NotImplementedException();
- }
- public int Invoke(string function, params object[] args)
- {
- switch (function)
- {
- case "HomeAll":
- if (IsIdle)
- {
- return (int)FSM_MSG.NONE;
- }
- if (CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Initialize))
- {
- return (int)PlatingCellMsg.Initialize;
- }
- else
- {
- return (int)FSM_MSG.NONE;
- }
- }
- return (int)FSM_MSG.NONE;
- }
- }
- }
|