VpwCellEntity.cs 10.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.Util;
  7. using Aitex.Core.Utilities;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Persistent.Temperature;
  10. using MECF.Framework.Common.Persistent.VpwCell;
  11. using MECF.Framework.Common.Persistent.VpwMain;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using MECF.Framework.Common.ToolLayout;
  14. using PunkHPX8_Core;
  15. using PunkHPX8_RT.Devices.VpwCell;
  16. using PunkHPX8_RT.Modules.VpwCell;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading;
  22. using System.Threading.Tasks;
  23. namespace PunkHPX8_RT.Modules.VpwMain
  24. {
  25. public class VpwCellEntity : Entity, IEntity, IModuleEntity
  26. {
  27. public enum MSG
  28. {
  29. Home
  30. }
  31. #region 常量
  32. private const string STRATUS = "Stratus";
  33. private const string AUTO = "Auto";
  34. private const string MANUAL = "Manual";
  35. private const string DISABLED = "Disabled";
  36. private const string ENGINEERING = "Engineering";
  37. private const string PRODUCTION = "Production";
  38. #endregion
  39. #region 内部变量
  40. /// <summary>
  41. /// 持久化数值
  42. /// </summary>
  43. private VpwCellPersistentValue _persistentValue;
  44. /// <summary>
  45. /// VPW cell集合
  46. /// </summary>
  47. private List<VpwCellDevice> _vpwCellDevices = new List<VpwCellDevice>();
  48. /// <summary>
  49. /// Home Routine
  50. /// </summary>
  51. private VPWHomeRoutine _homeRoutine;
  52. #endregion
  53. #region 属性
  54. public ModuleName Module { get; private set; }
  55. /// <summary>
  56. /// 是否Init
  57. /// </summary>
  58. public bool IsInit
  59. {
  60. get { return fsm.State == (int)VPWCellState.Init; }
  61. }
  62. /// <summary>
  63. /// 是否Idle
  64. /// </summary>
  65. public bool IsIdle
  66. {
  67. get
  68. {
  69. return fsm.State == (int)VPWCellState.Idle;
  70. }
  71. }
  72. /// <summary>
  73. /// 是否错误
  74. /// </summary>
  75. public bool IsError
  76. {
  77. get { return fsm.State == (int)VPWCellState.Error; }
  78. }
  79. /// <summary>
  80. /// 正在忙碌
  81. /// </summary>
  82. public bool IsBusy
  83. {
  84. get { return fsm.State == (int)VPWCellState.Initializing; }
  85. }
  86. /// <summary>
  87. /// 是否禁用
  88. /// </summary>
  89. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  90. /// <summary>
  91. /// 自动模式
  92. /// </summary>
  93. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  94. /// <summary>
  95. /// 自动模式
  96. /// </summary>
  97. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  98. /// <summary>
  99. /// 是否为工程模式
  100. /// </summary>
  101. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  102. /// <summary>
  103. /// 是否为产品模式
  104. /// </summary>
  105. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  106. #endregion
  107. /// <summary>
  108. /// 构造函数
  109. /// </summary>
  110. /// <param name="module"></param>
  111. public VpwCellEntity(ModuleName module)
  112. {
  113. this.Module = module;
  114. }
  115. /// <summary>
  116. /// 初始化
  117. /// </summary>
  118. /// <returns></returns>
  119. protected override bool Init()
  120. {
  121. InitialFsm();
  122. InitializeParameter();
  123. InitializeRoutine();
  124. InitializeDATA();
  125. InitializeOperation();
  126. return true;
  127. }
  128. /// <summary>
  129. /// 初始化参数
  130. /// </summary>
  131. private void InitializeParameter()
  132. {
  133. _persistentValue = VpwCellPersistentManager.Instance.GetPersistentValue(Module.ToString());
  134. if (_persistentValue == null)
  135. {
  136. LOG.WriteLog(eEvent.ERR_VPW, Module.ToString(), "Persistent Value Object is not exist");
  137. }
  138. _vpwCellDevices.Clear();
  139. VpwMainItem vpwMainItem = VpwMainItemManager.Instance.GetItem(ModuleName.VPWMain1.ToString());
  140. if (vpwMainItem == null || vpwMainItem.VpwCells == null)
  141. {
  142. return;
  143. }
  144. foreach (var item in vpwMainItem.VpwCells)
  145. {
  146. VpwCellDevice cellDevice = DEVICE.GetDevice<VpwCellDevice>(item.ModuleName);
  147. _vpwCellDevices.Add(cellDevice);
  148. }
  149. }
  150. /// <summary>
  151. /// 初始化状态机
  152. /// </summary>
  153. private void InitialFsm()
  154. {
  155. fsm = new StateMachine<VpwCellEntity>(Module.ToString(), (int)VPWCellState.Init, 100);
  156. fsm.EnableRepeatedMsg(true);
  157. AnyStateTransition(VpwCellMsg.Error, NullFunc, VPWCellState.Error);
  158. //Initialized
  159. Transition(VPWCellState.Error, VpwCellMsg.Initialize, InitializeAll, VPWCellState.Initializing);
  160. Transition(VPWCellState.Init, VpwCellMsg.Initialize, InitializeAll, VPWCellState.Initializing);
  161. Transition(VPWCellState.Idle, VpwCellMsg.Initialize, InitializeAll, VPWCellState.Initializing);
  162. Transition(VPWCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, VPWCellState.Idle);
  163. Transition(VPWCellState.Error, VpwCellMsg.EnterIdle, NullFunc, VPWCellState.Idle);
  164. Transition(VPWCellState.Init, VpwCellMsg.EnterIdle, NullFunc, VPWCellState.Idle);
  165. Transition(VPWCellState.Idle, VpwCellMsg.EnterIdle, NullFunc, VPWCellState.Idle);
  166. //Enter Init
  167. Transition(VPWCellState.Idle, VpwCellMsg.Init, NullFunc, VPWCellState.Init);
  168. }
  169. /// <summary>
  170. /// 初始化数据
  171. /// </summary>
  172. private void InitializeDATA()
  173. {
  174. InitializeSVID();
  175. DATA.Subscribe($"{Module}.FsmState", () => ((VPWCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  176. DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  177. DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  178. DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  179. DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  180. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  181. }
  182. /// <summary>
  183. /// 初始化SVID
  184. /// </summary>
  185. private void InitializeSVID()
  186. {
  187. DATA.Subscribe($"{Module}.OperatingMode", () => _persistentValue != null ? _persistentValue.OperatingMode : "None", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  188. }
  189. /// <summary>
  190. /// 初始化Routine
  191. /// </summary>
  192. private void InitializeRoutine()
  193. {
  194. _homeRoutine = new VPWHomeRoutine(Module.ToString());
  195. }
  196. /// <summary>
  197. /// 初始化操作
  198. /// </summary>
  199. private void InitializeOperation()
  200. {
  201. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<VPWCellState, VpwCellMsg>(eEvent.ERR_VPWMAIN, Module.ToString(), (int)VpwCellMsg.Initialize); });
  202. }
  203. #region InitializeAll
  204. /// <summary>
  205. /// Initialize
  206. /// </summary>
  207. /// <param name="param"></param>
  208. /// <returns></returns>
  209. private bool InitializeAll(object[] param)
  210. {
  211. if (_vpwCellDevices == null || _vpwCellDevices.Count == 0)
  212. {
  213. LOG.WriteLog(eEvent.ERR_VPW, Module.ToString(), "cell device is empty");
  214. return false;
  215. }
  216. foreach (var device in _vpwCellDevices)
  217. {
  218. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(device.Module);
  219. if (vpwCellEntity.IsBusy)
  220. {
  221. LOG.WriteLog(eEvent.ERR_VPW, Module.ToString(), $"cell device {device.Module} is busy,cannot initialize");
  222. return false;
  223. }
  224. }
  225. return _homeRoutine.Start(_vpwCellDevices) == RState.Running;
  226. }
  227. /// <summary>
  228. /// Initialize 监控
  229. /// </summary>
  230. /// <param name="param"></param>
  231. /// <returns></returns>
  232. private bool InitializeAllMonitor(object[] param)
  233. {
  234. RState ret = _homeRoutine.Monitor();
  235. if (ret == RState.Failed || ret == RState.Timeout)
  236. {
  237. PostMsg(VpwCellMsg.Error);
  238. return false;
  239. }
  240. return ret == RState.End;
  241. }
  242. #endregion
  243. public bool Check(int msg, out string reason, params object[] args)
  244. {
  245. reason = "";
  246. return false;
  247. }
  248. public bool CheckAcked(int msg)
  249. {
  250. return false;
  251. }
  252. /// <summary>
  253. /// EnterInit
  254. /// </summary>
  255. public void EnterInit()
  256. {
  257. }
  258. public int Invoke(string function, params object[] args)
  259. {
  260. switch (function)
  261. {
  262. case "HomeAll":
  263. return (int)MSG.Home;
  264. }
  265. return (int)FSM_MSG.NONE;
  266. }
  267. }
  268. }