PlatingCellEntity.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Fsm;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using Aitex.Core.Utilities;
  11. using CyberX12_RT.Modules.VpwCell;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.Persistent.Reservoirs;
  14. using MECF.Framework.Common.ProcessCell;
  15. using MECF.Framework.Common.RecipeCenter;
  16. using MECF.Framework.Common.Routine;
  17. using MECF.Framework.Common.SubstrateTrackings;
  18. using MECF.Framework.Common.ToolLayout;
  19. using MECF.Framework.RT.Core.Equipments;
  20. using PunkHPX8_Core;
  21. using PunkHPX8_RT.Devices.PlatingCell;
  22. using PunkHPX8_RT.Devices.PowerSupplier;
  23. using PunkHPX8_RT.Devices.Reservoir;
  24. using PunkHPX8_RT.Devices.Temperature;
  25. using PunkHPX8_RT.Modules.Reservoir;
  26. using PunkHPX8_RT.Modules.VpwCell;
  27. using PunkHPX8_RT.Modules.VpwMain;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Text;
  32. using System.Threading.Tasks;
  33. namespace PunkHPX8_RT.Modules.PlatingCell
  34. {
  35. public class PlatingCellEntity : Entity, IEntity, IModuleEntity
  36. {
  37. public enum PlatingCellMsg
  38. {
  39. NONE,
  40. Error,
  41. ResumeError,
  42. Initialize,
  43. Manual,
  44. Auto,
  45. CloseFlowValve,
  46. OpenFlowValve,
  47. RunRecipe,
  48. Abort,
  49. Init,
  50. CCR,
  51. CCRAbort
  52. }
  53. #region 常量
  54. private const string STRATUS = "Stratus";
  55. private const string AUTO = "Auto";
  56. private const string MANUAL = "Manual";
  57. private const string DISABLED = "Disabled";
  58. private const string ENGINEERING = "Engineering";
  59. private const string PRODUCTION = "Production";
  60. #endregion
  61. #region 内部变量
  62. /// <summary>
  63. /// 持久化数值
  64. /// </summary>
  65. private PlatingCellPersistentValue _persistentValue;
  66. /// <summary>
  67. /// 当前recipe
  68. /// </summary>
  69. private DepRecipe _currentRecipe;
  70. /// <summary>
  71. /// recipe时间
  72. /// </summary>
  73. private int _recipeTime;
  74. /// <summary>
  75. /// c&m Initialize routine
  76. /// </summary>
  77. private PlatingCellInitializeRoutine _initializeRoutine;
  78. /// <summary>
  79. /// CCR routine
  80. /// </summary>
  81. private PlatingCellCCRRoutine _platingCellCRRoutine;
  82. /// <summary>
  83. /// Run recipe routine
  84. /// </summary>
  85. private PlatingCellRunRecipeRoutine _runRecipeRoutine;
  86. /// <summary>
  87. /// 工艺当前执行小步骤
  88. /// </summary>
  89. private string _currentStepState = "Init";
  90. #endregion
  91. #region 属性
  92. /// <summary>
  93. /// 模块名称
  94. /// </summary>
  95. public ModuleName Module { get; private set; }
  96. /// <summary>
  97. /// 是否Init
  98. /// </summary>
  99. public bool IsInit
  100. {
  101. get { return fsm.State == (int)PlatingCellState.Init; }
  102. }
  103. /// <summary>
  104. /// 是否Idle
  105. /// </summary>
  106. public bool IsIdle
  107. {
  108. get
  109. {
  110. return fsm.State == (int)PlatingCellState.Idle;
  111. }
  112. }
  113. /// <summary>
  114. /// 是否错误
  115. /// </summary>
  116. public bool IsError
  117. {
  118. get { return fsm.State == (int)PlatingCellState.Error; }
  119. }
  120. /// <summary>
  121. /// 正在忙碌
  122. /// </summary>
  123. public bool IsBusy
  124. {
  125. get { return fsm.State == (int)PlatingCellState.Initializing; }
  126. }
  127. /// <summary>
  128. /// 化学液
  129. /// </summary>
  130. public string Chemistry
  131. {
  132. get { return _currentRecipe != null ? _currentRecipe.Chemistry : ""; }
  133. }
  134. /// <summary>
  135. /// 是否禁用
  136. /// </summary>
  137. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  138. /// <summary>
  139. /// 自动模式
  140. /// </summary>
  141. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  142. /// <summary>
  143. /// 自动模式
  144. /// </summary>
  145. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  146. /// <summary>
  147. /// 是否为工程模式
  148. /// </summary>
  149. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  150. /// <summary>
  151. /// 是否为产品模式
  152. /// </summary>
  153. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  154. /// <summary>
  155. /// 当前状态机状态
  156. /// </summary>
  157. public int State { get { return fsm.State; } }
  158. /// <summary>
  159. /// 是否初始化完成
  160. /// </summary>
  161. public bool IsInitialized { get { return fsm.State >= (int)PlatingCellState.Initialized; } }
  162. /// <summary>
  163. /// Reservoir项
  164. /// </summary>
  165. private ReservoirItem _reservoirItem;
  166. /// <summary>
  167. /// Wafer信息
  168. /// </summary>
  169. public WaferInfo WaferInfo { get { return WaferManager.Instance.GetWafer(Module,0); } }
  170. /// <summary>
  171. /// 当前Metal设置的WaferSize
  172. /// </summary>
  173. public int MetalWaferSize { get { return _persistentValue.PlatingCellWaferSize; } }
  174. /// <summary>
  175. /// 当前工步
  176. /// </summary>
  177. public string CurrentStepState { get { return _currentStepState; } }
  178. #endregion
  179. /// <summary>
  180. /// 构造函数
  181. /// </summary>
  182. /// <param name="module"></param>
  183. public PlatingCellEntity(ModuleName module)
  184. {
  185. this.Module = module;
  186. InitialFsm();
  187. }
  188. /// <summary>
  189. /// 初始化
  190. /// </summary>
  191. /// <returns></returns>
  192. protected override bool Init()
  193. {
  194. WaferManager.Instance.SubscribeLocation(Module, 1);
  195. InitializeRoutine();
  196. InitializeDATA();
  197. InitializeOperation();
  198. InitializeParameter();
  199. return true;
  200. }
  201. /// <summary>
  202. /// 初始化参数
  203. /// </summary>
  204. private void InitializeParameter()
  205. {
  206. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module.ToString());
  207. if (_persistentValue == null)
  208. {
  209. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Persistent Value Object is not exist");
  210. }
  211. }
  212. /// <summary>
  213. /// 初始化Routine
  214. /// </summary>
  215. private void InitializeRoutine()
  216. {
  217. _initializeRoutine = new PlatingCellInitializeRoutine(Module.ToString());
  218. _platingCellCRRoutine = new PlatingCellCCRRoutine(Module.ToString());
  219. _runRecipeRoutine=new PlatingCellRunRecipeRoutine(Module.ToString());
  220. }
  221. /// <summary>
  222. /// 初始化DATA
  223. /// </summary>
  224. private void InitializeDATA()
  225. {
  226. DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  227. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  228. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  229. DATA.Subscribe($"{Module}.TimeRemain", () => _recipeTime != 0 && _runRecipeRoutine != null ? (_recipeTime - Math.Round((double)_runRecipeRoutine.ElapsedMilliseconds / 1000, 0)) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  230. DATA.Subscribe($"{Module}.Chemistry", () => _currentRecipe != null ? _currentRecipe.Chemistry : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  231. DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  232. DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  233. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  234. DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  235. DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  236. }
  237. /// <summary>
  238. /// 初始化Operation
  239. /// </summary>
  240. private void InitializeOperation()
  241. {
  242. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.Initialize); });
  243. OP.Subscribe($"{Module}.ManualCCRStart", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCR); });
  244. OP.Subscribe($"{Module}.ManualCCRStop", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCRAbort); });
  245. }
  246. /// 初始化状态机
  247. /// </summary>
  248. private void InitialFsm()
  249. {
  250. fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Idle, 100);
  251. fsm.EnableRepeatedMsg(true);
  252. AnyStateTransition(PlatingCellMsg.Error, NullFunc, PlatingCellState.Error);
  253. //Initialized
  254. Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  255. Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  256. Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  257. Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
  258. //CCR
  259. Transition(PlatingCellState.Idle, PlatingCellMsg.CCR, ManualCCRStart, PlatingCellState.CCRing);
  260. Transition(PlatingCellState.CCRing, FSM_MSG.TIMER, CCRMonitor, PlatingCellState.Idle);
  261. Transition(PlatingCellState.CCRing, PlatingCellMsg.CCRAbort, CCRAbort, PlatingCellState.Init);
  262. //Cycle Manual Process
  263. Transition(PlatingCellState.Idle, PlatingCellMsg.RunRecipe, CycleManualProcess, PlatingCellState.RunReciping);
  264. Transition(PlatingCellState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PlatingCellState.Idle);
  265. Transition(PlatingCellState.RunReciping, VPWCellMsg.Abort, RunRecipeAbort, PlatingCellState.Idle);
  266. //直接进入Idle
  267. Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
  268. //Enter Init
  269. Transition(PlatingCellState.Idle, PlatingCellMsg.Init, NullFunc, PlatingCellState.Init);
  270. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  271. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  272. }
  273. /// <summary>
  274. /// 手动CCR
  275. /// </summary>
  276. /// <returns></returns>
  277. private bool ManualCCRStart(object[] param)
  278. {
  279. bool result = _platingCellCRRoutine.Start() == RState.Running;
  280. return result;
  281. }
  282. /// <summary>
  283. /// CCR 监控
  284. /// </summary>
  285. /// <param name="param"></param>
  286. /// <returns></returns>
  287. private bool CCRMonitor(object[] param)
  288. {
  289. RState rsstate = RState.Running;
  290. rsstate = _platingCellCRRoutine.Monitor();
  291. if (rsstate == RState.End)
  292. {
  293. return true;
  294. }
  295. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  296. {
  297. PostMsg(PlatingCellMsg.Error);
  298. return false;
  299. }
  300. return false;
  301. }
  302. /// <summary>
  303. /// CCR abort
  304. /// </summary>
  305. /// <param name="param"></param>
  306. /// <returns></returns>
  307. private bool CCRAbort(object[] param)
  308. {
  309. if(_platingCellCRRoutine.Monitor() == RState.Running)
  310. {
  311. _platingCellCRRoutine.Abort();
  312. }
  313. return true;
  314. }
  315. /// <summary>
  316. /// 初始化
  317. /// </summary>
  318. /// <returns></returns>
  319. private bool InitializeAll(object[] param)
  320. {
  321. if (_persistentValue == null)
  322. {
  323. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
  324. return false;
  325. }
  326. if (fsm.State == (int)PlatingCellState.Initializing)
  327. {
  328. LOG.WriteLog(eEvent.WARN_PLATINGCELL, Module.ToString(), "state is Initializing,cannot do initialize");
  329. return false;
  330. }
  331. if (!CheckReservoirInitialized())
  332. {
  333. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not initialized");
  334. return false;
  335. }
  336. if (!MetalUsageMointor(Module.ToString()))
  337. {
  338. return false;
  339. }
  340. if ("Auto".Equals(_persistentValue.OperatingMode))
  341. {
  342. if (!CheckReservoirIsAuto())
  343. {
  344. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not in Auto OperationMode");
  345. return false;
  346. }
  347. }
  348. bool result = _initializeRoutine.Start(_persistentValue) == RState.Running;
  349. return result;
  350. }
  351. /// <summary>
  352. /// 检验Reservoir是否Auto
  353. /// </summary>
  354. /// <returns></returns>
  355. private bool CheckReservoirIsAuto()
  356. {
  357. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  358. ReservoirsPersistentValue reservoirsPersistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(reservoir);
  359. if ("Auto".Equals(reservoirsPersistentValue.OperatingMode))
  360. {
  361. return true;
  362. }
  363. return false;
  364. }
  365. /// <summary>
  366. /// 检验Reservoir是否Initialized
  367. /// </summary>
  368. /// <returns></returns>
  369. private bool CheckReservoirInitialized()
  370. {
  371. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  372. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  373. if (reservoirEntity != null)
  374. {
  375. return reservoirEntity.IsInitialized;
  376. }
  377. return false;
  378. }
  379. /// <summary>
  380. /// 监控 PM Counter Metal用量
  381. /// </summary>
  382. private bool MetalUsageMointor(string Module)
  383. {
  384. return true;
  385. }
  386. /// <summary>
  387. /// Initialize 监控
  388. /// </summary>
  389. /// <param name="param"></param>
  390. /// <returns></returns>
  391. private bool InitializeAllMonitor(object[] param)
  392. {
  393. RState rsstate = RState.Running;
  394. rsstate = _initializeRoutine.Monitor();
  395. if (rsstate == RState.End)
  396. {
  397. return true;
  398. }
  399. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  400. {
  401. PostMsg(PlatingCellMsg.Error);
  402. return false;
  403. }
  404. return false;
  405. }
  406. /// <summary>
  407. /// EnterInit
  408. /// </summary>
  409. public void EnterInit()
  410. {
  411. if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
  412. else
  413. {
  414. CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
  415. }
  416. }
  417. #region cycle manual process
  418. /// <summary>
  419. /// process
  420. /// </summary>
  421. /// <param name="param"></param>
  422. /// <returns></returns>
  423. private bool CycleManualProcess(object[] param)
  424. {
  425. bool result = _runRecipeRoutine.Start(param) == RState.Running;
  426. _currentStepState = "";
  427. return result;
  428. }
  429. /// <summary>
  430. /// 监控
  431. /// </summary>
  432. /// <param name="param"></param>
  433. /// <returns></returns>
  434. private bool CycleManualMonitor(object[] param)
  435. {
  436. RState state = _runRecipeRoutine.Monitor();
  437. _currentStepState = _runRecipeRoutine.CurrentStep;
  438. if (state == RState.Failed || state == RState.Timeout)
  439. {
  440. PostMsg(PlatingCellMsg.Error);
  441. _currentStepState = "";
  442. return false;
  443. }
  444. bool result = state == RState.End;
  445. if (result)
  446. {
  447. _currentStepState = "";
  448. }
  449. return result;
  450. }
  451. /// <summary>
  452. /// 中止
  453. /// </summary>
  454. /// <param name="param"></param>
  455. /// <returns></returns>
  456. private bool RunRecipeAbort(object[] param)
  457. {
  458. _runRecipeRoutine.Abort();
  459. _currentStepState = "";
  460. return true;
  461. }
  462. #endregion
  463. public bool Check(int msg, out string reason, params object[] args)
  464. {
  465. reason = "";
  466. return true;
  467. }
  468. public bool CheckAcked(int msg)
  469. {
  470. throw new NotImplementedException();
  471. }
  472. public int Invoke(string function, params object[] args)
  473. {
  474. switch (function)
  475. {
  476. case "HomeAll":
  477. if (IsIdle)
  478. {
  479. return (int)FSM_MSG.NONE;
  480. }
  481. if (CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Initialize))
  482. {
  483. return (int)PlatingCellMsg.Initialize;
  484. }
  485. else
  486. {
  487. return (int)FSM_MSG.NONE;
  488. }
  489. }
  490. return (int)FSM_MSG.NONE;
  491. }
  492. }
  493. }