123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- 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;
- using MECF.Framework.Common.Event;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoPressureMeter3 : BaseDevice, IDevice, IPressureMeter
- {
- public double Value
- {
- get
- {
- return FeedBack;
- }
- }
- public double FeedBack
- {
- get
- {
- double value = _isFloatAioType ? _aiValue.FloatValue : _aiValue.Value;
- if (_tuningPercent > 0 && _tuningPercent < 100)
- {
- value = value * (1 - _tuningPercent/100.0);
- }
- return value;
- }
- }
- public double Precision
- {
- get
- {
- return _scPrecision == null ? 1000 : _scPrecision.DoubleValue;
- }
- }
- private AITPressureMeterData DeviceData
- {
- get
- {
- AITPressureMeterData data = new AITPressureMeterData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- FeedBack = Value,
- Unit = Unit,
- FormatString = _formatString,
- DisplayWithUnit = true,
- IsError = IsError,
- IsWarning = IsWarning,
- Precision = Precision,
- };
- return data;
- }
- }
- public bool IsWarning
- {
- get
- {
- return _checkWarning.Result;
- }
- }
- public bool IsError
- {
- get
- {
- return _checkAlarm.Result;
- }
- }
- public double MinPressure
- {
- get
- {
- return _scMinValue == null ? 0 : _scMinValue.DoubleValue;
- }
- }
- public double MaxPressure
- {
- get
- {
- return _scMaxValue == null ? 0 : _scMaxValue.DoubleValue;
- }
- }
- public int WarningTime
- {
- get
- {
- return _scWarningTime == null ? 0 : _scWarningTime.IntValue;
- }
- }
- public int AlarmTime
- {
- get
- {
- return _scAlarmTime == null ? 0 : _scAlarmTime.IntValue;
- }
- }
- public bool EnableAlarm
- {
- get
- {
- return _scEnableAlarm == null ? true : _scEnableAlarm.BoolValue;
- }
- }
- public bool IsOutOfRange
- {
- get
- {
- if (MinPressure < 0.01 && MaxPressure < 0.01)
- return false;
- return (Value < MinPressure) || (Value > MaxPressure);
- }
- }
- public string Unit { get; set; }
- private AIAccessor _aiValue = null;
- private string _formatString = "F5";
- private SCConfigItem _scMinValue;
- private SCConfigItem _scMaxValue;
- private SCConfigItem _scEnableAlarm;
- private SCConfigItem _scWarningTime;
- private SCConfigItem _scAlarmTime;
- private SCConfigItem _scPrecision;
- private ToleranceChecker _checkWarning = new ToleranceChecker();
- private ToleranceChecker _checkAlarm = new ToleranceChecker();
- public AlarmEventItem AlarmToleranceWarning { get; set; }
- public AlarmEventItem AlarmToleranceAlarm { get; set; }
- private bool _isFloatAioType = false;
- private float _tuningPercent;
- public IoPressureMeter3(string module, XmlElement node, string ioModule = "")
- {
- var attrModule = node.GetAttribute("module");
- base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
- Name = node.GetAttribute("id");
- Display = node.GetAttribute("display");
- DeviceID = node.GetAttribute("schematicId");
- Unit = node.GetAttribute("unit");
- _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
- _aiValue = ParseAiNode("aiValue", node, ioModule);
- if (node.HasAttribute("formatString"))
- _formatString = string.IsNullOrEmpty(node.GetAttribute("formatString")) ? "F5" : node.GetAttribute("formatString");
- string scBasePath = node.GetAttribute("scBasePath");
- if (string.IsNullOrEmpty(scBasePath))
- scBasePath = $"{Module}.{Name}";
- else
- {
- scBasePath = scBasePath.Replace("{module}", Module);
- }
- _scMinValue = ParseScNode("", node, "", $"{scBasePath}.{Name}.MinValue");
- _scMaxValue = ParseScNode("", node, "", $"{scBasePath}.{Name}.MaxValue");
- _scEnableAlarm = ParseScNode("", node, "", $"{scBasePath}.{Name}.EnableAlarm");
- _scWarningTime = ParseScNode("", node, "", $"{scBasePath}.{Name}.WarningTime");
- _scAlarmTime = ParseScNode("", node, "", $"{scBasePath}.{Name}.AlarmTime");
- _scPrecision = ParseScNode("", node, "", $"{scBasePath}.{Name}.Precision");
-
- }
- public bool Initialize()
- {
- DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
- DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
- //AlarmToleranceWarning = SubscribeAlarm($"{Module}.{Name}.OutOfToleranceWarning", "", ResetWarningChecker, EventLevel.Warning);
- //AlarmToleranceError = SubscribeAlarm($"{Module}.{Name}.OutOfToleranceError", "", ResetErrorChecker);
- AlarmToleranceWarning = SubscribeAlarm(new AlarmEventItem()
- {
- EventEnum = $"{Module}.{Name}ToleranceWarning",
- Description = $"{Name} tolerance warning ",
- Solution = "No information available. Press[Clear] to delete alarm message.",
- Explaination = "No information available.",
- AutoRecovery = false,
- Level = EventLevel.Warning,
- Action = EventAction.Clear,
- Category = "TubeAlarm",
- }, () => { Reset(); return true; });
- AlarmToleranceAlarm = SubscribeAlarm(new AlarmEventItem()
- {
- EventEnum = $"{Module}.{Name}ToleranceAlarm",
- Description = $"{Name} tolerance alarm ",
- Solution = "No information available. Press[Clear] to delete alarm message.",
- Explaination = "No information available.",
- AutoRecovery = false,
- Level = EventLevel.Alarm,
- Action = EventAction.Clear,
- Category = "TubeAlarm",
- }, () => { Reset(); return true; });
- return true;
- }
- public void Terminate()
- {
- }
- public void SetTuning(float percent)
- {
- if (percent>0 && percent<=100)
- _tuningPercent = percent;
- }
- public void UnsetTuning()
- {
- _tuningPercent = 0;
- }
- public void Monitor()
- {
- if (EnableAlarm && (WarningTime > 0))
- {
- _checkWarning.Monitor(Value, MinPressure, MaxPressure, WarningTime);
- if (_checkWarning.Trig)
- {
- AlarmToleranceWarning.Description =
- $"{Display} out of range [{MinPressure},{MaxPressure}]{Unit} for {WarningTime} seconds";
- AlarmToleranceWarning.Set();
- }
- if (!_checkWarning.Result)
- {
- AlarmToleranceWarning.Reset();
- }
- }
- else
- {
- AlarmToleranceWarning.Reset();
- }
- if (EnableAlarm && (AlarmTime > 0))
- {
- _checkAlarm.Monitor(Value, MinPressure, MaxPressure, AlarmTime);
- if (_checkAlarm.Trig)
- {
- AlarmToleranceAlarm.Description =
- $"{Display} out of range [{MinPressure},{MaxPressure}]{Unit} for {AlarmTime} seconds";
- AlarmToleranceAlarm.Set();
- }
- if (!_checkAlarm.Result)
- {
- AlarmToleranceAlarm.Reset();
- }
- }
- else
- {
- AlarmToleranceAlarm.Reset();
- }
- }
- public bool ResetWarningChecker()
- {
- _checkWarning.RST = true;
- return true;
- }
- public bool ResetErrorChecker()
- {
- _checkAlarm.RST = true;
- return true;
- }
- public void Reset()
- {
- _checkWarning.RST = true;
- _checkAlarm.RST = true;
- AlarmToleranceWarning.Reset();
- AlarmToleranceAlarm.Reset();
- }
- }
- }
|