using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.Util; using MECF.Framework.Common.Routine; using PunkHPX8_Core; using PunkHPX8_RT.Devices.VpwCell; using PunkHPX8_RT.Devices.VpwMain; using SecsGem.Core.ItemModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PunkHPX8_RT.Modules.VpwMain { public class VPWHomeRoutine : RoutineBase, IRoutine { private enum HomeStep { ChameberUp, OpenCellDrainValve, End } #region 常量 #endregion #region 内部变量 /// /// Cell device集合 /// private List _vpwCellDevices; /// /// Main Device /// private VpwMainDevice _mainDevice; /// /// cell集合 /// private List _cellLst=new List(); #endregion /// /// 构造函数 /// /// /// public VPWHomeRoutine(string module) : base(module) { } /// /// 中止 /// public void Abort() { Runner.Stop("Manual abort"); } /// /// 监控 /// /// public RState Monitor() { Runner.Run(HomeStep.ChameberUp, _mainDevice.ChamberUp, CheckChamberClosed, _delay_1s) .Run(HomeStep.OpenCellDrainValve, OpenCellDrainValve, CheckCellDrainValveStatus, _delay_2s) .End(HomeStep.End,NullFun, _delay_1ms); return Runner.Status; } /// /// 检验Chamber关闭 /// /// private bool CheckChamberClosed() { return _mainDevice.CommonData.ChamberClosed && !_mainDevice.CommonData.ChamberOpened; } /// /// 打开所有cell valve /// /// private bool OpenCellDrainValve() { foreach(var device in _vpwCellDevices) { VpwCellEntity vpwCellEntity = Singleton.Instance.GetModule(device.Module); if (vpwCellEntity.IsAuto||vpwCellEntity.IsManual) { _cellLst.Add(device); bool result= device.DrainValveOn(); if (!result) { LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} open drain valve failed"); CloseCellDrainValve(); return false; } } } return true; } /// /// 检验Cell Drain状态 /// /// private bool CheckCellDrainValveStatus() { foreach (var item in _cellLst) { bool result = item.CommonData.DrainValve; if (!result) { LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{item.Module} drain valve is not opened"); CloseCellDrainValve(); return false; } } return true; } /// /// 关闭所有cell的Drain valve /// private void CloseCellDrainValve() { foreach (var item in _cellLst) { item.DrainValveOff(); } } /// /// 启动 /// /// /// public RState Start(params object[] objs) { List lstDevice = (List)objs[0]; _vpwCellDevices.Clear(); _cellLst.Clear(); for (int i = 0; i < lstDevice.Count; i++) { _vpwCellDevices.Add(lstDevice[i]); } _mainDevice = DEVICE.GetDevice(Module.ToString()); return Runner.Start(Module,"VPW Home"); } } }