PlatingCellEntity.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. /// 循环次数
  76. /// </summary>
  77. private int _cycle = 0;
  78. /// <summary>
  79. /// c&m Initialize routine
  80. /// </summary>
  81. private PlatingCellInitializeRoutine _initializeRoutine;
  82. /// <summary>
  83. /// CCR routine
  84. /// </summary>
  85. private PlatingCellCCRRoutine _platingCellCRRoutine;
  86. /// <summary>
  87. /// Run recipe routine
  88. /// </summary>
  89. private PlatingCellRunRecipeRoutine _runRecipeRoutine;
  90. /// <summary>
  91. /// 工艺当前执行小步骤
  92. /// </summary>
  93. private string _currentStepState = "Init";
  94. #endregion
  95. #region 属性
  96. /// <summary>
  97. /// 模块名称
  98. /// </summary>
  99. public ModuleName Module { get; private set; }
  100. /// <summary>
  101. /// 是否Init
  102. /// </summary>
  103. public bool IsInit
  104. {
  105. get { return fsm.State == (int)PlatingCellState.Init; }
  106. }
  107. /// <summary>
  108. /// 是否Idle
  109. /// </summary>
  110. public bool IsIdle
  111. {
  112. get
  113. {
  114. return fsm.State == (int)PlatingCellState.Idle;
  115. }
  116. }
  117. /// <summary>
  118. /// 是否错误
  119. /// </summary>
  120. public bool IsError
  121. {
  122. get { return fsm.State == (int)PlatingCellState.Error; }
  123. }
  124. /// <summary>
  125. /// 正在忙碌
  126. /// </summary>
  127. public bool IsBusy
  128. {
  129. get { return fsm.State == (int)PlatingCellState.Initializing; }
  130. }
  131. /// <summary>
  132. /// 化学液
  133. /// </summary>
  134. public string Chemistry
  135. {
  136. get { return _currentRecipe != null ? _currentRecipe.Chemistry : ""; }
  137. }
  138. /// <summary>
  139. /// 是否禁用
  140. /// </summary>
  141. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  142. /// <summary>
  143. /// 自动模式
  144. /// </summary>
  145. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  146. /// <summary>
  147. /// 自动模式
  148. /// </summary>
  149. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  150. /// <summary>
  151. /// 是否为工程模式
  152. /// </summary>
  153. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  154. /// <summary>
  155. /// 是否为产品模式
  156. /// </summary>
  157. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  158. /// <summary>
  159. /// 当前状态机状态
  160. /// </summary>
  161. public int State { get { return fsm.State; } }
  162. /// <summary>
  163. /// 是否初始化完成
  164. /// </summary>
  165. public bool IsInitialized { get { return fsm.State >= (int)PlatingCellState.Initialized; } }
  166. /// <summary>
  167. /// Reservoir项
  168. /// </summary>
  169. private ReservoirItem _reservoirItem;
  170. /// <summary>
  171. /// Wafer信息
  172. /// </summary>
  173. public WaferInfo WaferInfo { get { return WaferManager.Instance.GetWafer(Module,0); } }
  174. /// <summary>
  175. /// 当前Metal设置的WaferSize
  176. /// </summary>
  177. public int MetalWaferSize { get { return _persistentValue.PlatingCellWaferSize; } }
  178. /// <summary>
  179. /// 当前工步
  180. /// </summary>
  181. public string CurrentStepState { get { return _currentStepState; } }
  182. #endregion
  183. /// <summary>
  184. /// 构造函数
  185. /// </summary>
  186. /// <param name="module"></param>
  187. public PlatingCellEntity(ModuleName module)
  188. {
  189. this.Module = module;
  190. InitialFsm();
  191. }
  192. /// <summary>
  193. /// 初始化
  194. /// </summary>
  195. /// <returns></returns>
  196. protected override bool Init()
  197. {
  198. WaferManager.Instance.SubscribeLocation(Module, 1);
  199. InitializeRoutine();
  200. InitializeDATA();
  201. InitializeOperation();
  202. InitializeParameter();
  203. return true;
  204. }
  205. /// <summary>
  206. /// 初始化参数
  207. /// </summary>
  208. private void InitializeParameter()
  209. {
  210. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module.ToString());
  211. if (_persistentValue == null)
  212. {
  213. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Persistent Value Object is not exist");
  214. }
  215. }
  216. /// <summary>
  217. /// 初始化Routine
  218. /// </summary>
  219. private void InitializeRoutine()
  220. {
  221. _initializeRoutine = new PlatingCellInitializeRoutine(Module.ToString());
  222. _platingCellCRRoutine = new PlatingCellCCRRoutine(Module.ToString());
  223. _runRecipeRoutine=new PlatingCellRunRecipeRoutine(Module.ToString());
  224. }
  225. /// <summary>
  226. /// 初始化DATA
  227. /// </summary>
  228. private void InitializeDATA()
  229. {
  230. DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  231. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  232. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  233. DATA.Subscribe($"{Module}.TimeRemain", () => _recipeTime != 0 && _runRecipeRoutine != null ? (_recipeTime - Math.Round((double)_runRecipeRoutine.ElapsedMilliseconds / 1000, 0)) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  234. DATA.Subscribe($"{Module}.Chemistry", () => Chemistry, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  235. DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  236. DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  237. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  238. DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  239. DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  240. }
  241. /// <summary>
  242. /// 初始化Operation
  243. /// </summary>
  244. private void InitializeOperation()
  245. {
  246. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.Initialize); });
  247. OP.Subscribe($"{Module}.ManualCCRStart", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCR); });
  248. OP.Subscribe($"{Module}.ManualCCRStop", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCRAbort); });
  249. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  250. {
  251. DepRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<DepRecipe>(args[0].ToString());
  252. if (recipe == null)
  253. {
  254. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), $"{args[0]} recipe is null");
  255. return false;
  256. }
  257. object[] objects = new object[args.Length];
  258. objects[0] = recipe;
  259. for (int i = 1; i < args.Length; i++)
  260. {
  261. objects[i] = args[i];
  262. }
  263. return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PlatingCellMsg.RunRecipe, objects);
  264. });
  265. }
  266. /// 初始化状态机
  267. /// </summary>
  268. private void InitialFsm()
  269. {
  270. fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Init, 100);
  271. fsm.EnableRepeatedMsg(true);
  272. AnyStateTransition(PlatingCellMsg.Error, NullFunc, PlatingCellState.Error);
  273. //Initialized
  274. Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  275. Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  276. Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  277. Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
  278. //CCR
  279. Transition(PlatingCellState.Idle, PlatingCellMsg.CCR, ManualCCRStart, PlatingCellState.CCRing);
  280. Transition(PlatingCellState.CCRing, FSM_MSG.TIMER, CCRMonitor, PlatingCellState.Idle);
  281. Transition(PlatingCellState.CCRing, PlatingCellMsg.CCRAbort, CCRAbort, PlatingCellState.Init);
  282. //Cycle Manual Process
  283. Transition(PlatingCellState.Idle, PlatingCellMsg.RunRecipe, CycleManualProcess, PlatingCellState.RunReciping);
  284. Transition(PlatingCellState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PlatingCellState.Idle);
  285. Transition(PlatingCellState.RunReciping, VPWCellMsg.Abort, RunRecipeAbort, PlatingCellState.Idle);
  286. //直接进入Idle
  287. Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
  288. //Enter Init
  289. Transition(PlatingCellState.Idle, PlatingCellMsg.Init, NullFunc, PlatingCellState.Init);
  290. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  291. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  292. }
  293. /// <summary>
  294. /// 手动CCR
  295. /// </summary>
  296. /// <returns></returns>
  297. private bool ManualCCRStart(object[] param)
  298. {
  299. bool result = _platingCellCRRoutine.Start() == RState.Running;
  300. return result;
  301. }
  302. /// <summary>
  303. /// CCR 监控
  304. /// </summary>
  305. /// <param name="param"></param>
  306. /// <returns></returns>
  307. private bool CCRMonitor(object[] param)
  308. {
  309. RState rsstate = RState.Running;
  310. rsstate = _platingCellCRRoutine.Monitor();
  311. if (rsstate == RState.End)
  312. {
  313. return true;
  314. }
  315. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  316. {
  317. PostMsg(PlatingCellMsg.Error);
  318. return false;
  319. }
  320. return false;
  321. }
  322. /// <summary>
  323. /// CCR abort
  324. /// </summary>
  325. /// <param name="param"></param>
  326. /// <returns></returns>
  327. private bool CCRAbort(object[] param)
  328. {
  329. if(_platingCellCRRoutine.Monitor() == RState.Running)
  330. {
  331. _platingCellCRRoutine.Abort();
  332. }
  333. return true;
  334. }
  335. /// <summary>
  336. /// 初始化
  337. /// </summary>
  338. /// <returns></returns>
  339. private bool InitializeAll(object[] param)
  340. {
  341. if (_persistentValue == null)
  342. {
  343. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
  344. return false;
  345. }
  346. if (fsm.State == (int)PlatingCellState.Initializing)
  347. {
  348. LOG.WriteLog(eEvent.WARN_PLATINGCELL, Module.ToString(), "state is Initializing,cannot do initialize");
  349. return false;
  350. }
  351. if (!CheckReservoirInitialized())
  352. {
  353. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not initialized");
  354. return false;
  355. }
  356. if (!MetalUsageMointor(Module.ToString()))
  357. {
  358. return false;
  359. }
  360. if ("Auto".Equals(_persistentValue.OperatingMode))
  361. {
  362. if (!CheckReservoirIsAuto())
  363. {
  364. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not in Auto OperationMode");
  365. return false;
  366. }
  367. }
  368. string AnotherModule = ModuleMatcherManager.Instance.GetMatcherByModule(Module.ToString());
  369. PlatingCellEntity anotherEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(AnotherModule);
  370. {
  371. if(anotherEntity != null && anotherEntity.IsBusy)
  372. {
  373. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Another Platingcell is busy, can not initialized");
  374. return false;
  375. }
  376. }
  377. bool result = _initializeRoutine.Start(_persistentValue) == RState.Running;
  378. return result;
  379. }
  380. /// <summary>
  381. /// 检验Reservoir是否Auto
  382. /// </summary>
  383. /// <returns></returns>
  384. private bool CheckReservoirIsAuto()
  385. {
  386. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  387. ReservoirsPersistentValue reservoirsPersistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(reservoir);
  388. if ("Auto".Equals(reservoirsPersistentValue.OperatingMode))
  389. {
  390. return true;
  391. }
  392. return false;
  393. }
  394. /// <summary>
  395. /// 检验Reservoir是否Initialized
  396. /// </summary>
  397. /// <returns></returns>
  398. private bool CheckReservoirInitialized()
  399. {
  400. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  401. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  402. if (reservoirEntity != null)
  403. {
  404. return reservoirEntity.IsInitialized;
  405. }
  406. return false;
  407. }
  408. /// <summary>
  409. /// 监控 PM Counter Metal用量
  410. /// </summary>
  411. private bool MetalUsageMointor(string Module)
  412. {
  413. return true;
  414. }
  415. /// <summary>
  416. /// Initialize 监控
  417. /// </summary>
  418. /// <param name="param"></param>
  419. /// <returns></returns>
  420. private bool InitializeAllMonitor(object[] param)
  421. {
  422. RState rsstate = RState.Running;
  423. rsstate = _initializeRoutine.Monitor();
  424. if (rsstate == RState.End)
  425. {
  426. return true;
  427. }
  428. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  429. {
  430. PostMsg(PlatingCellMsg.Error);
  431. return false;
  432. }
  433. return false;
  434. }
  435. /// <summary>
  436. /// EnterInit
  437. /// </summary>
  438. public void EnterInit()
  439. {
  440. if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
  441. else
  442. {
  443. CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
  444. }
  445. }
  446. #region cycle manual process
  447. /// <summary>
  448. /// process
  449. /// </summary>
  450. /// <param name="param"></param>
  451. /// <returns></returns>
  452. private bool CycleManualProcess(object[] param)
  453. {
  454. bool result = _runRecipeRoutine.Start(param) == RState.Running;
  455. _currentStepState = "";
  456. DepRecipe recipe = param[0] as DepRecipe;
  457. _cycle = (int)param[2];
  458. if (result)
  459. {
  460. _recipeTime = recipe.CalculateRecipeTotalTime() * _cycle;
  461. _currentRecipe = recipe;
  462. }
  463. return result;
  464. }
  465. /// <summary>
  466. /// 监控
  467. /// </summary>
  468. /// <param name="param"></param>
  469. /// <returns></returns>
  470. private bool CycleManualMonitor(object[] param)
  471. {
  472. RState state = _runRecipeRoutine.Monitor();
  473. _currentStepState = _runRecipeRoutine.CurrentStep;
  474. //LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module.ToString(), _currentStepState);
  475. if (state == RState.Failed || state == RState.Timeout)
  476. {
  477. PostMsg(PlatingCellMsg.Error);
  478. _currentStepState = "";
  479. return false;
  480. }
  481. bool result = state == RState.End;
  482. if (result)
  483. {
  484. _currentStepState = "";
  485. }
  486. return result;
  487. }
  488. /// <summary>
  489. /// 中止
  490. /// </summary>
  491. /// <param name="param"></param>
  492. /// <returns></returns>
  493. private bool RunRecipeAbort(object[] param)
  494. {
  495. _runRecipeRoutine.Abort();
  496. _currentStepState = "";
  497. return true;
  498. }
  499. #endregion
  500. public bool Check(int msg, out string reason, params object[] args)
  501. {
  502. reason = "";
  503. return true;
  504. }
  505. public bool CheckAcked(int msg)
  506. {
  507. throw new NotImplementedException();
  508. }
  509. public int Invoke(string function, params object[] args)
  510. {
  511. switch (function)
  512. {
  513. case "HomeAll":
  514. if (IsIdle)
  515. {
  516. return (int)FSM_MSG.NONE;
  517. }
  518. if (CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Initialize))
  519. {
  520. return (int)PlatingCellMsg.Initialize;
  521. }
  522. else
  523. {
  524. return (int)FSM_MSG.NONE;
  525. }
  526. }
  527. return (int)FSM_MSG.NONE;
  528. }
  529. }
  530. }