123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System.Xml;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoPressureMeter : BaseDevice, IDevice
- {
- [Subscription(AITPressureMeterPropertyName.Feedback)]
- public double Value
- {
- get
- {
- if (_aiPressure != null)
- return _aiPressure.Value;
- return 0;
- }
- }
- public bool IsError
- {
- get
- {
- if (_diGaugeError != null)
- return _diGaugeError.Value;
- return false;
- }
- }
- public double Precision
- {
- get
- {
- return _scPrecision == null ? float.MaxValue : _scPrecision.Value;
- }
- }
- private string _unit = "mTorr";
- public string Unit
- {
- get
- {
- return _unit;
- }
- set
- {
- _unit = value;
- }
- }
- private AIAccessor _aiPressure = null;
- private DIAccessor _diGaugeError;
- private SCItem<double> _scPrecision;
- private R_TRIG _trigGaugeError = new R_TRIG();
- private F_TRIG _trigPressureException = new F_TRIG();
- private DeviceTimer _timerPressureException = new DeviceTimer();
- const float PRESSURE_EXCEPTION_THRESHOLD = 0.4f;
- public IoPressureMeter(string module, XmlElement node)
- {
- base.Module = module;
- base.Name = node.GetAttribute("id");
- base.Display = node.GetAttribute("display");
- base.DeviceID = node.GetAttribute("schematicId");
- Unit = node.GetAttribute("unit");
- _aiPressure = ParseAiNode("aiPressure", node);
- _diGaugeError = ParseDiNode("diGaugeFail", node);
- _scPrecision = ParseScNodeDouble("scPrecision", node);
- }
- public bool Initialize()
- {
- DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
- {
- AITPressureMeterData data = new AITPressureMeterData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- FeedBack = Value,
- Precision = Precision,
- Unit = Unit,
- IsError = IsError,
- };
- return data;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- // Gauge error triggered
- _trigGaugeError.CLK = IsError;
- if (_trigGaugeError.Q)
- {
- EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("Vacuum gauge error."));
- }
- // pressure exception, 可能真空压力计断线
- _trigPressureException.CLK = this.Value > PRESSURE_EXCEPTION_THRESHOLD;
- if (_trigPressureException.Q)
- {
- _timerPressureException.Start(2000);
- }
- if (_timerPressureException.IsTimeout() && this.Value < PRESSURE_EXCEPTION_THRESHOLD)
- {
- EV.PostMessage(Module, EventEnum.DefaultAlarm, $"压力数值[{this.Value}]异常");
- _timerPressureException.Stop();
- }
- }
- public void Reset()
- {
- _trigGaugeError.RST = true;
- _trigPressureException.RST = true;
- }
- }
- }
|