| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 | using System;using System.Xml;using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.Device;using Aitex.Core.RT.Event;using Aitex.Core.RT.IOCore;using Aitex.Core.RT.Log;using Aitex.Core.RT.SCCore;using Aitex.Core.Util;namespace VirgoRT.Devices{    public enum BoostPumpEnable    {        Disable = 0,        Enable = 1,    }    public class IoBoostPump : BaseDevice, IDevice    {        private DIAccessor _diBoosterInvAlarm = null;        private DIAccessor _diBoosterInvRun = null;        private DIAccessor _diBreakerState;        private DIAccessor _diPowerOn;        private AOAccessor _aoBoosterEnable = null;        private AOAccessor _aoBoosterSetPoint = null;        private AIAccessor _aiInverterFrequency = null;        private SCConfigItem _scPressureSetPointMaxValue = null;        private SCConfigItem _scEnableFrequency = null;        public bool IsRunning        {            get            {                if (_diPowerOn != null)                    return _diPowerOn.Value;                if (_diBreakerState != null)                    return _diBreakerState.Value;                return true;            }        }        public bool IsError        {            get            {                return _diBoosterInvAlarm != null && _diBoosterInvAlarm.Value;            }        }        public double PressureSetPointMax        {            get            {                if (_scPressureSetPointMaxValue == null)                    return 760000;                return _scPressureSetPointMaxValue.DoubleValue;            }        }        [Subscription(AITBoostPumpDataPropertyName.EnableSetPoint)]        public double EnableSetPoint        {            get            {                if (_aoBoosterEnable == null)                    return 0;                return _aoBoosterEnable.Value;            }        }        [Subscription(AITBoostPumpDataPropertyName.PressureSetPoint)]        public double PressureSetPoint        {            get            {                if (_aoBoosterSetPoint == null)                    return 0;                return _aoBoosterSetPoint.Value;            }        }        [Subscription(AITBoostPumpDataPropertyName.InverterFrequency)]        public double InverterFrequency        {            get            {                if (_aiInverterFrequency == null)                    return 0;                return _aiInverterFrequency.Value;            }        }        public bool EnableFrequency        {            get            {                return _scEnableFrequency == null || _scEnableFrequency.BoolValue;            }        }        private R_TRIG _trigError = new R_TRIG();        public IoBoostPump(string module, XmlElement node, string ioModule = "")        {            base.Module = module;            base.Name = node.GetAttribute("id");            base.Display = node.GetAttribute("display");            base.DeviceID = node.GetAttribute("schematicId");            _diBoosterInvAlarm = ParseDiNode("diBoosterInvAlarm", node, ioModule);            _diBoosterInvRun = ParseDiNode("diBoosterInvRun", node, ioModule);            _diBreakerState = ParseDiNode("diBreakerState", node, ioModule);            _diPowerOn = ParseDiNode("diBoosterPowerOn", node, ioModule);            _aoBoosterEnable = ParseAoNode("aoBoosterEnable", node, ioModule);            _aoBoosterSetPoint = ParseAoNode("aoBoosterSetPoint", node, ioModule);            _aiInverterFrequency = ParseAiNode("aiFrequency", node, ioModule);            _scPressureSetPointMaxValue = ParseScNode("scPressureSetPointMaxValue", node);            _scEnableFrequency = ParseScNode("scEnableFrequency", node);        }        public bool Initialize()        {            DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>            {                AITBoostPumpData data = new AITBoostPumpData()                {                    DeviceName = Name,                    DeviceSchematicId = DeviceID,                    DisplayName = Display,                    IsError = IsError,                    IsRunning = IsRunning,                    EnableSetPoint = EnableSetPoint,                    PressureSetPoint = PressureSetPoint,                    InverterFrequency = InverterFrequency,                    PressureSetPointMax = PressureSetPointMax,                    EnableFrequency = EnableFrequency,                };                return data;            }, SubscriptionAttribute.FLAG.IgnoreSaveDB);            DEVICE.Register($"{Module}.{Name}.{AITBoostPumpOperation.SetEnable}", (out string reason, int time, object[] param) =>            {                if (IsError)                {                    reason = string.Format("boost pump is in error state, recover before set enable");                    return false;                }                int isEnable = Convert.ToInt16((string)param[0]);                if ((isEnable != (int)BoostPumpEnable.Enable) && (isEnable != (int)BoostPumpEnable.Disable))                {                    reason = string.Format("boost pump set value {0} is not valid, should be 0 || 1", isEnable);                    return false;                }                reason = string.Empty;                _aoBoosterEnable.Value = (short)isEnable;                return true;            });            DEVICE.Register($"{Module}.{Name}.{AITBoostPumpOperation.SetPressure}", (out string reason, int time, object[] param) =>            {                if (IsError)                {                    reason = string.Format("boost pump is in error state, recover before set pressure");                    return false;                }                double pressureSetPoint = Convert.ToDouble((string)param[0]);                if (pressureSetPoint > PressureSetPointMax)                {                    reason = string.Format("boost pump pressure set to {0} is not valid, should be less than {1}", pressureSetPoint, PressureSetPointMax);                    return false;                }                _aoBoosterSetPoint.Value = (short)pressureSetPoint;                reason = string.Empty;                return true;            });            return true;        }        public bool SetEnable(int enable)        {            if (IsError)            {                return false;            }            if ((enable != (int)BoostPumpEnable.Enable) && (enable != (int)BoostPumpEnable.Disable))            {                LOG.Error(string.Format("boost pump set value {0} is not valid, should be 0 || 1", enable));                return false;            }            if (_aoBoosterEnable != null)            {                _aoBoosterEnable.Value = (short)enable;            }            return true;        }        public bool SetPressure(double setpoint, out string reason)        {            if (setpoint > PressureSetPointMax)            {                reason = string.Format("boost pump setpoint {0}, should be less than {1}", setpoint, PressureSetPointMax);                return false;            }            reason = string.Empty;            _aoBoosterSetPoint.Value = (short)setpoint;            return true;        }        public void Terminate()        {        }        public void Monitor()        {            try            {                _trigError.CLK = IsError;                if (_trigError.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultAlarm, "Booster Inverter Alarm");                }            }            catch (Exception ex)            {                LOG.Write(ex);                throw ex;            }        }        public void Reset()        {            _trigError.RST = true;        }    }}
 |