PlatingCellEntity.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.Utilities;
  12. using CyberX12_RT.Modules.VpwCell;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.Persistent.Reservoirs;
  15. using MECF.Framework.Common.ProcessCell;
  16. using MECF.Framework.Common.RecipeCenter;
  17. using MECF.Framework.Common.Routine;
  18. using MECF.Framework.Common.SubstrateTrackings;
  19. using MECF.Framework.Common.ToolLayout;
  20. using MECF.Framework.RT.Core.Equipments;
  21. using PunkHPX8_Core;
  22. using PunkHPX8_RT.Devices.PlatingCell;
  23. using PunkHPX8_RT.Devices.PowerSupplier;
  24. using PunkHPX8_RT.Devices.Reservoir;
  25. using PunkHPX8_RT.Devices.Temperature;
  26. using PunkHPX8_RT.Modules.Reservoir;
  27. using PunkHPX8_RT.Modules.VpwCell;
  28. using PunkHPX8_RT.Modules.VpwMain;
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Linq;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. namespace PunkHPX8_RT.Modules.PlatingCell
  35. {
  36. public class PlatingCellEntity : Entity, IEntity, IModuleEntity
  37. {
  38. #region 常量
  39. private const string STRATUS = "Stratus";
  40. private const string AUTO = "Auto";
  41. private const string MANUAL = "Manual";
  42. private const string DISABLED = "Disabled";
  43. private const string ENGINEERING = "Engineering";
  44. private const string PRODUCTION = "Production";
  45. #endregion
  46. #region 内部变量
  47. /// <summary>
  48. /// 持久化数值
  49. /// </summary>
  50. private PlatingCellPersistentValue _persistentValue;
  51. /// <summary>
  52. /// 当前recipe
  53. /// </summary>
  54. private DepRecipe _currentRecipe;
  55. /// <summary>
  56. /// recipe时间
  57. /// </summary>
  58. private int _recipeTime;
  59. /// <summary>
  60. /// 循环次数
  61. /// </summary>
  62. private int _cycle = 0;
  63. /// <summary>
  64. /// 已经完成的Cycle次数
  65. /// </summary>
  66. private int _achievedCycle = 0;
  67. /// <summary>
  68. /// c&m Initialize routine
  69. /// </summary>
  70. private PlatingCellInitializeRoutine _initializeRoutine;
  71. /// <summary>
  72. /// CCR routine
  73. /// </summary>
  74. private PlatingCellCCRRoutine _platingCellCRRoutine;
  75. /// <summary>
  76. /// Run recipe routine
  77. /// </summary>
  78. private PlatingCellRunRecipeRoutine _runRecipeRoutine;
  79. /// <summary>
  80. /// dummy risne Run recipe routine
  81. /// </summary>
  82. private DummyRinseRunRecipeRoutine _dummyRinseRunRecipeRoutine;
  83. /// <summary>
  84. /// Unload Routine
  85. /// </summary>
  86. private PlatingCellUnloadRoutine _unloadRoutine;
  87. /// <summary>
  88. /// 工艺当前执行小步骤
  89. /// </summary>
  90. private string _currentStepState = "Init";
  91. #endregion
  92. #region 属性
  93. /// <summary>
  94. /// 模块名称
  95. /// </summary>
  96. public ModuleName Module { get; private set; }
  97. /// <summary>
  98. /// 是否Init
  99. /// </summary>
  100. public bool IsInit
  101. {
  102. get { return fsm.State == (int)PlatingCellState.Init; }
  103. }
  104. /// <summary>
  105. /// 是否Idle
  106. /// </summary>
  107. public bool IsIdle
  108. {
  109. get
  110. {
  111. return fsm.State == (int)PlatingCellState.Idle;
  112. }
  113. }
  114. /// <summary>
  115. /// 是否错误
  116. /// </summary>
  117. public bool IsError
  118. {
  119. get { return fsm.State == (int)PlatingCellState.Error; }
  120. }
  121. /// <summary>
  122. /// 正在忙碌
  123. /// </summary>
  124. public bool IsBusy
  125. {
  126. get { return fsm.State == (int)PlatingCellState.Initializing ; }
  127. }
  128. /// <summary>
  129. /// 正在Run recipe
  130. /// </summary>
  131. public bool IsInRecipe
  132. {
  133. get { return fsm.State == (int)PlatingCellState.RunReciping; }
  134. }
  135. /// <summary>
  136. /// 已完成的RunRecipeCycle次数
  137. /// </summary>
  138. public int AchievedCycle { get { return _achievedCycle; } }
  139. /// <summary>
  140. /// 化学液
  141. /// </summary>
  142. public string Chemistry
  143. {
  144. get { return _currentRecipe != null ? _currentRecipe.Chemistry : ""; }
  145. }
  146. /// <summary>
  147. /// 当前正在run 的recipe
  148. /// </summary>
  149. public DepRecipe CurrentRecipe
  150. {
  151. get { return _currentRecipe; }
  152. }
  153. /// <summary>
  154. /// 是否禁用
  155. /// </summary>
  156. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  157. /// <summary>
  158. /// 自动模式
  159. /// </summary>
  160. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  161. /// <summary>
  162. /// 自动模式
  163. /// </summary>
  164. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  165. /// <summary>
  166. /// 是否为工程模式
  167. /// </summary>
  168. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  169. /// <summary>
  170. /// 是否为产品模式
  171. /// </summary>
  172. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  173. /// <summary>
  174. /// 当前状态机状态
  175. /// </summary>
  176. public int State { get { return fsm.State; } }
  177. /// <summary>
  178. /// 是否初始化完成
  179. /// </summary>
  180. public bool IsInitialized { get { return fsm.State >= (int)PlatingCellState.Initialized; } }
  181. /// <summary>
  182. /// Reservoir项
  183. /// </summary>
  184. private ReservoirItem _reservoirItem;
  185. /// <summary>
  186. /// Wafer信息
  187. /// </summary>
  188. public WaferInfo WaferInfo { get { return WaferManager.Instance.GetWafer(Module,0); } }
  189. /// <summary>
  190. /// 当前Metal设置的WaferSize
  191. /// </summary>
  192. public int MetalWaferSize { get { return _persistentValue.PlatingCellWaferSize; } }
  193. /// <summary>
  194. /// 当前工步
  195. /// </summary>
  196. public string CurrentStepState { get { return _currentStepState; } }
  197. #endregion
  198. /// <summary>
  199. /// 构造函数
  200. /// </summary>
  201. /// <param name="module"></param>
  202. public PlatingCellEntity(ModuleName module)
  203. {
  204. this.Module = module;
  205. InitialFsm();
  206. }
  207. /// <summary>
  208. /// 初始化
  209. /// </summary>
  210. /// <returns></returns>
  211. protected override bool Init()
  212. {
  213. WaferManager.Instance.SubscribeLocation(Module, 1);
  214. InitializeRoutine();
  215. InitializeDATA();
  216. InitializeOperation();
  217. InitializeParameter();
  218. return true;
  219. }
  220. /// <summary>
  221. /// 初始化参数
  222. /// </summary>
  223. private void InitializeParameter()
  224. {
  225. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module.ToString());
  226. if (_persistentValue == null)
  227. {
  228. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Persistent Value Object is not exist");
  229. }
  230. }
  231. /// <summary>
  232. /// 初始化Routine
  233. /// </summary>
  234. private void InitializeRoutine()
  235. {
  236. _initializeRoutine = new PlatingCellInitializeRoutine(Module.ToString());
  237. _platingCellCRRoutine = new PlatingCellCCRRoutine(Module.ToString());
  238. _runRecipeRoutine=new PlatingCellRunRecipeRoutine(Module.ToString());
  239. _dummyRinseRunRecipeRoutine=new DummyRinseRunRecipeRoutine(Module.ToString());
  240. _unloadRoutine=new PlatingCellUnloadRoutine(Module.ToString());
  241. }
  242. /// <summary>
  243. /// 初始化DATA
  244. /// </summary>
  245. private void InitializeDATA()
  246. {
  247. DATA.Subscribe($"{Module}.FsmState", () => ((PlatingCellState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  248. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  249. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  250. DATA.Subscribe($"{Module}.TimeRemain", () => CalculateRecipeTimeRemain(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  251. DATA.Subscribe($"{Module}.Chemistry", () => Chemistry, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  252. DATA.Subscribe($"{Module}.AchievedCycle", () => AchievedCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  253. DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  254. DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  255. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  256. DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  257. DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  258. }
  259. /// <summary>
  260. /// 初始化Operation
  261. /// </summary>
  262. private void InitializeOperation()
  263. {
  264. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.Initialize); });
  265. OP.Subscribe($"{Module}.ManualCCRStart", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCR); });
  266. OP.Subscribe($"{Module}.ManualCCRStop", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.CCRAbort); });
  267. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  268. {
  269. bool isDummyLoad = (bool)args[1];
  270. object recipe = null;
  271. if (!isDummyLoad)
  272. {
  273. recipe = RecipeFileManager.Instance.LoadGenericityRecipe<DepRecipe>(args[0].ToString());
  274. if (recipe == null)
  275. {
  276. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), $"{args[0]} recipe is null");
  277. return false;
  278. }
  279. }
  280. else
  281. {
  282. recipe = RecipeFileManager.Instance.LoadGenericityRecipe<DqdrRecipe>(args[0].ToString());
  283. if (recipe == null)
  284. {
  285. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), $"{args[0]} recipe is null");
  286. return false;
  287. }
  288. }
  289. object[] objects = new object[args.Length];
  290. objects[0] = recipe;
  291. for (int i = 1; i < args.Length; i++)
  292. {
  293. objects[i] = args[i];
  294. }
  295. return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PlatingCellMsg.RunRecipe, objects);
  296. });
  297. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_RESERVOIR, Module.ToString(), (int)PlatingCellMsg.Abort); });
  298. }
  299. /// 初始化状态机
  300. /// </summary>
  301. private void InitialFsm()
  302. {
  303. fsm = new StateMachine<PlatingCellEntity>(Module.ToString(), (int)PlatingCellState.Init, 100);
  304. fsm.EnableRepeatedMsg(true);
  305. AnyStateTransition(PlatingCellMsg.Error, NullFunc, PlatingCellState.Error);
  306. //Initialized
  307. Transition(PlatingCellState.Error, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  308. Transition(PlatingCellState.Init, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  309. Transition(PlatingCellState.Idle, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  310. Transition(PlatingCellState.Abort, PlatingCellMsg.Initialize, InitializeAll, PlatingCellState.Initializing);
  311. Transition(PlatingCellState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, PlatingCellState.Idle);
  312. //CCR
  313. Transition(PlatingCellState.Idle, PlatingCellMsg.CCR, ManualCCRStart, PlatingCellState.CCRing);
  314. Transition(PlatingCellState.CCRing, FSM_MSG.TIMER, CCRMonitor, PlatingCellState.Idle);
  315. Transition(PlatingCellState.CCRing, PlatingCellMsg.CCRAbort, CCRAbort, PlatingCellState.Init);
  316. //Cycle Manual Process
  317. Transition(PlatingCellState.Idle, PlatingCellMsg.RunRecipe, CycleManualProcess, PlatingCellState.RunReciping);
  318. Transition(PlatingCellState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PlatingCellState.Idle);
  319. Transition(PlatingCellState.RunReciping, PlatingCellMsg.Abort, AbortRecipe, PlatingCellState.Idle);
  320. //Unload
  321. Transition(PlatingCellState.Idle, PlatingCellMsg.Unload, Unload, PlatingCellState.Unloading);
  322. Transition(PlatingCellState.Unloading, FSM_MSG.TIMER, UnloadMonitor, PlatingCellState.Idle);
  323. Transition(PlatingCellState.Unloading, PlatingCellMsg.Abort, UnloadAbort, PlatingCellState.Idle);
  324. //直接进入Idle
  325. Transition(PlatingCellState.Initialized, FSM_MSG.TIMER, NullFunc, PlatingCellState.Idle);
  326. //Enter Init
  327. Transition(PlatingCellState.Idle, PlatingCellMsg.Init, NullFunc, PlatingCellState.Init);
  328. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  329. EnumLoop<PlatingCellState>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  330. }
  331. /// <summary>
  332. /// 计算recipe的剩余时间
  333. /// </summary>
  334. /// <returns></returns>
  335. private int CalculateRecipeTimeRemain()
  336. {
  337. if (!IsInRecipe)
  338. {
  339. return 0;
  340. }
  341. int remainTime = 0;
  342. if (WaferInfo == null || WaferInfo.IsEmpty)
  343. {
  344. return 0;
  345. }
  346. if (_recipeTime != 0)
  347. {
  348. if (WaferInfo.WaferType == WaferType.Production)
  349. {
  350. remainTime = (int)(_recipeTime - Math.Round((double)_runRecipeRoutine.ElapsedMilliseconds / 1000));
  351. }
  352. else
  353. {
  354. remainTime = (int)(_recipeTime - Math.Round((double)_dummyRinseRunRecipeRoutine.ElapsedMilliseconds / 1000));
  355. }
  356. }
  357. return remainTime;
  358. }
  359. /// <summary>
  360. /// Abort Recipe
  361. /// </summary>
  362. /// <param name="param"></param>
  363. /// <returns></returns>
  364. public bool AbortRecipe(object[] param)
  365. {
  366. if (WaferInfo == null || WaferInfo.IsEmpty)
  367. {
  368. return true;
  369. }
  370. //后续还要增加lottrack相关
  371. if (WaferInfo.WaferType==WaferType.Production)
  372. {
  373. _runRecipeRoutine.Abort();
  374. }
  375. else
  376. {
  377. _dummyRinseRunRecipeRoutine.Abort();
  378. }
  379. return true;
  380. }
  381. /// <summary>
  382. /// 手动CCR
  383. /// </summary>
  384. /// <returns></returns>
  385. private bool ManualCCRStart(object[] param)
  386. {
  387. bool result = _platingCellCRRoutine.Start() == RState.Running;
  388. return result;
  389. }
  390. /// <summary>
  391. /// CCR 监控
  392. /// </summary>
  393. /// <param name="param"></param>
  394. /// <returns></returns>
  395. private bool CCRMonitor(object[] param)
  396. {
  397. RState rsstate = RState.Running;
  398. rsstate = _platingCellCRRoutine.Monitor();
  399. if (rsstate == RState.End)
  400. {
  401. return true;
  402. }
  403. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  404. {
  405. PostMsg(PlatingCellMsg.Error);
  406. return false;
  407. }
  408. return false;
  409. }
  410. /// <summary>
  411. /// CCR abort
  412. /// </summary>
  413. /// <param name="param"></param>
  414. /// <returns></returns>
  415. private bool CCRAbort(object[] param)
  416. {
  417. if(_platingCellCRRoutine.Monitor() == RState.Running)
  418. {
  419. _platingCellCRRoutine.Abort();
  420. }
  421. return true;
  422. }
  423. /// <summary>
  424. /// 初始化
  425. /// </summary>
  426. /// <returns></returns>
  427. private bool InitializeAll(object[] param)
  428. {
  429. if (_persistentValue == null)
  430. {
  431. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "persistent is null");
  432. return false;
  433. }
  434. if (fsm.State == (int)PlatingCellState.Initializing)
  435. {
  436. LOG.WriteLog(eEvent.WARN_PLATINGCELL, Module.ToString(), "state is Initializing,cannot do initialize");
  437. return false;
  438. }
  439. if (!CheckReservoirInitialized())
  440. {
  441. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not initialized");
  442. return false;
  443. }
  444. if (!MetalUsageMointor(Module.ToString()))
  445. {
  446. return false;
  447. }
  448. if ("Auto".Equals(_persistentValue.OperatingMode))
  449. {
  450. if (!CheckReservoirIsAuto())
  451. {
  452. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Reservoir is not in Auto OperationMode");
  453. return false;
  454. }
  455. }
  456. string AnotherModule = ModuleMatcherManager.Instance.GetMatcherByModule(Module.ToString());
  457. PlatingCellEntity anotherEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(AnotherModule);
  458. {
  459. if(anotherEntity != null && anotherEntity.IsBusy)
  460. {
  461. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), "Another Platingcell is busy, can not initialized");
  462. return false;
  463. }
  464. }
  465. bool result = _initializeRoutine.Start(_persistentValue) == RState.Running;
  466. return result;
  467. }
  468. /// <summary>
  469. /// 检验Reservoir是否Auto
  470. /// </summary>
  471. /// <returns></returns>
  472. private bool CheckReservoirIsAuto()
  473. {
  474. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  475. ReservoirsPersistentValue reservoirsPersistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(reservoir);
  476. if ("Auto".Equals(reservoirsPersistentValue.OperatingMode))
  477. {
  478. return true;
  479. }
  480. return false;
  481. }
  482. /// <summary>
  483. /// 检验Reservoir是否Initialized
  484. /// </summary>
  485. /// <returns></returns>
  486. private bool CheckReservoirInitialized()
  487. {
  488. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  489. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  490. if (reservoirEntity != null)
  491. {
  492. return reservoirEntity.IsInitialized;
  493. }
  494. return false;
  495. }
  496. /// <summary>
  497. /// 监控 PM Counter Metal用量
  498. /// </summary>
  499. private bool MetalUsageMointor(string Module)
  500. {
  501. return true;
  502. }
  503. /// <summary>
  504. /// Initialize 监控
  505. /// </summary>
  506. /// <param name="param"></param>
  507. /// <returns></returns>
  508. private bool InitializeAllMonitor(object[] param)
  509. {
  510. RState rsstate = RState.Running;
  511. rsstate = _initializeRoutine.Monitor();
  512. if (rsstate == RState.End)
  513. {
  514. return true;
  515. }
  516. else if (rsstate == RState.Failed || rsstate == RState.Timeout)
  517. {
  518. PostMsg(PlatingCellMsg.Error);
  519. return false;
  520. }
  521. return false;
  522. }
  523. /// <summary>
  524. /// EnterInit
  525. /// </summary>
  526. public void EnterInit()
  527. {
  528. if ((PlatingCellState)fsm.State != PlatingCellState.Idle) return;
  529. else
  530. {
  531. CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Init);
  532. }
  533. }
  534. #region cycle manual process
  535. /// <summary>
  536. /// process
  537. /// </summary>
  538. /// <param name="param"></param>
  539. /// <returns></returns>
  540. private bool CycleManualProcess(object[] param)
  541. {
  542. if (WaferInfo == null || WaferInfo.IsEmpty)
  543. {
  544. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Wafer is empty");
  545. return false;
  546. }
  547. bool _isDummyLoad = (bool)param[1];
  548. if (_isDummyLoad && WaferInfo.WaferType == WaferType.Production)
  549. {
  550. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "production wafer cannot execute dummy recipe");
  551. return false;
  552. }
  553. if (!_isDummyLoad)
  554. {
  555. bool result = _runRecipeRoutine.Start(param) == RState.Running;
  556. _currentStepState = "";
  557. DepRecipe recipe = param[0] as DepRecipe;
  558. _cycle = (int)param[2];
  559. if (result)
  560. {
  561. _recipeTime = recipe.CalculateRecipeTotalTime() * _cycle;
  562. _currentRecipe = recipe;
  563. }
  564. return result;
  565. }
  566. else
  567. {
  568. bool result = _dummyRinseRunRecipeRoutine.Start(param) == RState.Running;
  569. _currentStepState = "";
  570. DqdrRecipe recipe = param[0] as DqdrRecipe;
  571. _cycle = (int)param[2];
  572. if (result)
  573. {
  574. _recipeTime = recipe.CalculateRecipeTotalTime() * _cycle;
  575. //run dummy recipe不需要记录当前recipe
  576. }
  577. return result;
  578. }
  579. }
  580. /// <summary>
  581. /// 监控
  582. /// </summary>
  583. /// <param name="param"></param>
  584. /// <returns></returns>
  585. private bool CycleManualMonitor(object[] param)
  586. {
  587. if (WaferInfo == null || WaferInfo.IsEmpty)
  588. {
  589. PostMsg(PlatingCellMsg.Error);
  590. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module.ToString(), "Wafer is empty");
  591. _currentStepState = "";
  592. _currentRecipe = null;
  593. return false;
  594. }
  595. if (WaferInfo.WaferType==WaferType.Production)
  596. {
  597. RState state = _runRecipeRoutine.Monitor();
  598. _currentStepState = _runRecipeRoutine.CurrentStep;
  599. _achievedCycle = _runRecipeRoutine.GetCurrentCycle();
  600. //LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module.ToString(), _currentStepState);
  601. if (state == RState.Failed || state == RState.Timeout)
  602. {
  603. PostMsg(PlatingCellMsg.Error);
  604. _currentStepState = "";
  605. _currentRecipe = null;
  606. return false;
  607. }
  608. bool result = state == RState.End;
  609. if (result)
  610. {
  611. _currentStepState = "";
  612. _currentRecipe = null;
  613. }
  614. return result;
  615. }
  616. else
  617. {
  618. RState state = _dummyRinseRunRecipeRoutine.Monitor();
  619. _currentStepState = _dummyRinseRunRecipeRoutine.CurrentStep;
  620. _achievedCycle = _dummyRinseRunRecipeRoutine.GetCurrentCycle();
  621. //LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module.ToString(), _currentStepState);
  622. if (state == RState.Failed || state == RState.Timeout)
  623. {
  624. PostMsg(PlatingCellMsg.Error);
  625. _currentStepState = "";
  626. _currentRecipe = null;
  627. return false;
  628. }
  629. bool result = state == RState.End;
  630. if (result)
  631. {
  632. _currentStepState = "";
  633. _currentRecipe = null;
  634. }
  635. return result;
  636. }
  637. }
  638. /// <summary>
  639. /// 中止
  640. /// </summary>
  641. /// <param name="param"></param>
  642. /// <returns></returns>
  643. private bool RunRecipeAbort(object[] param)
  644. {
  645. _runRecipeRoutine.Abort();
  646. _currentStepState = "";
  647. return true;
  648. }
  649. #endregion
  650. #region unload
  651. /// <summary>
  652. /// unload
  653. /// </summary>
  654. /// <param name="param"></param>
  655. /// <returns></returns>
  656. private bool Unload(object[] param)
  657. {
  658. return _unloadRoutine.Start(param) == RState.Running;
  659. }
  660. /// <summary>
  661. /// 监控
  662. /// </summary>
  663. /// <param name="param"></param>
  664. /// <returns></returns>
  665. private bool UnloadMonitor(object[] param)
  666. {
  667. RState state = _unloadRoutine.Monitor();
  668. if (state == RState.Failed || state == RState.Timeout)
  669. {
  670. PostMsg(PlatingCellMsg.Error);
  671. return false;
  672. }
  673. return state == RState.End;
  674. }
  675. /// <summary>
  676. /// 中止
  677. /// </summary>
  678. /// <param name="param"></param>
  679. /// <returns></returns>
  680. private bool UnloadAbort(object[] param)
  681. {
  682. _unloadRoutine.Abort();
  683. return true;
  684. }
  685. #endregion
  686. public bool Check(int msg, out string reason, params object[] args)
  687. {
  688. reason = "";
  689. return true;
  690. }
  691. public bool CheckAcked(int msg)
  692. {
  693. throw new NotImplementedException();
  694. }
  695. public int Invoke(string function, params object[] args)
  696. {
  697. switch (function)
  698. {
  699. case "HomeAll":
  700. if (IsIdle)
  701. {
  702. return (int)FSM_MSG.NONE;
  703. }
  704. if (CheckToPostMessage<PlatingCellState, PlatingCellMsg>(eEvent.ERR_PLATINGCELL, Module.ToString(), (int)PlatingCellMsg.Initialize))
  705. {
  706. return (int)PlatingCellMsg.Initialize;
  707. }
  708. else
  709. {
  710. return (int)FSM_MSG.NONE;
  711. }
  712. }
  713. return (int)FSM_MSG.NONE;
  714. }
  715. }
  716. public enum PlatingCellMsg
  717. {
  718. NONE,
  719. Error,
  720. ResumeError,
  721. Initialize,
  722. Manual,
  723. Auto,
  724. CloseFlowValve,
  725. OpenFlowValve,
  726. RunRecipe,
  727. Abort,
  728. Init,
  729. CCR,
  730. CCRAbort,
  731. Unload
  732. }
  733. }