ReservoirCellHomeRoutine.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Routine;
  5. using MECF.Framework.Common.ToolLayout;
  6. using PunkHPX8_Core;
  7. using PunkHPX8_RT.Modules.PlatingCell;
  8. using PunkHPX8_RT.Modules.Reservoir;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Markup;
  15. namespace PunkHPX8_RT.Modules
  16. {
  17. public class ReservoirCellHomeRoutine : RoutineBase, IRoutine
  18. {
  19. private enum ReservoirStep
  20. {
  21. ReservoirHome,
  22. ReservoirHomeWait,
  23. WaitMatcherIdle,
  24. CellHome,
  25. End,
  26. }
  27. #region 内部变量
  28. private ReservoirEntity _reservoirEntity;
  29. private PlatingCellEntity _platingCellEntity;
  30. private string _matcher = "";
  31. #endregion
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. /// <param name="module"></param>
  36. public ReservoirCellHomeRoutine(string module) : base(module)
  37. {
  38. }
  39. /// <summary>
  40. /// 中止
  41. /// </summary>
  42. public void Abort()
  43. {
  44. Runner.Stop("Manual abort");
  45. }
  46. /// <summary>
  47. /// 监控
  48. /// </summary>
  49. /// <returns></returns>
  50. public RState Monitor()
  51. {
  52. Runner.RunIf(ReservoirStep.ReservoirHome, _reservoirEntity.IsAuto, ReservoirHome, _delay_1ms)
  53. .WaitWithStopConditionIf(ReservoirStep.ReservoirHomeWait,_reservoirEntity.IsAuto,() => { return _reservoirEntity.IsIdle; }, () => { return _reservoirEntity.State != ReservoirState.Initializing && !_reservoirEntity.IsIdle; })
  54. .Wait(ReservoirStep.WaitMatcherIdle,ChechMatcherIdle,_delay_2m)
  55. .Run(ReservoirStep.CellHome, MetalsHome, _delay_1ms)
  56. .End(ReservoirStep.End, NullFun, _delay_1ms);
  57. return Runner.Status;
  58. }
  59. /// <summary>
  60. /// Reservoir Home
  61. /// </summary>
  62. /// <returns></returns>
  63. private bool ReservoirHome()
  64. {
  65. int reservoirInvoke = _reservoirEntity.Invoke("HomeAll");
  66. return reservoirInvoke==(int)ReservoirMsg.Initialize;
  67. }
  68. /// <summary>
  69. /// 检验匹配另一个是否完成Idle
  70. /// </summary>
  71. /// <returns></returns>
  72. private bool ChechMatcherIdle()
  73. {
  74. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  75. if (reservoirItem == null)
  76. {
  77. return false;
  78. }
  79. List<PlatingCellItem> platingCellItems = reservoirItem.PlatingCells;
  80. if (platingCellItems == null || platingCellItems.Count == 0)
  81. {
  82. return false;
  83. }
  84. foreach (PlatingCellItem item in platingCellItems)
  85. {
  86. if (!item.Installed)
  87. {
  88. continue;
  89. }
  90. _platingCellEntity= Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(item.ModuleName);
  91. _matcher=ModuleMatcherManager.Instance.GetMatcherByModule(item.ModuleName);
  92. break;
  93. }
  94. if (string.IsNullOrEmpty(_matcher))
  95. {
  96. return false;
  97. }
  98. if (ModuleMatcherManager.Instance.IsMatcherFirst(_platingCellEntity.Module.ToString()))
  99. {
  100. return true;
  101. }
  102. PlatingCellEntity matherEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(_matcher);
  103. if(matherEntity == null)
  104. {
  105. return true;
  106. }
  107. if (matherEntity.IsDisable)
  108. {
  109. return true;
  110. }
  111. if (!matherEntity.IsAuto)
  112. {
  113. return true;
  114. }
  115. if (matherEntity.IsError)
  116. {
  117. return true;
  118. }
  119. return matherEntity.IsIdle;
  120. }
  121. /// <summary>
  122. /// Metal Home
  123. /// </summary>
  124. /// <returns></returns>
  125. private bool MetalsHome()
  126. {
  127. if (_platingCellEntity.IsAuto)
  128. {
  129. _platingCellEntity.Invoke("HomeAll");
  130. }
  131. return true;
  132. }
  133. /// <summary>
  134. /// 启动
  135. /// </summary>
  136. /// <param name="objs"></param>
  137. /// <returns></returns>
  138. public RState Start(params object[] objs)
  139. {
  140. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  141. return Runner.Start(Module.ToString(), "Reservoir PlatingCell Home");
  142. }
  143. }
  144. }