| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 | using Aitex.Core.RT.Device;using Aitex.Core.RT.OperationCenter;using Aitex.Core.Util;using MECF.Framework.Common.CommonData;using MECF.Framework.Common.Device.PowerSupplier;using MECF.Framework.Common.Device.Rinse;using MECF.Framework.Common.TwinCat;using CyberX8_RT.Devices.Metal;using CyberX8_RT.Devices.PowerSupplier;using CyberX8_RT.Devices.PUF;using System;using System.Collections.Generic;using System.Diagnostics.PerformanceData;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;using MECF.Framework.Common.ToolLayout;using CyberX8_RT.Modules.Reservoir;using CyberX8_RT.Modules;using CyberX8_RT.Devices.Reservoir;using MECF.Framework.Common.IOCore;namespace CyberX8_RT.Devices.Reservoir{    public class TotalReservoirDevice : BaseDevice, IDevice    {        #region 常量         private const string DIREPLEN_FLOW = "DiReplenFlow";        private const string COUNTER_VALUE = "CounterValue";        private const string COUNTER_START = "Start";        private const string COUNTER_STOP = "Stop";        private const string COUNTER_RESET = "Reset";        private const string EVAPORATOR_LEVEL = "EvaporatorLevel";        private const string HIGH_LEVEL = "HighLevel";        private const string STRATUS = "Stratus";        #endregion        #region 内部变量        /// <summary>        /// Di Replen Flow        /// </summary>        private CounterFlowData _diReplenFlow = new CounterFlowData();        /// <summary>        /// High Level        /// </summary>        private bool _highLevel;        /// <summary>        /// Evaporator Level        /// </summary>        private bool _evaporatorLevel;        /// <summary>        /// Counter字典        /// </summary>        private Dictionary<string, CounterFlowData> _nameCounterFlowData = new Dictionary<string, CounterFlowData>();        /// <summary>        /// 定时器        /// </summary>        private PeriodicJob _period;        #endregion        #region 属性        /// <summary>        /// Di Replen Flow        /// </summary>        private CounterFlowData DiReplenFlow { get { return _diReplenFlow; } }        /// <summary>        /// High Level        /// </summary>        public bool HighLevel { get { return _highLevel; } }        /// <summary>        /// Evaporator Level        /// </summary>        public bool EvaporatorLevel { get { return _evaporatorLevel; } }        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="moduleName"></param>        /// <param name="name"></param>        public TotalReservoirDevice() : base("Reservoir", "Reservoir", "Reservoir", "Reservoir")        {            _period = new PeriodicJob(500, OnTimer, "Reservoir.OnTimer", true, true);        }        /// <summary>        /// 初始化        /// </summary>        /// <returns></returns>        public bool Initialize()        {            InitializeParameter();            SubscribeValueAction();            InitializeOperation();            return true;        }        /// <summary>        /// 加载参数        /// </summary>        private void InitializeParameter()        {        }        /// <summary>        /// 初始化操作        /// </summary>        private void InitializeOperation()        {        }        /// <summary>        /// 订阅变量数值发生变化        /// </summary>        private void SubscribeValueAction()        {            BeckhoffCounterSubscribeUpdateVariable(DIREPLEN_FLOW, DiReplenFlow);            BeckhoffIoSubscribeUpdateVariable(EVAPORATOR_LEVEL);            BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);        }        /// <summary>        /// 订阅Counter变量        /// </summary>        /// <param name="variable"></param>        private void BeckhoffCounterSubscribeUpdateVariable(string variable, CounterFlowData counterFlowData)        {            _nameCounterFlowData[$"{Module}.{variable}"] = counterFlowData;            BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_VALUE, UpdateCounterVariableValue);            BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_START, UpdateCounterVariableValue);            BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_STOP, UpdateCounterVariableValue);            BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_RESET, UpdateCounterVariableValue);        }        /// <summary>        /// 订阅IO变量        /// </summary>        /// <param name="variable"></param>        private void BeckhoffIoSubscribeUpdateVariable(string variable)        {            IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateIOVariableValue);        }        /// <summary>        /// 更新变量数值        /// </summary>        /// <param name="variable"></param>        /// <param name="value"></param>        private void UpdateIOVariableValue(string variable, object value)        {            if (variable == HIGH_LEVEL)            {                _highLevel = (bool)value;            }            else if (variable == EVAPORATOR_LEVEL)            {                _evaporatorLevel = (bool)value;            }        }        /// <summary>        /// 更新变量数值        /// </summary>        /// <param name="variable"></param>        /// <param name="value"></param>        private void UpdateCounterVariableValue(string variable, object value)        {            string[] strAry = variable.Split('.');            string lastVariable = strAry[strAry.Length - 1];            PropertyInfo property = null;            string key = variable.Replace($".{lastVariable}", "");            if (_nameCounterFlowData.ContainsKey(key))            {                CounterFlowData counterFlowData = _nameCounterFlowData[key];                property = counterFlowData.GetType().GetProperty(lastVariable);                if (property != null)                {                    property.SetValue(counterFlowData, value);                }            }        }        /// <summary>        /// 定时器        /// </summary>        /// <returns></returns>        private bool OnTimer()        {            List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;            foreach (string module in reservoirs)            {                ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(module);                ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(module);                if (reservoirEntity != null && !reservoirEntity.IsError)                {                    if (reservoirItem.SubType == STRATUS)                    {                        StandardHotReservoirDevice reservoirDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(module);                        if (reservoirDevice.IsDireplenOn)                        {                            break;                        }                        if (reservoirDevice.NeedAutoDireplen && !reservoirDevice.IsDireplenOn)                        {                            reservoirDevice.AutoDireplen();                        }                    }                }                else                {                    continue;                }            }            return true;        }        public void Monitor()        {        }        public void Reset()        {        }        public void Terminate()        {            _period.Stop(false);        }    }}
 |