PlatingCellEntity.cs 28 KB

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