| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.ToolLayout;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Modules.PlatingCell;
- using PunkHPX8_RT.Modules.Reservoir;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Markup;
- namespace PunkHPX8_RT.Modules
- {
- public class ReservoirCellHomeRoutine : RoutineBase, IRoutine
- {
- private enum ReservoirStep
- {
- ReservoirHome,
- ReservoirHomeWait,
- WaitMatcherIdle,
- CellHome,
- End,
- }
- #region 内部变量
- private ReservoirEntity _reservoirEntity;
- private PlatingCellEntity _platingCellEntity;
- private string _matcher = "";
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public ReservoirCellHomeRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.RunIf(ReservoirStep.ReservoirHome, _reservoirEntity.IsAuto, ReservoirHome, _delay_1ms)
- .WaitWithStopConditionIf(ReservoirStep.ReservoirHomeWait,_reservoirEntity.IsAuto,() => { return _reservoirEntity.IsIdle; }, () => { return _reservoirEntity.State != ReservoirState.Initializing && !_reservoirEntity.IsIdle; })
- .Wait(ReservoirStep.WaitMatcherIdle,ChechMatcherIdle,_delay_2m)
- .Run(ReservoirStep.CellHome, MetalsHome, _delay_1ms)
- .End(ReservoirStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// Reservoir Home
- /// </summary>
- /// <returns></returns>
- private bool ReservoirHome()
- {
- int reservoirInvoke = _reservoirEntity.Invoke("HomeAll");
- return reservoirInvoke==(int)ReservoirMsg.Initialize;
- }
- /// <summary>
- /// 检验匹配另一个是否完成Idle
- /// </summary>
- /// <returns></returns>
- private bool ChechMatcherIdle()
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (reservoirItem == null)
- {
- return false;
- }
- List<PlatingCellItem> platingCellItems = reservoirItem.PlatingCells;
- if (platingCellItems == null || platingCellItems.Count == 0)
- {
- return false;
- }
- foreach (PlatingCellItem item in platingCellItems)
- {
- if (!item.Installed)
- {
- continue;
- }
- _platingCellEntity= Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(item.ModuleName);
- _matcher=ModuleMatcherManager.Instance.GetMatcherByModule(item.ModuleName);
- break;
- }
- if (string.IsNullOrEmpty(_matcher))
- {
- return false;
- }
- if (ModuleMatcherManager.Instance.IsMatcherFirst(_platingCellEntity.Module.ToString()))
- {
- return true;
- }
- PlatingCellEntity matherEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(_matcher);
- if(matherEntity == null)
- {
- return true;
- }
- if (matherEntity.IsDisable)
- {
- return true;
- }
- if (!matherEntity.IsAuto)
- {
- return true;
- }
- if (matherEntity.IsError)
- {
- return true;
- }
- return matherEntity.IsIdle;
- }
- /// <summary>
- /// Metal Home
- /// </summary>
- /// <returns></returns>
- private bool MetalsHome()
- {
- if (_platingCellEntity.IsAuto)
- {
- _platingCellEntity.Invoke("HomeAll");
- }
- return true;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- return Runner.Start(Module.ToString(), "Reservoir PlatingCell Home");
- }
-
- }
- }
|