| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912 | 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.OperationCenter;using Aitex.Core.RT.SCCore;using Aitex.Core.RT.Tolerance;using Aitex.Core.UI.Control;using Aitex.Core.Util;using MECF.Framework.Common.Device.Bases;namespace VirgoRT.Devices{    public class IoPump : PumpBase    {        [Subscription(AITPumpProperty.EnableDryPump)]        public bool IsDryPumpEnabled        {            get            {                return _scEnableDryPump == null || _scEnableDryPump.BoolValue;            }        }        [Subscription(AITPumpProperty.EnableWaterFlow)]        public bool EnableWaterFlow        {            get            {                return _scEnableWaterFlow != null && _scEnableWaterFlow.BoolValue;            }        }        [Subscription(AITPumpProperty.WaterFlowWarning)]        public bool WaterFlowWarning        {            get            {                return _checkWaterFlowWarning.Result;            }        }        //[Subscription(AITPumpProperty.WaterFlowAlarm)]        public bool WaterFlowAlarm        {            get            {                return _diWaterFlowAlarm.Value;            }        }        [Subscription(AITPumpProperty.WaterFlowAlarmSetPoint)]        public bool WaterFlowAlarmSetPoint        {            get            {                return _doWaterFlowAlarm != null && _doWaterFlowAlarm.Value;            }            set            {                if (_doWaterFlowAlarm != null)                {                    string reason;                    if (!_doWaterFlowAlarm.SetValue(value, out reason))                    {                        LOG.Write(reason);                    }                }            }        }        [Subscription(AITPumpProperty.WaterFlowWarningTime)]        public float WaterFlowWarningTime        {            get            {                return _scWaterFlowOutOfToleranceWarningTime == null ? 0 : (float)_scWaterFlowOutOfToleranceWarningTime.Value;            }        }        [Subscription(AITPumpProperty.WaterFlowAlarmTime)]        public float WaterFlowAlarmTime        {            get            {                return _scWaterFlowOutOfToleranceAlarmTime == null ? 0 : (float)_scWaterFlowOutOfToleranceAlarmTime.Value;            }        }        [Subscription(AITPumpProperty.WaterFlowValue)]        public double WaterFlowValue        {            get            {                return _aiWaterFlow == null ? 0 : _aiWaterFlow.Value;            }        }        [Subscription(AITPumpProperty.WaterFlowMinValue)]        public double WaterFlowMinValue        {            get            {                return _scWaterFlowMinValue == null ? 0 : (float)_scWaterFlowMinValue.Value;            }        }        [Subscription(AITPumpProperty.WaterFlowMaxValue)]        public double WaterFlowMaxValue        {            get            {                return _scWaterFlowMaxValue == null ? 0 : (float)_scWaterFlowMaxValue.Value;            }        }        [Subscription(AITPumpProperty.EnableN2Pressure)]        public bool EnableN2Pressure        {            get            {                if (_scEnableN2Pressure == null || _scN2PressureMinValue == null || _scN2PressureMaxValue == null ||                    _scN2PressureOutOfToleranceWarningTime == null || _scN2PressureOutOfToleranceAlarmTime == null)                    return false;                return _scEnableN2Pressure != null && _scEnableN2Pressure.BoolValue;            }        }        [Subscription(AITPumpProperty.N2PressureWarning)]        public bool N2PressureWarning        {            get            {                return _checkN2PressureWarning.Result;            }        }        [Subscription(AITPumpProperty.N2PressureValue)]        public float N2PressureValue        {            get            {                return _aiN2Pressure == null ? 0 : _aiN2Pressure.Value;            }        }        [Subscription(AITPumpProperty.N2PressureWarningTime)]        public float N2PressureWarningTime        {            get            {                return _scN2PressureOutOfToleranceWarningTime == null ? 0 : (float)_scN2PressureOutOfToleranceWarningTime.Value;            }        }        [Subscription(AITPumpProperty.N2PressureAlarmTime)]        public float N2PressureAlarmTime        {            get            {                return _scN2PressureOutOfToleranceAlarmTime == null ? 0 : (float)_scN2PressureOutOfToleranceAlarmTime.Value;            }        }        [Subscription(AITPumpProperty.N2PressureMinValue)]        public float N2PressureMinValue        {            get            {                return _scN2PressureMinValue == null ? 0 : (float)_scN2PressureMinValue.Value;            }        }        [Subscription(AITPumpProperty.N2PressureMaxValue)]        public float N2PressureMaxValue        {            get            {                return _scN2PressureMaxValue == null ? 0 : (float)_scN2PressureMaxValue.Value;            }        }        //[Subscription(AITPumpProperty.N2PressureAlarm)]        public bool N2PressureAlarm        {            get            {                return _diN2Alarm.Value;            }        }        [Subscription(AITPumpProperty.N2PressureAlarmSetPoint)]        public bool N2PressureAlarmSetPoint        {            get            {                return _doN2PressureAlarm != null && _doN2PressureAlarm.Value;            }            set            {                if (_doN2PressureAlarm != null)                {                    string reason;                    if (!_doN2PressureAlarm.SetValue(value, out reason))                    {                        LOG.Write(reason);                    }                }            }        }        public int LocalRemoteMode        {            get            {                return _doLocalRemote.Value ? 1 : 0;            }        }        public bool HasError        {            get            {                return IsPumpTempAlarm || IsPumpOverloadAlarm || IsError || N2PressureAlarm || WaterFlowAlarm || _trigExhaustPressureAlarm.M;            }        }        public bool HasWarning        {            get            {                return IsPumpN2FlowWarning || IsPumpTempWarning || IsWaterFlowWarning || IsWarning;            }        }        [Subscription(AITPumpProperty.IsRunning)]        public override bool IsRunning        {            get            {                if (_diRunning != null)                    return _diRunning.Value;                if (_diPowerOn != null)                    return _diPowerOn.Value;                return true; //默认常开            }        }        public bool IsWarning        {            get            {                return _diWarning != null && _diWarning.Value;            }        }        public bool IsPumpTempWarning        {            get            {                return _diPumpTempWaring != null && _diPumpTempWaring.Value;            }        }        public bool IsPumpN2FlowWarning        {            get            {                return _diPumpN2FlowWarning != null && _diPumpN2FlowWarning.Value;            }        }        public override bool IsError        {            get            {                return _diError != null && _diError.Value;            }        }        public bool IsWaterFlowWarning        {            get            {                return _diWaterFlowWarning != null && _diWaterFlowWarning.Value;            }        }        public bool IsPumpTempAlarm        {            get            {                return _diPumpTempAlarm != null && _diPumpTempAlarm.Value;            }        }        public bool IsPumpOverloadAlarm        {            get            {                return _diOverloadAlarm != null && _diOverloadAlarm.Value;            }        }        public double H2OSensorMassWarningThreshold        {            get            {                return _aiH2OSensorMassWarningThreshold == null ? 0 : _aiH2OSensorMassWarningThreshold.Value;            }            set            {                if (_scH2OSensorMassWarningThreshold == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scH2OSensorMassWarningThreshold.Min), result);                result = Math.Min(int.Parse(_scH2OSensorMassWarningThreshold.Max), result);                _scH2OSensorMassWarningThreshold.DoubleValue = result;                //_aoH2OSensorMassWarningThreshold.Value = (float)value;            }        }        public double H2OSensorMassWarningTime        {            get            {                return _aiH2OSensorMassWarningTime == null ? 0 : _aiH2OSensorMassWarningTime.Value;            }            set            {                if (_scH2OSensorMassWarningTime == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scH2OSensorMassWarningTime.Min), result);                result = Math.Min(int.Parse(_scH2OSensorMassWarningTime.Max), result);                _scH2OSensorMassWarningTime.DoubleValue = result;                //_aoH2OSensorMassWarningTime.Value = (float) value;            }        }        public double N2PurgeFlow        {            get            {                return _aiN2PurgeFlow == null ? 0 : _aiN2PurgeFlow.Value;            }        }        public double N2PurgeFlowWarningThreshold        {            get            {                return _aiN2PurgeFlowWarningThreshold == null ? 0 : _aiN2PurgeFlowWarningThreshold.Value;            }            set            {                if (_scN2PurgeFlowWarning == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scN2PurgeFlowWarning.Min), result);                result = Math.Min(int.Parse(_scN2PurgeFlowWarning.Max), result);                _scN2PurgeFlowWarning.DoubleValue = result;                //_aoN2PurgeFlowWarning.Value = (float) value;            }        }        public double N2PurgeFlowWarningTime        {            get            {                return _aiN2PurgeFlowWarningTime == null ? 0 : _aiN2PurgeFlowWarningTime.Value;            }            set            {                if (_scN2PurgeFlowWarningTime == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scN2PurgeFlowWarningTime.Min), result);                result = Math.Min(int.Parse(_scN2PurgeFlowWarningTime.Max), result);                _scN2PurgeFlowWarningTime.DoubleValue = result;                //_aoN2PurgeFlowWarningTime.Value = (float) value;            }        }        public double ExhaustPressure        {            get            {                return _aiExhaustPressure == null ? 0 : _aiExhaustPressure.Value;            }        }        public double ExhaustPressurePreWarningThreshold        {            get            {                return _aiExhaustPressurePreWarningThreshold == null ? 0 : _aiExhaustPressurePreWarningThreshold.Value;            }            set            {                if (_scExhaustPressurePreWarningThreshold == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scExhaustPressurePreWarningThreshold.Min), result);                result = Math.Min(int.Parse(_scExhaustPressurePreWarningThreshold.Max), result);                _scExhaustPressurePreWarningThreshold.DoubleValue = result;                //_aoExhaustPressurePreWarningThreshold.Value = (float) value;            }        }        public double ExhaustPressurePreWarningTime        {            get            {                return _aiExhaustPressurePreWarningTime == null ? 0 : _aiExhaustPressurePreWarningTime.Value;            }            set            {                if (_scExhaustPressurePreWarningTime == null)                    return;                double result = value;                result = Math.Max(int.Parse(_scExhaustPressurePreWarningTime.Min), result);                result = Math.Min(int.Parse(_scExhaustPressurePreWarningTime.Max), result);                _scExhaustPressurePreWarningTime.DoubleValue = result;                //_aoExhaustPressurePreWarningTime.Value = (float) value;            }        }        public bool IsStartButtonPushed        {            get            {                return _diStart != null && _diStart.Value;            }        }        public bool IsStopButtonPushed        {            get            {                return _diStop != null && _diStop.Value;            }        }        private readonly DIAccessor _diRunning = null;        private readonly DIAccessor _diPumpTempWaring = null;        private readonly DIAccessor _diPumpN2FlowWarning = null;        private readonly DIAccessor _diPumpTempAlarm = null;        private readonly DIAccessor _diWaterFlowWarning = null;        private readonly DIAccessor _diOverloadAlarm;        private readonly DIAccessor _diPowerOn;        private readonly DIAccessor _diStart;        private readonly DIAccessor _diStop;        private readonly DIAccessor _diError;        private readonly DIAccessor _diWarning;        private readonly DIAccessor _diWaterFlowAlarm;        private readonly DIAccessor _diN2Warning;        private readonly DIAccessor _diN2Alarm;        private readonly DIAccessor _diExhaustPressureWarning;        private readonly DIAccessor _diExhaustPressureAlarm;        private readonly DIAccessor _diLogicWaterFlowAlarm;        private readonly DIAccessor _diLogicN2PressureAlarm;        private readonly DOAccessor _doStart;        private readonly DOAccessor _doStop;        private readonly DOAccessor _doLocalRemote;        private readonly DOAccessor _doWarningReset;        private readonly DOAccessor _doWaterFlowAlarm;        private readonly DOAccessor _doN2PressureAlarm;        private readonly AOAccessor _aoH2OSensorMassWarningThreshold;        private readonly AOAccessor _aoH2OSensorMassWarningTime;        private readonly AOAccessor _aoN2PurgeFlowWarning;        private readonly AOAccessor _aoN2PurgeFlowWarningTime;        private readonly AOAccessor _aoExhaustPressurePreWarningThreshold;        private readonly AOAccessor _aoExhaustPressurePreWarningTime;        private readonly AOAccessor _aoWaterFlowAlarmMinValue;        private readonly AOAccessor _aoWaterFlowAlarmMaxValue;        private readonly AOAccessor _aoN2PressureAlarmMinValue;        private readonly AOAccessor _aoN2PressureAlarmMaxValue;        private readonly AIAccessor _aiWaterFlow;        private readonly AIAccessor _aiN2Pressure;        private readonly AIAccessor _aiH2OSensorMassWarningThreshold;        private readonly AIAccessor _aiH2OSensorMassWarningTime;        private readonly AIAccessor _aiN2PurgeFlow;        private readonly AIAccessor _aiN2PurgeFlowWarningThreshold;        private readonly AIAccessor _aiN2PurgeFlowWarningTime;        private readonly AIAccessor _aiExhaustPressure;        private readonly AIAccessor _aiExhaustPressurePreWarningThreshold;        private readonly AIAccessor _aiExhaustPressurePreWarningTime;        private readonly SCConfigItem _scH2OSensorMassWarningThreshold;        private readonly SCConfigItem _scH2OSensorMassWarningTime;        private readonly SCConfigItem _scN2PurgeFlowWarning;        private readonly SCConfigItem _scN2PurgeFlowWarningTime;        private readonly SCConfigItem _scExhaustPressurePreWarningThreshold;        private readonly SCConfigItem _scExhaustPressurePreWarningTime;        private readonly SCConfigItem _scEnableWaterFlow;        private readonly SCConfigItem _scWaterFlowMinValue;        private readonly SCConfigItem _scWaterFlowMaxValue;        private readonly SCConfigItem _scWaterFlowOutOfToleranceWarningTime;        private readonly SCConfigItem _scWaterFlowOutOfToleranceAlarmTime;        private readonly SCConfigItem _scEnableN2Pressure;        private readonly SCConfigItem _scN2PressureMinValue;        private readonly SCConfigItem _scN2PressureMaxValue;        private readonly SCConfigItem _scN2PressureOutOfToleranceWarningTime;        private readonly SCConfigItem _scN2PressureOutOfToleranceAlarmTime;        private readonly SCConfigItem _scEnableDryPump;        private readonly R_TRIG _trigWarning = new R_TRIG();        private readonly R_TRIG _trigError = new R_TRIG();        private readonly R_TRIG _trigWaterFlowSensorWarning = new R_TRIG();        private readonly R_TRIG _trigWaterFlowSensorAlarm = new R_TRIG();        private readonly R_TRIG _trigN2Warning = new R_TRIG();        private readonly R_TRIG _trigN2Alarm = new R_TRIG();        private readonly R_TRIG _trigExhaustPressureWarning = new R_TRIG();        private readonly R_TRIG _trigExhaustPressureAlarm = new R_TRIG();        private readonly ToleranceChecker _checkN2PressureWarning = new ToleranceChecker();        private readonly ToleranceChecker _checkN2PressureAlarm = new ToleranceChecker();        private readonly ToleranceChecker _checkWaterFlowWarning = new ToleranceChecker();        private readonly ToleranceChecker _checkWaterFlowAlarm = new ToleranceChecker();        private readonly DeviceTimer _timer = new DeviceTimer();        private string PumpError = "PumpError";                public IoPump(string module, XmlElement node, string ioModule = "")        {            base.Module                            = module;            base.Name                              = node.GetAttribute("id");            base.Display                           = node.GetAttribute("display");            base.DeviceID                          = node.GetAttribute("schematicId");            _diError                               = ParseDiNode("diAlarm", node, ioModule);            _diRunning                             = ParseDiNode("diRunning", node, ioModule);            _diWarning                             = ParseDiNode("diWarning", node, ioModule);            _diOverloadAlarm                       = ParseDiNode("diOverloadAlarm", node, ioModule);            _diPowerOn                             = ParseDiNode("diPowerOn", node, ioModule);            _diStart                               = ParseDiNode("diStart", node, ioModule);            _diStop                                = ParseDiNode("diStop", node, ioModule);            _diPumpTempWaring                      = ParseDiNode("diPumpTempWaring", node, ioModule);            _diPumpTempAlarm                       = ParseDiNode("diPumpTempAlarm", node, ioModule);            _diWaterFlowWarning                    = ParseDiNode("diWaterFlowWarning", node, ioModule);            _diWaterFlowAlarm                      = ParseDiNode("diWaterFlowAlarm", node, ioModule);            _diN2Warning                           = ParseDiNode("diN2Warning", node, ioModule);            _diN2Alarm                             = ParseDiNode("diN2Alarm", node, ioModule);            _diExhaustPressureWarning              = ParseDiNode("diExhaustPressureWarning", node, ioModule);            _diExhaustPressureAlarm                = ParseDiNode("diExhaustPressureAlarm", node, ioModule);            _diLogicWaterFlowAlarm                 = ParseDiNode("diLogicWaterFlowAlarm", node, ioModule);            _diLogicN2PressureAlarm                = ParseDiNode("diLogicN2PressureAlarm", node, ioModule);            _doStart                               = ParseDoNode("doStart", node, ioModule);            _doStop                                = ParseDoNode("doStop", node, ioModule);            _doLocalRemote                         = ParseDoNode("doLocalRemote", node, ioModule);            _doWarningReset                        = ParseDoNode("doReset", node, ioModule);            _doN2PressureAlarm                     = ParseDoNode("doN2PressureAlarm", node, ioModule);            _doWaterFlowAlarm                      = ParseDoNode("doWaterFlowAlarm", node, ioModule);            _aoH2OSensorMassWarningThreshold       = ParseAoNode("aoH2OSensorMassWarningThreshold", node, ioModule);            _aoH2OSensorMassWarningTime            = ParseAoNode("aoH2OSensorMassWarningTime", node, ioModule);            _aoN2PurgeFlowWarning                  = ParseAoNode("aoN2PurgeFlowWarning", node, ioModule);            _aoN2PurgeFlowWarningTime              = ParseAoNode("aoN2PurgeFlowWarningTime", node, ioModule);            _aoExhaustPressurePreWarningThreshold  = ParseAoNode("aoExhaustPressurePreWarningThreshold", node, ioModule);            _aoExhaustPressurePreWarningTime       = ParseAoNode("aoExhaustPressurePreWarningTime", node, ioModule);            _aoWaterFlowAlarmMinValue              = ParseAoNode("aoWaterFlowAlarmMinValue", node, ioModule);            _aoWaterFlowAlarmMaxValue              = ParseAoNode("aoWaterFlowAlarmMaxValue", node, ioModule);            _aoN2PressureAlarmMinValue             = ParseAoNode("aoN2PressureAlarmMinValue", node, ioModule);            _aoN2PressureAlarmMaxValue             = ParseAoNode("aoN2PressureAlarmMaxValue", node, ioModule);            _aiWaterFlow                           = ParseAiNode("aiWaterFlow", node, ioModule);            _aiN2Pressure                          = ParseAiNode("aiN2Pressure", node, ioModule);            _aiH2OSensorMassWarningThreshold       = ParseAiNode("aiH2OSensorMassWarningThreshold", node, ioModule);            _aiH2OSensorMassWarningTime            = ParseAiNode("aiH2OSensorMassWarningTime", node, ioModule);            _aiN2PurgeFlow                         = ParseAiNode("aiN2PurgeFlow", node, ioModule);            _aiN2PurgeFlowWarningThreshold         = ParseAiNode("aiN2PurgeFlowWarningThreshold", node, ioModule);            _aiN2PurgeFlowWarningTime              = ParseAiNode("aiN2PurgeFlowWarningTime", node, ioModule);            _aiExhaustPressure                     = ParseAiNode("aiExhaustPressure", node, ioModule);            _aiExhaustPressurePreWarningThreshold  = ParseAiNode("aiExhaustPressurePreWarningThreshold", node, ioModule);            _aiExhaustPressurePreWarningTime       = ParseAiNode("aiExhaustPressurePreWarningTime", node, ioModule);            _scH2OSensorMassWarningThreshold       = ParseScNode("scH2OSensorMassWarningThreshold", node);            _scH2OSensorMassWarningTime            = ParseScNode("scH2OSensorMassWarningTime", node);            _scN2PurgeFlowWarning                  = ParseScNode("scN2PurgeFlowWarning", node);            _scN2PurgeFlowWarningTime              = ParseScNode("scN2PurgeFlowWarningTime", node);            _scExhaustPressurePreWarningThreshold  = ParseScNode("scExhaustPressurePreWarningThreshold", node);            _scExhaustPressurePreWarningTime       = ParseScNode("scExhaustPressurePreWarningTime", node);            _scEnableDryPump                       = ParseScNode("scEnableDryPump", node);            _scEnableWaterFlow                     = ParseScNode("scEnableWaterFlow", node);            _scWaterFlowMinValue                   = ParseScNode("scWaterFlowMinValue", node);            _scWaterFlowMaxValue                   = ParseScNode("scWaterFlowMaxValue", node);            _scWaterFlowOutOfToleranceWarningTime  = ParseScNode("scWaterFlowOutOfToleranceWarningTime", node);            _scWaterFlowOutOfToleranceAlarmTime    = ParseScNode("scWaterFlowOutOfToleranceAlarmTime", node);            _scEnableN2Pressure                    = ParseScNode("scEnableN2Pressure", node);            _scN2PressureMinValue                  = ParseScNode("scN2PressureMinValue", node);            _scN2PressureMaxValue                  = ParseScNode("scN2PressureMaxValue", node);            _scN2PressureOutOfToleranceWarningTime = ParseScNode("scN2PressureOutOfToleranceWarningTime", node);            _scN2PressureOutOfToleranceAlarmTime   = ParseScNode("scN2PressureOutOfToleranceAlarmTime", node);        }        private void SetConfigValue()        {            if (_aoWaterFlowAlarmMinValue != null && _scWaterFlowMinValue != null)                _aoWaterFlowAlarmMinValue.Value = (short)_scWaterFlowMinValue.Value;            if (_aoWaterFlowAlarmMaxValue != null && _scWaterFlowMaxValue != null)                _aoWaterFlowAlarmMaxValue.Value = (short)_scWaterFlowMaxValue.Value;            if (_aoN2PressureAlarmMinValue != null && _scN2PressureMinValue != null)                _aoN2PressureAlarmMinValue.Value = (short)_scN2PressureMinValue.Value;            if (_aoN2PressureAlarmMaxValue != null && _scN2PressureMaxValue != null)                _aoN2PressureAlarmMaxValue.Value = (short)_scN2PressureMaxValue.Value;        }        public override bool Initialize()        {            SetConfigValue();            EV.Subscribe(new EventItem("Event", PumpError, "Pump Error", EventLevel.Alarm, EventType.HostNotification));            DATA.Subscribe($"{Module}.{Name}.DeviceData", () =>            {                AITPumpData data = new AITPumpData()                {                    DeviceName = Name,                    DeviceModule = Module,                    DeviceSchematicId = DeviceID,                    DisplayName = Display,                    IsError = HasError,                    IsWarning = HasWarning,                    IsOn = IsRunning,                    WaterFlow = WaterFlowValue,                    IsDryPumpEnable = IsDryPumpEnabled,                    IsN2PressureEnable = true,                    IsWaterFlowEnable = true,                    WaterFlowWarning = WaterFlowWarning,                    WaterFlowAlarm = WaterFlowAlarm,                    N2PressureAlarm = N2PressureAlarm,                    N2PressureWarning = N2PressureWarning,                };                return data;            }, SubscriptionAttribute.FLAG.IgnoreSaveDB);            OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOn}", (cmd, args) =>            {                if (IsError)                {                    EV.PostWarningLog(Module, "Pump is in error state, reset before turn ON");                    return false;                }                if (IsRunning)                {                    EV.PostWarningLog(Module, "Pump is running");                    return false;                }                Start(true);                return true;            });            OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOff}", (cmd, args) =>            {                if (IsError)                {                    EV.PostWarningLog(Module, "Pump is in error state, reset before turn OFF");                    return false;                }                if (!IsRunning)                {                    EV.PostWarningLog(Module, "Pump is not running");                    return false;                }                Start(false);                return true;            });            DEVICE.Register($"{Module}.{Name}.{AITPumpOperation.SetOnOff}", (out string reason, int time, object[] param) =>            {                bool isOn = Convert.ToBoolean((string)param[0]);                if (IsError)                {                    reason = string.Format("Pump is in error state, reset before turn {0}", isOn ? "ON" : "OFF");                    return false;                }                reason = string.Empty;                this.Start(isOn);                return true;            });            return true;        }        public override void Terminate()        {        }        public void Start(bool on)        {            if (on)            {                if (_doStart != null)                {                    _doStart.Value = true;                    _doStop.Value = false;                }            }            else            {                if (_doStop != null)                {                    _doStart.Value = false;                    _doStop.Value = true;                }            }            _timer.Start(2000);        }        private void ResetSwitch()        {            if (null != _doStart) _doStart.Value = false;            if (null != _doStop) _doStop.Value = false;        }        private void MonitorN2Pressure()        {            if (!IsDryPumpEnabled)                return;            if (!EnableN2Pressure)                return;            //_checkN2PressureWarning.Monitor(N2PressureValue, N2PressureMinValue, N2PressureMaxValue, N2PressureWarningTime);            //if (_checkN2PressureWarning.Trig)            //{            //    EV.PostMessage(Module, EventEnum.DefaultWarning, string.Format("{0} N2 pressure out of tolerance [{1}, {2}] for {3} seconds", Display, N2PressureMinValue, N2PressureMaxValue, N2PressureWarningTime));            //}            //_checkN2PressureAlarm.Monitor(N2PressureValue, N2PressureMinValue, N2PressureMaxValue, N2PressureAlarmTime);            //if (_checkN2PressureAlarm.Trig)            //{            //    EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0} N2 pressure out of tolerance [{1}, {2}] for {3} seconds", Display, N2PressureMinValue, N2PressureMaxValue, N2PressureAlarmTime));            //}            if (_diLogicN2PressureAlarm != null)                _diLogicN2PressureAlarm.RawData = N2PressureAlarm;            N2PressureAlarmSetPoint = N2PressureAlarm;        }        private void MonitorWaterFlow()        {            if (!IsDryPumpEnabled)                return;            if (!EnableWaterFlow)                return;            _checkWaterFlowWarning.Monitor(WaterFlowValue, WaterFlowMinValue, WaterFlowMaxValue, WaterFlowWarningTime);            if (_checkWaterFlowWarning.Trig)            {                EV.PostMessage(Module, EventEnum.DefaultWarning, string.Format("{0} Cooling Water Flow Out Of Tolerance [{1}, {2}] for {3} seconds", Display, WaterFlowMinValue, WaterFlowMaxValue, WaterFlowWarningTime));            }            _checkWaterFlowAlarm.Monitor(WaterFlowValue, WaterFlowMinValue, WaterFlowMaxValue, WaterFlowAlarmTime);            if (_checkWaterFlowAlarm.Trig)            {                EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0} Cooling Water Flow Out Of Tolerance [{1}, {2}] for {3} seconds", Display, WaterFlowMinValue, WaterFlowMaxValue, WaterFlowAlarmTime));            }            if (_diLogicWaterFlowAlarm != null)                _diLogicWaterFlowAlarm.RawData = WaterFlowAlarm;            WaterFlowAlarmSetPoint = WaterFlowAlarm;        }        public override void Monitor()        {            try            {                SetConfigValue();                //if (_timer.IsTimeout())                //{                //    //this.ResetSwitch();                //    _timer.Stop();                //}                //MonitorN2Pressure();                //MonitorWaterFlow();                if (_scH2OSensorMassWarningThreshold != null && _aoH2OSensorMassWarningThreshold != null)                    _aoH2OSensorMassWarningThreshold.Value = (short)_scH2OSensorMassWarningThreshold.Value;                if (_scH2OSensorMassWarningTime != null && _aoH2OSensorMassWarningTime != null)                    _aoH2OSensorMassWarningTime.Value = (short)_scH2OSensorMassWarningTime.Value;                if (_scN2PurgeFlowWarning != null && _aoN2PurgeFlowWarning != null)                    _aoN2PurgeFlowWarning.Value = (short)_scN2PurgeFlowWarning.Value;                if (_scN2PurgeFlowWarningTime != null && _aoN2PurgeFlowWarningTime != null)                    _aoN2PurgeFlowWarningTime.Value = (short)_scN2PurgeFlowWarningTime.Value;                if (_scExhaustPressurePreWarningThreshold != null && _aoExhaustPressurePreWarningThreshold != null)                    _aoExhaustPressurePreWarningThreshold.Value = (short)_scExhaustPressurePreWarningThreshold.Value;                if (_scExhaustPressurePreWarningTime != null && _aoExhaustPressurePreWarningTime != null)                    _aoExhaustPressurePreWarningTime.Value = (short)_scExhaustPressurePreWarningTime.Value;                _trigWarning.CLK = IsWarning;                if (_trigWarning.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultWarning, "Dry Pump Warning");                }                _trigError.CLK = IsError;                if (_trigError.Q)                {                    EV.Notify(PumpError);                    EV.PostMessage(Module, EventEnum.DefaultAlarm, "Dry Pump Error");                }                _trigWaterFlowSensorWarning.CLK = _diWaterFlowWarning != null && _diWaterFlowWarning.Value;                if (_trigWaterFlowSensorWarning.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultWarning, "Dry Pump water flow warning");                }                _trigWaterFlowSensorAlarm.CLK = _diWaterFlowAlarm != null && _diWaterFlowAlarm.Value;                if (_trigWaterFlowSensorAlarm.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultAlarm, "Dry Pump water flow alarm");                }                _trigN2Warning.CLK = _diN2Warning != null && _diN2Warning.Value;                if (_trigN2Warning.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultWarning, "Dry Pump N2 flow warning");                }                _trigN2Alarm.CLK = _diN2Alarm != null && _diN2Alarm.Value;                if (_trigN2Alarm.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultAlarm, "Dry Pump N2 flow alarm");                }                _trigExhaustPressureWarning.CLK = _diExhaustPressureWarning != null && _diExhaustPressureWarning.Value;                if (_trigExhaustPressureWarning.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultWarning, "Dry Pump exhaust pressure warning");                }                _trigExhaustPressureAlarm.CLK = _diExhaustPressureAlarm != null && _diExhaustPressureAlarm.Value;                if (_trigExhaustPressureAlarm.Q)                {                    EV.PostMessage(Module, EventEnum.DefaultAlarm, "Dry Pump exhaust pressure alarm");                }            }            catch (Exception ex)            {                LOG.Write(ex);            }        }        public override void Reset()        {            if ((IsWarning || IsError) && _doWarningReset != null)                _doWarningReset.Value = true;            _trigWarning.RST = true;            _trigError.RST = true;            _trigWaterFlowSensorWarning.RST = true;            _trigWaterFlowSensorAlarm.RST = true;            _trigN2Warning.RST = true;            _trigN2Alarm.RST = true;            _trigExhaustPressureWarning.RST = true;            _trigExhaustPressureAlarm.RST = true;            _checkN2PressureAlarm.RST = true;            _checkN2PressureWarning.RST = true;            _checkWaterFlowAlarm.RST = true;            _checkWaterFlowWarning.RST = true;        }        public override void SetPumpOnOff(bool isOn)        {            Start(isOn);        }    }}
 |