| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 | using System;using System.Xml;using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.Device;using Aitex.Core.RT.Event;using Aitex.Core.RT.IOCore;using Aitex.Core.RT.OperationCenter;using Aitex.Core.RT.SCCore;using Aitex.Core.RT.Tolerance;using Aitex.Core.Util;using VirgoRT.Devices.IODevices;namespace VirgoRT.Devices{    public class IoPressureControl : BaseDevice, IDevice    {        private bool _enableTolerance;        public bool EnableTolerance        {            get            {                return _enableTolerance;            }            set            {                if (_enableTolerance != value)                {                    EV.PostInfoLog(Module, value ? "Start monitor pressure stability" : "Stop monitor pressure stability");                    if (value)                    {                        _tolerance.Reset(_scAlarmTime.DoubleValue);                    }                }                _enableTolerance = value;            }        }        public bool IsIndependentControl        {            get            {                if (_scIsIndependentControl != null)                    return _scIsIndependentControl.BoolValue;                return false;            }        }        public bool IsTvInstalled        {            get            {                if (_scTvInstalled != null)                    return _scTvInstalled.BoolValue;                return false;            }        }        public bool IsBoostPumpInstalled        {            get            {                if (_scIsBoostPumpInstalled != null)                    return _scIsBoostPumpInstalled.BoolValue;                return false;            }        }        public bool EnableBoostControl        {            get            {                return _diLogicProcessGasFlowing == null || _diLogicProcessGasFlowing.Value;            }        }        public readonly IoThrottleValve ThrottleValve;        public readonly IoPressureMeter PressureGauge;        public readonly IoPressureMeter ProcessGauge;        public readonly IoPressureMeter ForelineGauge;        //public readonly IoBoostPump _boost;        //public readonly IoPump DryPump;        private readonly ToleranceChecker _tolerance = new ToleranceChecker();        private readonly SCConfigItem _scAlarmRange;        private readonly SCConfigItem _scAlarmTime;        private readonly SCConfigItem _scIsIndependentControl;        private readonly SCConfigItem _scIsBoostPumpInstalled;        private readonly SCConfigItem _scTvInstalled;        private readonly DIAccessor _diLogicProcessGasFlowing;        private readonly R_TRIG _trigPressureGauge = new R_TRIG();        private readonly R_TRIG _trigProcessGauge = new R_TRIG();        private readonly R_TRIG _trigForelineGauge = new R_TRIG();        // Properties        //        public double TargetPressure { get; set; }                private string PressureOutOfTolerance = "PressureOutOfTolerance";        // Constructor        //        public IoPressureControl(string module, XmlElement node, string ioModule = "")        {            base.Module = module;            base.Name = node.GetAttribute("id");            base.Display = node.GetAttribute("display");            base.DeviceID = node.GetAttribute("schematicId");            _diLogicProcessGasFlowing   = ParseDiNode("diLogicProcessGasFlowing", node, ioModule);            _scAlarmRange               = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmRange");            _scAlarmTime                = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmTime");            _scIsIndependentControl     = SC.GetConfigItem($"{Module}.IsIndependentControl");            _scIsBoostPumpInstalled     = SC.GetConfigItem($"{Module}.EnableBoosterPump");            _scTvInstalled              = SC.GetConfigItem($"{Module}.EnableThrottleValve");            //_enableTolerance = true;            ThrottleValve               = ParseDeviceNode<IoThrottleValve>(Module, "tv", node);            PressureGauge               = ParseDeviceNode<IoPressureMeter>(Module, "pressureMeter", node);            ProcessGauge                = ParseDeviceNode<IoPressureMeter>(Module, "processMeter", node);            ForelineGauge               = ParseDeviceNode<IoPressureMeter>(Module, "forelineMeter", node);            //DryPump                     = ParseDeviceNode<IoPump>(Module, "drypump", node);        }        public bool Initialize()        {            DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", _setTVPressure);            DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", _setTVPosition);            DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", _setTVMode);            //DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetBoostPressure}", _setBoostPressure);            DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", _setChamberPressure);            OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", (out string reason, int time, object[] param) =>            {                _setChamberPressure(out reason, 0, param);                return true;            });            OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", (out string reason, int time, object[] param) =>            {                _setTVMode(out reason, 0, param);                return true;            });            OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", (out string reason, int time, object[] param) =>            {                _setTVPressure(out reason, 0, param);                return true;            });            OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", (out string reason, int time, object[] param) =>            {                _setTVPosition(out reason, 0, param);                return true;            });            EV.Subscribe(new EventItem("Event", PressureOutOfTolerance, "Pressure Out Of Tolerance", EventLevel.Alarm, EventType.HostNotification));            return true;        }        //public void StartPump(bool on)        //{        //    this.DryPump?.Start(on);        //}        public void FullOpenThrottleValve()        {            this.ThrottleValve.PressureMode = PressureCtrlMode.TVPositionCtrl;            this.ThrottleValve.PositionSetpoint = 100;        }        private bool? _setTVPressure(out string reason, int time, object[] param)        {            double target = Convert.ToDouble((string)param[0]);            if (!IsTvInstalled)            {                reason = "Throttle valve not config";                return true;            }            if (ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)            {                reason = "Throttle valve is in position control mode, can not set pressure";                return false;            }            ThrottleValve.PressureSetpoint = (short)target;            ThrottleValve.PositionSetpoint = 0.0f;            reason = $"TV pressure set to {target} mTorr";            return true;        }        private bool? _setTVPosition(out string reason, int time, object[] param)        {            double target = Convert.ToDouble((string)param[0]);            if (!IsTvInstalled)            {                reason = "Throttle valve not config";                return true;            }            if (ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)            {                reason = "Throttle valve is in pressure control mode, can not set position";                return false;            }            ThrottleValve.PressureSetpoint = 0.0f;            ThrottleValve.PositionSetpoint = (short)target;            reason = $"TV position set to {target}";            return true;        }        private bool? _setTVMode(out string reason, int time, object[] param)        {            reason = string.Empty;            if (!IsTvInstalled)            {                reason = "Throttle valve not config";                return true;            }            ThrottleValve.PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);            reason = $"TV mode set to {ThrottleValve.PressureMode}";            return true;        }        private bool? _setChamberPressure(out string reason, int time, object[] param)        {            double setpoint = Convert.ToDouble((string)param[0]);            TargetPressure = setpoint;            reason = $"Chamber pressure set to {setpoint} mTorr";            return true;        }        public void Terminate()        {        }        public void Monitor()        {            CheckTolerance();            _trigProcessGauge.CLK = ProcessGauge.GaugeAlarm;            if (_trigProcessGauge.Q) EV.PostAlarmLog(Module, "Process pressure gauge Alarm");            _trigPressureGauge.CLK = PressureGauge.GaugeAlarm;            if (_trigPressureGauge.Q) EV.PostAlarmLog(Module, "Chamber pressure gauge Alarm");            _trigForelineGauge.CLK = ForelineGauge.GaugeAlarm;            if (_trigForelineGauge.Q) EV.PostAlarmLog(Module, "Foreline pressure gauge Alarm");        }        public void CheckTolerance()        {            if (!EnableTolerance)                return;            if (ThrottleValve != null && IsTvInstalled && ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)                return;            _tolerance.Monitor(PressureGauge.Value,                TargetPressure - Math.Abs(_scAlarmRange.DoubleValue),                TargetPressure + Math.Abs(_scAlarmRange.DoubleValue), _scAlarmTime.DoubleValue);            if (_tolerance.Trig)            {                EV.Notify(PressureOutOfTolerance);                EV.PostAlarmLog(Module, $"Gas Flow Pressure Alarm Out of range in {_scAlarmTime.Value:0} seconds");            }        }        public void Reset()        {            _trigProcessGauge.RST = true;            _trigPressureGauge.RST = true;            _trigForelineGauge.RST = true;            if (_scAlarmTime != null)            {                _tolerance.Reset(_scAlarmTime.DoubleValue);            }        }    }}
 |