123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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.Util;
- using Aitex.Core.Utilities;
- 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.ToolLayout;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.PlatingCell;
- using PunkHPX8_RT.Devices.PowerSupplier;
- using PunkHPX8_RT.Devices.Temperature;
- using PunkHPX8_RT.Modules.Reservoir;
- 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,
- CurrentShortTest,
- CloseFlowValve,
- OpenFlowValve,
- RunRecipe,
- Abort,
- Init
- }
- #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;
- #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;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellEntity(ModuleName module)
- {
- this.Module = module;
- InitializeParameter();
- InitialFsm();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- protected override bool Init()
- {
- InitializeRoutine();
- InitializeDATA();
- InitializeOperation();
- 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()
- {
- }
- /// <summary>
- /// 初始化DATA
- /// </summary>
- private void InitializeDATA()
- {
- DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化Operation
- /// </summary>
- private void InitializeOperation()
- {
- OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, ReservoirMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)ReservoirMsg.Initialize); });
- }
- /// 初始化状态机
- /// </summary>
- private void InitialFsm()
- {
- fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Init, 100);
- fsm.EnableRepeatedMsg(true);
- AnyStateTransition(ReservoirMsg.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);
- //直接进入Idle
- Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
- //Enter Init
- Transition(PlatingCellState.Idle, ReservoirMsg.Init, NullFunc, PlatingCellState.Init);
- EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
- EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
- }
- #region Initialize All
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- private bool InitializeAll(object[] param)
- {
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
- return false;
- }
- return true;
-
- }
- /// <summary>
- /// Initialize 监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeAllMonitor(object[] param)
- {
- RState ret = RState.Init;
-
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(ReservoirMsg.Error);
- return false;
- }
- return ret == RState.End;
- }
- #endregion
- /// <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);
- }
- }
-
- 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)
- {
- throw new NotImplementedException();
- }
- }
- }
|