using System; using System.Collections.Generic; using System.Linq; using System.Text; 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.RT.Tolerance; using Aitex.Core.Util; namespace Aitex.Core.RT.Device.Unit { public class IoWaterFlowSensor : BaseDevice, IDevice { [Subscription(AITWaterFlowSensorPropertyName.Feedback)] public double Feedback { get { if (_aiFlowValue != null) return _aiFlowValue.Value; return 0; } } [Subscription(AITWaterFlowSensorPropertyName.IsWarning)] public bool IsWarning { get { return _checkWarning.Result; } } [Subscription(AITWaterFlowSensorPropertyName.IsError)] public bool IsError { get { return _checkAlarm.Result; } } private double _minSetPoint; public double MinSetPoint { get { return _minSetPoint; } set { _minSetPoint = value; if (_aoMin != null) _aoMin.Value = (float)value; } } private double _maxSetPoint; public double MaxSetPoint { get { return _maxSetPoint; } set { _maxSetPoint = value; if (_aoMax != null) _aoMax.Value = (float) value; } } public double MinFlow { get { return _scMinFlow == null ? 0 : _scMinFlow.Value; } } public double MaxFlow { get { return _scMaxFlow == null ? 0 : _scMaxFlow.Value; } } public double WarningTime { get { return _scWarningTime == null ? 0 : _scWarningTime.Value; } } public double AlarmTime { get { return _scAlarmTime == null ? 0 : _scAlarmTime.Value; } } public bool IsOutOfTolerance { get { if (MinFlow < 0.01 && MaxFlow < 0.01) return false; return (Feedback < MinFlow) || (Feedback > MaxFlow); } } public string Unit { get; set; } private AIAccessor _aiFlowValue = null; private DIAccessor _diValve; private DOAccessor _doWarning; private DOAccessor _doAlarm; private AOAccessor _aoMin; private AOAccessor _aoMax; private SCItem _scMinFlow; private SCItem _scMaxFlow; private SCItem _scWarningTime; private SCItem _scAlarmTime; private ToleranceChecker _checkWarning = new ToleranceChecker(); private ToleranceChecker _checkAlarm = new ToleranceChecker(); private RD_TRIG _trigValveOpenClose = new RD_TRIG(); public IoWaterFlowSensor(string module, XmlElement node) { Module = module; Name = node.GetAttribute("id"); Display = node.GetAttribute("display"); DeviceID = node.GetAttribute("schematicId"); Unit = node.GetAttribute("unit"); _aiFlowValue = ParseAiNode("aiFlowValue", node); _diValve = ParseDiNode("diValve", node); _doWarning = ParseDoNode("doWarning", node); _doAlarm = ParseDoNode("doAlarm", node); _aoMax = ParseAoNode("aoMax", node); _aoMin = ParseAoNode("aoMin", node); _scMinFlow = ParseScNodeDouble("scMinFlow", node); _scMaxFlow = ParseScNodeDouble("scMaxFlow", node); _scWarningTime = ParseScNodeDouble("scWarningTime", node); _scAlarmTime = ParseScNodeDouble("scAlarmTime", node); MinSetPoint = MinFlow; MaxSetPoint = MaxFlow; } public bool Initialize() { DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () => { AITWaterFlowSensorData data = new AITWaterFlowSensorData() { DeviceName = Name, DeviceSchematicId = DeviceID, DisplayName = Display, FeedBack = Feedback, IsWarning = IsWarning, Unit = Unit, IsError = IsError, IsOutOfTolerance = IsOutOfTolerance, }; return data; }, SubscriptionAttribute.FLAG.IgnoreSaveDB); return true; } public void Terminate() { } public void Monitor() { MinSetPoint = MinFlow; MaxSetPoint = MaxFlow; _trigValveOpenClose.CLK = (_diValve == null || _diValve.Value); //关闭阀门 if (_trigValveOpenClose.T) { _checkWarning.RST = true; _checkAlarm.RST = true; } //打开过程中,一直监控 if (_trigValveOpenClose.M) { if (WarningTime > 0.1) { _checkWarning.Monitor(Feedback, MinFlow,MaxFlow, WarningTime); if (_checkWarning.Trig) { EV.PostMessage(Module, EventEnum.WT_Flow_Warning, Display, Feedback.ToString("F1"), WarningTime, Feedback > MaxFlow ? ">" : "<", Feedback > MaxFlow ? MaxFlow : MinFlow); } if (_doWarning!=null) { _doWarning.Value = _checkWarning.Result; } } if (AlarmTime > 0.1) { _checkAlarm.Monitor(Feedback, MinFlow, MaxFlow, AlarmTime); if (_checkAlarm.Trig) { EV.PostMessage(Module, EventEnum.WT_Flow_Alarm, Display, Feedback.ToString("F1"), AlarmTime, Feedback > MaxFlow ? ">" : "<", Feedback > MaxFlow ? MaxFlow : MinFlow); } if (_doAlarm != null) { _doAlarm.Value = _checkAlarm.Result; } } } } public void Reset() { _checkWarning.RST = true; _checkAlarm.RST = true; } } }