IoWaterFlowSensor.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.IOCore;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.RT.Tolerance;
  12. using Aitex.Core.Util;
  13. namespace Aitex.Core.RT.Device.Unit
  14. {
  15. public class IoWaterFlowSensor : BaseDevice, IDevice
  16. {
  17. [Subscription(AITWaterFlowSensorPropertyName.Feedback)]
  18. public double Feedback
  19. {
  20. get
  21. {
  22. if (_aiFlowValue != null)
  23. return _aiFlowValue.Value;
  24. return 0;
  25. }
  26. }
  27. [Subscription(AITWaterFlowSensorPropertyName.IsWarning)]
  28. public bool IsWarning
  29. {
  30. get
  31. {
  32. return _checkWarning.Result;
  33. }
  34. }
  35. [Subscription(AITWaterFlowSensorPropertyName.IsError)]
  36. public bool IsError
  37. {
  38. get
  39. {
  40. return _checkAlarm.Result;
  41. }
  42. }
  43. private double _minSetPoint;
  44. public double MinSetPoint
  45. {
  46. get
  47. {
  48. return _minSetPoint;
  49. }
  50. set
  51. {
  52. _minSetPoint = value;
  53. if (_aoMin != null)
  54. _aoMin.Value = (float)value;
  55. }
  56. }
  57. private double _maxSetPoint;
  58. public double MaxSetPoint
  59. {
  60. get
  61. {
  62. return _maxSetPoint;
  63. }
  64. set
  65. {
  66. _maxSetPoint = value;
  67. if (_aoMax != null)
  68. _aoMax.Value = (float) value;
  69. }
  70. }
  71. public double MinFlow
  72. {
  73. get
  74. {
  75. return _scMinFlow == null ? 0 : _scMinFlow.Value;
  76. }
  77. }
  78. public double MaxFlow
  79. {
  80. get
  81. {
  82. return _scMaxFlow == null ? 0 : _scMaxFlow.Value;
  83. }
  84. }
  85. public double WarningTime
  86. {
  87. get
  88. {
  89. return _scWarningTime == null ? 0 : _scWarningTime.Value;
  90. }
  91. }
  92. public double AlarmTime
  93. {
  94. get
  95. {
  96. return _scAlarmTime == null ? 0 : _scAlarmTime.Value;
  97. }
  98. }
  99. public bool IsOutOfTolerance
  100. {
  101. get
  102. {
  103. if (MinFlow < 0.01 && MaxFlow < 0.01)
  104. return false;
  105. return (Feedback < MinFlow) || (Feedback > MaxFlow);
  106. }
  107. }
  108. public string Unit { get; set; }
  109. private AIAccessor _aiFlowValue = null;
  110. private DIAccessor _diValve;
  111. private DOAccessor _doWarning;
  112. private DOAccessor _doAlarm;
  113. private AOAccessor _aoMin;
  114. private AOAccessor _aoMax;
  115. private SCItem<double> _scMinFlow;
  116. private SCItem<double> _scMaxFlow;
  117. private SCItem<double> _scWarningTime;
  118. private SCItem<double> _scAlarmTime;
  119. private ToleranceChecker _checkWarning = new ToleranceChecker();
  120. private ToleranceChecker _checkAlarm = new ToleranceChecker();
  121. private RD_TRIG _trigValveOpenClose = new RD_TRIG();
  122. public IoWaterFlowSensor(string module, XmlElement node)
  123. {
  124. Module = module;
  125. Name = node.GetAttribute("id");
  126. Display = node.GetAttribute("display");
  127. DeviceID = node.GetAttribute("schematicId");
  128. Unit = node.GetAttribute("unit");
  129. _aiFlowValue = ParseAiNode("aiFlowValue", node);
  130. _diValve = ParseDiNode("diValve", node);
  131. _doWarning = ParseDoNode("doWarning", node);
  132. _doAlarm = ParseDoNode("doAlarm", node);
  133. _aoMax = ParseAoNode("aoMax", node);
  134. _aoMin = ParseAoNode("aoMin", node);
  135. _scMinFlow = ParseScNodeDouble("scMinFlow", node);
  136. _scMaxFlow = ParseScNodeDouble("scMaxFlow", node);
  137. _scWarningTime = ParseScNodeDouble("scWarningTime", node);
  138. _scAlarmTime = ParseScNodeDouble("scAlarmTime", node);
  139. MinSetPoint = MinFlow;
  140. MaxSetPoint = MaxFlow;
  141. }
  142. public bool Initialize()
  143. {
  144. DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
  145. {
  146. AITWaterFlowSensorData data = new AITWaterFlowSensorData()
  147. {
  148. DeviceName = Name,
  149. DeviceSchematicId = DeviceID,
  150. DisplayName = Display,
  151. FeedBack = Feedback,
  152. IsWarning = IsWarning,
  153. Unit = Unit,
  154. IsError = IsError,
  155. IsOutOfTolerance = IsOutOfTolerance,
  156. };
  157. return data;
  158. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  159. return true;
  160. }
  161. public void Terminate()
  162. {
  163. }
  164. public void Monitor()
  165. {
  166. MinSetPoint = MinFlow;
  167. MaxSetPoint = MaxFlow;
  168. _trigValveOpenClose.CLK = (_diValve == null || _diValve.Value);
  169. //关闭阀门
  170. if (_trigValveOpenClose.T)
  171. {
  172. _checkWarning.RST = true;
  173. _checkAlarm.RST = true;
  174. }
  175. //打开过程中,一直监控
  176. if (_trigValveOpenClose.M)
  177. {
  178. if (WarningTime > 0.1)
  179. {
  180. _checkWarning.Monitor(Feedback, MinFlow,MaxFlow, WarningTime);
  181. if (_checkWarning.Trig)
  182. {
  183. EV.PostMessage(Module, EventEnum.WT_Flow_Warning, Display, Feedback.ToString("F1"), WarningTime,
  184. Feedback > MaxFlow ? ">" : "<", Feedback > MaxFlow ? MaxFlow : MinFlow);
  185. }
  186. if (_doWarning!=null)
  187. {
  188. _doWarning.Value = _checkWarning.Result;
  189. }
  190. }
  191. if (AlarmTime > 0.1)
  192. {
  193. _checkAlarm.Monitor(Feedback, MinFlow, MaxFlow, AlarmTime);
  194. if (_checkAlarm.Trig)
  195. {
  196. EV.PostMessage(Module, EventEnum.WT_Flow_Alarm, Display, Feedback.ToString("F1"), AlarmTime,
  197. Feedback > MaxFlow ? ">" : "<", Feedback > MaxFlow ? MaxFlow : MinFlow);
  198. }
  199. if (_doAlarm != null)
  200. {
  201. _doAlarm.Value = _checkAlarm.Result;
  202. }
  203. }
  204. }
  205. }
  206. public void Reset()
  207. {
  208. _checkWarning.RST = true;
  209. _checkAlarm.RST = true;
  210. }
  211. }
  212. }