123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- 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 IoThermalCouple : BaseDevice, IDevice
- {
- public string Unit { get; set; }
- [Subscription(AITThermalCoupleProperty.Feedback)]
- public double Feedback
- {
- get
- {
- return _aiFeedback==null? 0: _aiFeedback.Value;
- }
- }
-
- [Subscription(AITThermalCoupleProperty.IsTcBroken)]
- public bool IsTcBroken
- {
- get
- {
- return _diTcBroken != null && _diTcBroken.Value;
- }
- }
- public double MinValue
- {
- get
- {
- return _scMinValue == null ? 0 : _scMinValue.Value;
- }
- }
- public double MaxValue
- {
- get
- {
- return _scMaxValue == null ? 0 : _scMaxValue.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 (MinValue < 0.01 && MaxValue < 0.01)
- return false;
- return (Feedback < MinValue) || (Feedback > MaxValue);
- }
- }
- public bool IsWarning
- {
- get
- {
- return _checkWarning.Result;
- }
- }
- public bool IsAlarm
- {
- get
- {
- return _checkAlarm.Result;
- }
- }
-
- private AIAccessor _aiFeedback = null;
- private DIAccessor _diTcBroken = null;
-
- private SCItem<double> _scMinValue = null;
- private SCItem<double> _scMaxValue = null;
- private SCItem<double> _scWarningTime = null;
- private SCItem<double> _scAlarmTime = null;
-
- private R_TRIG _trigTcBroken = new R_TRIG();
-
- ToleranceChecker _checkWarning = new ToleranceChecker();
- ToleranceChecker _checkAlarm = new ToleranceChecker();
- public IoThermalCouple(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");
- _aiFeedback = ParseAiNode("aiValue", node);
- _diTcBroken = ParseDiNode("diTcBroken", node);
- _scMinValue = ParseScNodeDouble("scMinValue", node);
- _scMaxValue = ParseScNodeDouble("scMaxValue", node);
- _scWarningTime = ParseScNodeDouble("scWarningTime", node);
- _scAlarmTime = ParseScNodeDouble("scAlarmTime", node);
- }
-
- public bool Initialize()
- {
- DATA.Subscribe(string.Format("Device.{0}.{1}", Module , Name), () =>
- {
- AITThermalCoupleData data = new AITThermalCoupleData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- FeedBack = Feedback,
- IsBroken = IsTcBroken,
- IsOutOfTolerance = IsOutOfTolerance,
- IsWarning = IsWarning,
- IsAlarm = IsAlarm,
- };
- return data;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- _trigTcBroken.CLK = IsTcBroken;
- if (_trigTcBroken.Q)
- {
- EV.PostMessage(Module, EventEnum.TCBroken, Display);
- }
- if (WarningTime > 0.01)
- {
- _checkWarning.Monitor(Feedback, MinValue,MaxValue, WarningTime);
- if (_checkWarning.Trig)
- {
- EV.PostMessage(Module, EventEnum.TC_Temp_Warning, Display, Feedback.ToString("F1"), WarningTime,
- Feedback > MaxValue ? ">" : "<", Feedback > MaxValue ? MaxValue : MinValue);
- }
- }
- if (AlarmTime > 0.01)
- {
- _checkAlarm.Monitor(Feedback, MinValue, MaxValue, AlarmTime);
-
- if (_checkAlarm.Trig)
- {
- EV.PostMessage(Module, EventEnum.TC_Temp_Alarm, Display, Feedback.ToString("F1"), AlarmTime,
- Feedback > MaxValue ? ">" : "<", Feedback > MaxValue ? MaxValue : MinValue);
- }
- }
- }
-
-
- public void Reset()
- {
- _trigTcBroken.RST = true;
- _checkWarning.RST = true;
- _checkAlarm.RST = true;
- }
- }
- }
|