| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 | using Aitex.Core.RT.Device;using Aitex.Core.RT.Log;using Aitex.Core.RT.SCCore;using CyberX8_RT.Devices.Metal;using MECF.Framework.Common.CommonData.Reservoir;using MECF.Framework.Common.RecipeCenter;using MECF.Framework.Common.ToolLayout;using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;namespace CyberX8_RT.Devices.Reservoir{    public class ReservoirPumpSpeedHelper    {        #region 内部变量        /// <summary>        /// 时间        /// </summary>        private DateTime _updateTime=DateTime.Now;        /// <summary>        /// 模块名称        /// </summary>        private string _moduleName;        /// <summary>        /// AN流量总和        /// </summary>        private double _anTotalFlow = 0;        /// <summary>        /// CA流量总和        /// </summary>        private double _caTotalFlow = 0;        /// <summary>        /// 设备对象        /// </summary>        CompactMembranReservoirDevice _device;        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="moduleName"></param>        public ReservoirPumpSpeedHelper(string moduleName,CompactMembranReservoirDevice reservoirDevice)        {            _moduleName = moduleName;            _device = reservoirDevice;        }        /// <summary>        /// 监控        /// </summary>        public void Monitor(ResRecipe resRecipe)        {            int cellFlowUpdatePeriod = SC.GetValue<int>("Reservoir.CellFlowUpdatePeriod");            if(DateTime.Now.Subtract(_updateTime).TotalSeconds > cellFlowUpdatePeriod)            {                _updateTime = DateTime.Now;                AdjustANPumpSpeed(resRecipe);                AdjustCAPumpSpeed(resRecipe);            }        }        /// <summary>        /// 调节阳极泵速        /// </summary>        private void AdjustANPumpSpeed(ResRecipe resRecipe)        {            double anPumpSpeed = _device.ReservoirData.ANPump;            if (anPumpSpeed != 0)            {                double averageANFlow = GetAverageANFlow();                if (averageANFlow == 0)                {                    return;                }                double anFlowDelta = resRecipe.ANFlowSetPoint - averageANFlow;                double newANPumpSpeed = 1.8 * anFlowDelta + anPumpSpeed;                if (newANPumpSpeed <= 0)                {                    return;                }                if (Math.Abs(newANPumpSpeed - anPumpSpeed) >= 0.01)                {                    _device.AnPump(newANPumpSpeed);                }            }        }        /// <summary>        /// 调节阳极泵速        /// </summary>        private void AdjustCAPumpSpeed(ResRecipe resRecipe)        {            if (_device.ReservoirData.CAPumpEnable)            {                double caPumpSpeed = _device.ReservoirData.CAPumpSpeed;                double averageCAFlow = GetAverageCAFlow();                if (averageCAFlow == 0)                {                    return;                }                double caPumpMaxSpeed = SC.GetValue<double>("Reservoir.CAMaxPumpSpeed");                double caFlowDelta = resRecipe.CAFlowSetPoint - averageCAFlow;                double newCAPumpSpeed = 330 * caFlowDelta + caPumpSpeed;                if (newCAPumpSpeed <= 0 || newCAPumpSpeed > caPumpMaxSpeed)                {                    return;                }                if (Math.Abs(newCAPumpSpeed - caPumpSpeed) >= 10)                {                    _device.CAPumpSpeed(newCAPumpSpeed);                }            }        }        /// <summary>        /// 获取平均阳极流量         /// </summary>        /// <returns></returns>        private double GetAverageANFlow()        {            int count = 0;            _anTotalFlow = 0;            double ANOverFlow = SC.GetValue<double>("Reservoir.ANOverFlow");            ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(_moduleName);            if (reservoirItem == null)            {                return 0;            }            List<MetalItem> metalItems = reservoirItem.MetalCells;            if (metalItems == null || metalItems.Count == 0)            {                return 0;            }            foreach (MetalItem metalItem in metalItems)            {                CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);                if (metalDevice == null || metalDevice.IsManual || metalDevice.IsDisable)                {                    continue;                }                if (metalDevice.MetalDeviceData.ANAPinEnable&&metalDevice.ANACellFlow.CounterValue < ANOverFlow)                {                    _anTotalFlow += metalDevice.ANACellFlow.CounterValue;                    count++;                }                if (metalDevice.MetalDeviceData.ANBPinEnable&&metalDevice.ANBCellFlow.CounterValue<ANOverFlow)                {                    _anTotalFlow += metalDevice.ANBCellFlow.CounterValue;                    count++;                }            }            if (count != 0)            {                return _anTotalFlow / count;            }            return 0;        }        /// <summary>        /// 获取平均阳极流量         /// </summary>        /// <returns></returns>        private double GetAverageCAFlow()        {            int count = 0;            _caTotalFlow = 0;            ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(_moduleName);            if (reservoirItem != null)            {                List<MetalItem> metalItems = reservoirItem.MetalCells;                if (metalItems != null && metalItems.Count > 0)                {                    foreach (MetalItem metalItem in metalItems)                    {                        CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);                        if (metalDevice != null&&metalDevice.IsAuto)                        {                            if (metalDevice.MetalDeviceData.CellFlowValve)                            {                                count++;                                _caTotalFlow += metalDevice.MetalDeviceData.CellFlow;                            }                        }                    }                }                if (count != 0)                {                    return _caTotalFlow / count;                }            }            return 0;        }    }}
 |