PlatingCellEntity.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.RecipeCenter;
  7. using Aitex.Core.Util;
  8. using Aitex.Core.Utilities;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Persistent.Reservoirs;
  11. using MECF.Framework.Common.ProcessCell;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using MECF.Framework.Common.ToolLayout;
  14. using PunkHPX8_Core;
  15. using PunkHPX8_RT.Devices.PlatingCell;
  16. using PunkHPX8_RT.Devices.PowerSupplier;
  17. using PunkHPX8_RT.Devices.Temperature;
  18. using PunkHPX8_RT.Modules.Reservoir;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. namespace PunkHPX8_RT.Modules.PlatingCell
  25. {
  26. public class PlatingCellEntity : Entity, IEntity, IModuleEntity
  27. {
  28. public enum PlatingCellMsg
  29. {
  30. NONE,
  31. Error,
  32. ResumeError,
  33. Initialize,
  34. Manual,
  35. Auto,
  36. CurrentShortTest,
  37. CloseFlowValve,
  38. OpenFlowValve,
  39. RunRecipe,
  40. Abort,
  41. Init
  42. }
  43. #region 常量
  44. private const string STRATUS = "Stratus";
  45. private const string AUTO = "Auto";
  46. private const string MANUAL = "Manual";
  47. private const string DISABLED = "Disabled";
  48. private const string ENGINEERING = "Engineering";
  49. private const string PRODUCTION = "Production";
  50. #endregion
  51. #region 内部变量
  52. /// <summary>
  53. /// 持久化数值
  54. /// </summary>
  55. private PlatingCellPersistentValue _persistentValue;
  56. /// <summary>
  57. /// 当前recipe
  58. /// </summary>
  59. private DepRecipe _currentRecipe;
  60. #endregion
  61. #region 属性
  62. /// <summary>
  63. /// 模块名称
  64. /// </summary>
  65. public ModuleName Module { get; private set; }
  66. /// <summary>
  67. /// 是否Init
  68. /// </summary>
  69. public bool IsInit
  70. {
  71. get { return fsm.State == (int)PlatingCellState.Init; }
  72. }
  73. /// <summary>
  74. /// 是否Idle
  75. /// </summary>
  76. public bool IsIdle
  77. {
  78. get
  79. {
  80. return fsm.State == (int)PlatingCellState.Idle;
  81. }
  82. }
  83. /// <summary>
  84. /// 是否错误
  85. /// </summary>
  86. public bool IsError
  87. {
  88. get { return fsm.State == (int)PlatingCellState.Error; }
  89. }
  90. /// <summary>
  91. /// 正在忙碌
  92. /// </summary>
  93. public bool IsBusy
  94. {
  95. get { return fsm.State == (int)PlatingCellState.Initializing; }
  96. }
  97. /// <summary>
  98. /// 化学液
  99. /// </summary>
  100. public string Chemistry
  101. {
  102. get { return _currentRecipe != null ? _currentRecipe.Chemistry : ""; }
  103. }
  104. /// <summary>
  105. /// 是否禁用
  106. /// </summary>
  107. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  108. /// <summary>
  109. /// 自动模式
  110. /// </summary>
  111. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  112. /// <summary>
  113. /// 自动模式
  114. /// </summary>
  115. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  116. /// <summary>
  117. /// 是否为工程模式
  118. /// </summary>
  119. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  120. /// <summary>
  121. /// 是否为产品模式
  122. /// </summary>
  123. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  124. /// <summary>
  125. /// 状态机状态
  126. /// </summary>
  127. public PlatingCellState State { get { return (PlatingCellState)fsm.State; } }
  128. /// <summary>
  129. /// 是否初始化完成
  130. /// </summary>
  131. public bool IsInitialized { get { return fsm.State >= (int)PlatingCellState.Initialized; } }
  132. /// <summary>
  133. /// Reservoir项
  134. /// </summary>
  135. private ReservoirItem _reservoirItem;
  136. #endregion
  137. /// <summary>
  138. /// 构造函数
  139. /// </summary>
  140. /// <param name="module"></param>
  141. public PlatingCellEntity(ModuleName module)
  142. {
  143. this.Module = module;
  144. InitializeParameter();
  145. InitialFsm();
  146. }
  147. /// <summary>
  148. /// 初始化
  149. /// </summary>
  150. /// <returns></returns>
  151. protected override bool Init()
  152. {
  153. InitializeRoutine();
  154. InitializeDATA();
  155. InitializeOperation();
  156. return true;
  157. }
  158. /// <summary>
  159. /// 初始化参数
  160. /// </summary>
  161. private void InitializeParameter()
  162. {
  163. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module.ToString());
  164. if (_persistentValue == null)
  165. {
  166. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Persistent Value Object is not exist");
  167. }
  168. }
  169. /// <summary>
  170. /// 初始化Routine
  171. /// </summary>
  172. private void InitializeRoutine()
  173. {
  174. }
  175. /// <summary>
  176. /// 初始化DATA
  177. /// </summary>
  178. private void InitializeDATA()
  179. {
  180. DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  181. }
  182. /// <summary>
  183. /// 初始化Operation
  184. /// </summary>
  185. private void InitializeOperation()
  186. {
  187. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, ReservoirMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)ReservoirMsg.Initialize); });
  188. }
  189. /// 初始化状态机
  190. /// </summary>
  191. private void InitialFsm()
  192. {
  193. fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Init, 100);
  194. fsm.EnableRepeatedMsg(true);
  195. AnyStateTransition(ReservoirMsg.Error, NullFunc, PlatingCellState.Error);
  196. //Initialized
  197. Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  198. Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  199. Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  200. Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
  201. //直接进入Idle
  202. Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
  203. //Enter Init
  204. Transition(PlatingCellState.Idle, ReservoirMsg.Init, NullFunc, PlatingCellState.Init);
  205. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  206. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  207. }
  208. #region Initialize All
  209. /// <summary>
  210. /// 初始化
  211. /// </summary>
  212. /// <returns></returns>
  213. private bool InitializeAll(object[] param)
  214. {
  215. if (_persistentValue == null)
  216. {
  217. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
  218. return false;
  219. }
  220. return true;
  221. }
  222. /// <summary>
  223. /// Initialize 监控
  224. /// </summary>
  225. /// <param name="param"></param>
  226. /// <returns></returns>
  227. private bool InitializeAllMonitor(object[] param)
  228. {
  229. RState ret = RState.Init;
  230. if (ret == RState.Failed || ret == RState.Timeout)
  231. {
  232. PostMsg(ReservoirMsg.Error);
  233. return false;
  234. }
  235. return ret == RState.End;
  236. }
  237. #endregion
  238. /// <summary>
  239. /// EnterInit
  240. /// </summary>
  241. public void EnterInit()
  242. {
  243. if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
  244. else
  245. {
  246. CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
  247. }
  248. }
  249. public bool Check(int msg, out string reason, params object[] args)
  250. {
  251. reason = "";
  252. return true;
  253. }
  254. public bool CheckAcked(int msg)
  255. {
  256. throw new NotImplementedException();
  257. }
  258. public int Invoke(string function, params object[] args)
  259. {
  260. throw new NotImplementedException();
  261. }
  262. }
  263. }