IoThermalCouple.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using Aitex.Core.Common.DeviceData;
  8. using Aitex.Core.RT.DataCenter;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.IOCore;
  11. using Aitex.Core.RT.SCCore;
  12. using Aitex.Core.RT.Tolerance;
  13. using Aitex.Core.Util;
  14. namespace Aitex.Core.RT.Device.Unit
  15. {
  16. public class IoThermalCouple : BaseDevice, IDevice
  17. {
  18. public string Unit { get; set; }
  19. [Subscription(AITThermalCoupleProperty.Feedback)]
  20. public double Feedback
  21. {
  22. get
  23. {
  24. return _aiFeedback==null? 0: _aiFeedback.Value;
  25. }
  26. }
  27. [Subscription(AITThermalCoupleProperty.IsTcBroken)]
  28. public bool IsTcBroken
  29. {
  30. get
  31. {
  32. return _diTcBroken != null && _diTcBroken.Value;
  33. }
  34. }
  35. public double MinValue
  36. {
  37. get
  38. {
  39. return _scMinValue == null ? 0 : _scMinValue.Value;
  40. }
  41. }
  42. public double MaxValue
  43. {
  44. get
  45. {
  46. return _scMaxValue == null ? 0 : _scMaxValue.Value;
  47. }
  48. }
  49. public double WarningTime
  50. {
  51. get
  52. {
  53. return _scWarningTime == null ? 0 : _scWarningTime.Value;
  54. }
  55. }
  56. public double AlarmTime
  57. {
  58. get
  59. {
  60. return _scAlarmTime == null ? 0 : _scAlarmTime.Value;
  61. }
  62. }
  63. public bool IsOutOfTolerance
  64. {
  65. get
  66. {
  67. if (MinValue < 0.01 && MaxValue < 0.01)
  68. return false;
  69. return (Feedback < MinValue) || (Feedback > MaxValue);
  70. }
  71. }
  72. public bool IsWarning
  73. {
  74. get
  75. {
  76. return _checkWarning.Result;
  77. }
  78. }
  79. public bool IsAlarm
  80. {
  81. get
  82. {
  83. return _checkAlarm.Result;
  84. }
  85. }
  86. private AIAccessor _aiFeedback = null;
  87. private DIAccessor _diTcBroken = null;
  88. private SCItem<double> _scMinValue = null;
  89. private SCItem<double> _scMaxValue = null;
  90. private SCItem<double> _scWarningTime = null;
  91. private SCItem<double> _scAlarmTime = null;
  92. private R_TRIG _trigTcBroken = new R_TRIG();
  93. ToleranceChecker _checkWarning = new ToleranceChecker();
  94. ToleranceChecker _checkAlarm = new ToleranceChecker();
  95. public IoThermalCouple(string module, XmlElement node)
  96. {
  97. base.Module = module;
  98. base.Name = node.GetAttribute("id");
  99. base.Display = node.GetAttribute("display");
  100. base.DeviceID = node.GetAttribute("schematicId");
  101. Unit = node.GetAttribute("unit");
  102. _aiFeedback = ParseAiNode("aiValue", node);
  103. _diTcBroken = ParseDiNode("diTcBroken", node);
  104. _scMinValue = ParseScNodeDouble("scMinValue", node);
  105. _scMaxValue = ParseScNodeDouble("scMaxValue", node);
  106. _scWarningTime = ParseScNodeDouble("scWarningTime", node);
  107. _scAlarmTime = ParseScNodeDouble("scAlarmTime", node);
  108. }
  109. public bool Initialize()
  110. {
  111. DATA.Subscribe(string.Format("Device.{0}.{1}", Module , Name), () =>
  112. {
  113. AITThermalCoupleData data = new AITThermalCoupleData()
  114. {
  115. DeviceName = Name,
  116. DeviceSchematicId = DeviceID,
  117. DisplayName = Display,
  118. FeedBack = Feedback,
  119. IsBroken = IsTcBroken,
  120. IsOutOfTolerance = IsOutOfTolerance,
  121. IsWarning = IsWarning,
  122. IsAlarm = IsAlarm,
  123. };
  124. return data;
  125. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  126. return true;
  127. }
  128. public void Terminate()
  129. {
  130. }
  131. public void Monitor()
  132. {
  133. _trigTcBroken.CLK = IsTcBroken;
  134. if (_trigTcBroken.Q)
  135. {
  136. EV.PostMessage(Module, EventEnum.TCBroken, Display);
  137. }
  138. if (WarningTime > 0.01)
  139. {
  140. _checkWarning.Monitor(Feedback, MinValue,MaxValue, WarningTime);
  141. if (_checkWarning.Trig)
  142. {
  143. EV.PostMessage(Module, EventEnum.TC_Temp_Warning, Display, Feedback.ToString("F1"), WarningTime,
  144. Feedback > MaxValue ? ">" : "<", Feedback > MaxValue ? MaxValue : MinValue);
  145. }
  146. }
  147. if (AlarmTime > 0.01)
  148. {
  149. _checkAlarm.Monitor(Feedback, MinValue, MaxValue, AlarmTime);
  150. if (_checkAlarm.Trig)
  151. {
  152. EV.PostMessage(Module, EventEnum.TC_Temp_Alarm, Display, Feedback.ToString("F1"), AlarmTime,
  153. Feedback > MaxValue ? ">" : "<", Feedback > MaxValue ? MaxValue : MinValue);
  154. }
  155. }
  156. }
  157. public void Reset()
  158. {
  159. _trigTcBroken.RST = true;
  160. _checkWarning.RST = true;
  161. _checkAlarm.RST = true;
  162. }
  163. }
  164. }