PlatingCellEntity.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  246. {
  247. DepRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<DepRecipe>(args[0].ToString());
  248. if (recipe == null)
  249. {
  250. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), $"{args[0]} recipe is null");
  251. return false;
  252. }
  253. object[] objects = new object[args.Length];
  254. objects[0] = recipe;
  255. for (int i = 1; i < args.Length; i++)
  256. {
  257. objects[i] = args[i];
  258. }
  259. return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PlatingCellMsg.RunRecipe, objects);
  260. });
  261. }
  262. /// 初始化状态机
  263. /// </summary>
  264. private void InitialFsm()
  265. {
  266. fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Init, 100);
  267. fsm.EnableRepeatedMsg(true);
  268. AnyStateTransition(PlatingCellMsg.Error, NullFunc, PlatingCellState.Error);
  269. //Initialized
  270. Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  271. Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  272. Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  273. Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
  274. //CCR
  275. Transition(PlatingCellState.Idle, PlatingCellMsg.CCR, ManualCCRStart, PlatingCellState.CCRing);
  276. Transition(PlatingCellState.CCRing, FSM_MSG.TIMER, CCRMonitor, PlatingCellState.Idle);
  277. Transition(PlatingCellState.CCRing, PlatingCellMsg.CCRAbort, CCRAbort, PlatingCellState.Init);
  278. //Cycle Manual Process
  279. Transition(PlatingCellState.Idle, PlatingCellMsg.RunRecipe, CycleManualProcess, PlatingCellState.RunReciping);
  280. Transition(PlatingCellState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PlatingCellState.Idle);
  281. Transition(PlatingCellState.RunReciping, VPWCellMsg.Abort, RunRecipeAbort, PlatingCellState.Idle);
  282. //直接进入Idle
  283. Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
  284. //Enter Init
  285. Transition(PlatingCellState.Idle, PlatingCellMsg.Init, NullFunc, PlatingCellState.Init);
  286. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  287. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  288. }
  289. /// <summary>
  290. /// 手动CCR
  291. /// </summary>
  292. /// <returns></returns>
  293. private bool ManualCCRStart(object[] param)
  294. {
  295. bool result = _platingCellCRRoutine.Start() == RState.Running;
  296. return result;
  297. }
  298. /// <summary>
  299. /// CCR 监控
  300. /// </summary>
  301. /// <param name="param"></param>
  302. /// <returns></returns>
  303. private bool CCRMonitor(object[] param)
  304. {
  305. RState rsstate = RState.Running;
  306. rsstate = _platingCellCRRoutine.Monitor();
  307. if (rsstate == RState.End)
  308. {
  309. return true;
  310. }
  311. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  312. {
  313. PostMsg(PlatingCellMsg.Error);
  314. return false;
  315. }
  316. return false;
  317. }
  318. /// <summary>
  319. /// CCR abort
  320. /// </summary>
  321. /// <param name="param"></param>
  322. /// <returns></returns>
  323. private bool CCRAbort(object[] param)
  324. {
  325. if(_platingCellCRRoutine.Monitor() == RState.Running)
  326. {
  327. _platingCellCRRoutine.Abort();
  328. }
  329. return true;
  330. }
  331. /// <summary>
  332. /// 初始化
  333. /// </summary>
  334. /// <returns></returns>
  335. private bool InitializeAll(object[] param)
  336. {
  337. if (_persistentValue == null)
  338. {
  339. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
  340. return false;
  341. }
  342. if (fsm.State == (int)PlatingCellState.Initializing)
  343. {
  344. LOG.WriteLog(eEvent.WARN_PLATINGCELL, Module.ToString(), "state is Initializing,cannot do initialize");
  345. return false;
  346. }
  347. if (!CheckReservoirInitialized())
  348. {
  349. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not initialized");
  350. return false;
  351. }
  352. if (!MetalUsageMointor(Module.ToString()))
  353. {
  354. return false;
  355. }
  356. if ("Auto".Equals(_persistentValue.OperatingMode))
  357. {
  358. if (!CheckReservoirIsAuto())
  359. {
  360. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not in Auto OperationMode");
  361. return false;
  362. }
  363. }
  364. string AnotherModule = ModuleMatcherManager.Instance.GetMatcherByModule(Module.ToString());
  365. PlatingCellEntity anotherEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(AnotherModule);
  366. {
  367. if(anotherEntity != null && anotherEntity.IsBusy)
  368. {
  369. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Another Platingcell is busy, can not initialized");
  370. return false;
  371. }
  372. }
  373. bool result = _initializeRoutine.Start(_persistentValue) == RState.Running;
  374. return result;
  375. }
  376. /// <summary>
  377. /// 检验Reservoir是否Auto
  378. /// </summary>
  379. /// <returns></returns>
  380. private bool CheckReservoirIsAuto()
  381. {
  382. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  383. ReservoirsPersistentValue reservoirsPersistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(reservoir);
  384. if ("Auto".Equals(reservoirsPersistentValue.OperatingMode))
  385. {
  386. return true;
  387. }
  388. return false;
  389. }
  390. /// <summary>
  391. /// 检验Reservoir是否Initialized
  392. /// </summary>
  393. /// <returns></returns>
  394. private bool CheckReservoirInitialized()
  395. {
  396. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  397. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  398. if (reservoirEntity != null)
  399. {
  400. return reservoirEntity.IsInitialized;
  401. }
  402. return false;
  403. }
  404. /// <summary>
  405. /// 监控 PM Counter Metal用量
  406. /// </summary>
  407. private bool MetalUsageMointor(string Module)
  408. {
  409. return true;
  410. }
  411. /// <summary>
  412. /// Initialize 监控
  413. /// </summary>
  414. /// <param name="param"></param>
  415. /// <returns></returns>
  416. private bool InitializeAllMonitor(object[] param)
  417. {
  418. RState rsstate = RState.Running;
  419. rsstate = _initializeRoutine.Monitor();
  420. if (rsstate == RState.End)
  421. {
  422. return true;
  423. }
  424. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  425. {
  426. PostMsg(PlatingCellMsg.Error);
  427. return false;
  428. }
  429. return false;
  430. }
  431. /// <summary>
  432. /// EnterInit
  433. /// </summary>
  434. public void EnterInit()
  435. {
  436. if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
  437. else
  438. {
  439. CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
  440. }
  441. }
  442. #region cycle manual process
  443. /// <summary>
  444. /// process
  445. /// </summary>
  446. /// <param name="param"></param>
  447. /// <returns></returns>
  448. private bool CycleManualProcess(object[] param)
  449. {
  450. bool result = _runRecipeRoutine.Start(param) == RState.Running;
  451. _currentStepState = "";
  452. return result;
  453. }
  454. /// <summary>
  455. /// 监控
  456. /// </summary>
  457. /// <param name="param"></param>
  458. /// <returns></returns>
  459. private bool CycleManualMonitor(object[] param)
  460. {
  461. RState state = _runRecipeRoutine.Monitor();
  462. _currentStepState = _runRecipeRoutine.CurrentStep;
  463. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module.ToString(), _currentStepState);
  464. if (state == RState.Failed || state == RState.Timeout)
  465. {
  466. PostMsg(PlatingCellMsg.Error);
  467. _currentStepState = "";
  468. return false;
  469. }
  470. bool result = state == RState.End;
  471. if (result)
  472. {
  473. _currentStepState = "";
  474. }
  475. return result;
  476. }
  477. /// <summary>
  478. /// 中止
  479. /// </summary>
  480. /// <param name="param"></param>
  481. /// <returns></returns>
  482. private bool RunRecipeAbort(object[] param)
  483. {
  484. _runRecipeRoutine.Abort();
  485. _currentStepState = "";
  486. return true;
  487. }
  488. #endregion
  489. public bool Check(int msg, out string reason, params object[] args)
  490. {
  491. reason = "";
  492. return true;
  493. }
  494. public bool CheckAcked(int msg)
  495. {
  496. throw new NotImplementedException();
  497. }
  498. public int Invoke(string function, params object[] args)
  499. {
  500. switch (function)
  501. {
  502. case "HomeAll":
  503. if (IsIdle)
  504. {
  505. return (int)FSM_MSG.NONE;
  506. }
  507. if (CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Initialize))
  508. {
  509. return (int)PlatingCellMsg.Initialize;
  510. }
  511. else
  512. {
  513. return (int)FSM_MSG.NONE;
  514. }
  515. }
  516. return (int)FSM_MSG.NONE;
  517. }
  518. }
  519. }