123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- 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<double> _scMinFlow;
- private SCItem<double> _scMaxFlow;
- private SCItem<double> _scWarningTime;
- private SCItem<double> _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;
- }
- }
- }
|