IoHeater2.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.RT.Tolerance;
  8. using MECF.Framework.Common.Event;
  9. using System;
  10. using System.Xml;
  11. namespace Aitex.Core.RT.Device.Unit
  12. {
  13. /// <summary>
  14. ///
  15. ///
  16. /// 1个DO控制开关, 1个AI显示当前反馈。根据反馈值和设定值的差别,来自动调整开或者关
  17. ///
  18. /// AI 大于 设定值,关闭DO
  19. /// AI 小于 设定值, 打开DO
  20. ///
  21. /// </summary>
  22. public class IoHeater2 : BaseDevice, IDevice
  23. {
  24. public bool HeaterOnSetPoint
  25. {
  26. get
  27. {
  28. if (_doOn != null)
  29. return _doOn.Value;
  30. return false;
  31. }
  32. set
  33. {
  34. if (_doOn != null)
  35. _doOn.Value = value;
  36. }
  37. }
  38. public float Feedback
  39. {
  40. get
  41. {
  42. return _aiFeedback.FloatValue;
  43. }
  44. }
  45. public string Unit
  46. {
  47. get; set;
  48. }
  49. private AITHeaterData DeviceData
  50. {
  51. get
  52. {
  53. AITHeaterData data = new AITHeaterData()
  54. {
  55. Module = Module,
  56. DeviceName = Name,
  57. DeviceSchematicId = DeviceID,
  58. DisplayName = Display,
  59. FeedBack = Feedback,
  60. IsPowerOn = HeaterOnSetPoint,
  61. IsPowerOnSetPoint = HeaterOnSetPoint,
  62. Unit = Unit,
  63. DisplayWithUnit = true,
  64. FormatString = "F2",
  65. };
  66. return data;
  67. }
  68. }
  69. private DOAccessor _doOn = null;
  70. private AIAccessor _aiFeedback = null;
  71. private bool _isFloatAioType = false;
  72. private SCConfigItem _scAutoAdjustMinValue;
  73. private SCConfigItem _scAutoAdjustMaxValue;
  74. private SCConfigItem _scEnableAutoAdjust;
  75. private SCConfigItem _scEnableAlarm;
  76. private SCConfigItem _scAlarmTime;
  77. private SCConfigItem _scAlarmMaxValue;
  78. private SCConfigItem _scAlarmMinValue;
  79. private bool _enableHeatUp;
  80. public AlarmEventItem AlarmOutOfRange { get; set; }
  81. private ToleranceChecker _outOfRangeChecker = new ToleranceChecker();
  82. public IoHeater2(string module, XmlElement node, string ioModule = "")
  83. {
  84. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  85. base.Name = node.GetAttribute("id");
  86. base.Display = node.GetAttribute("display");
  87. base.DeviceID = node.GetAttribute("schematicId");
  88. Unit = node.GetAttribute("unit");
  89. string scBasePath = node.GetAttribute("scBasePath");
  90. if (string.IsNullOrEmpty(scBasePath))
  91. scBasePath = $"{Module}.{Name}";
  92. else
  93. {
  94. scBasePath = scBasePath.Replace("{module}", Module);
  95. }
  96. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  97. _aiFeedback = ParseAiNode("aiFeedback", node, ioModule);
  98. _doOn = ParseDoNode("doOn", node, ioModule);
  99. _scAutoAdjustMinValue = SC.GetConfigItem($"{scBasePath}.{Name}.AutoAdjustMinValue");
  100. _scAutoAdjustMaxValue = SC.GetConfigItem($"{scBasePath}.{Name}.AutoAdjustMaxValue");
  101. _scEnableAutoAdjust = SC.GetConfigItem($"{scBasePath}.{Name}.EnableAutoAdjust");
  102. _scEnableAlarm = SC.GetConfigItem($"{scBasePath}.{Name}.EnableAlarm");
  103. _scAlarmTime = SC.GetConfigItem($"{scBasePath}.{Name}.AlarmTime");
  104. _scAlarmMaxValue = SC.GetConfigItem($"{scBasePath}.{Name}.AlarmMaxValue");
  105. _scAlarmMinValue = SC.GetConfigItem($"{scBasePath}.{Name}.AlarmMinValue");
  106. _enableHeatUp = true;
  107. }
  108. public bool Initialize()
  109. {
  110. AlarmOutOfRange = SubscribeAlarm($"{Module}.{Name}.OutOfRangeAlarm", $"{Name} temperature out of range", ResetOutOfRangeChecker);
  111. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  112. DATA.Subscribe($"{Module}.{Name}.Feedback", () => Feedback);
  113. OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.Ramp}", (out string reason, int time, object[] param) =>
  114. {
  115. reason = "do not support set temperature";
  116. EV.PostWarningLog(Module, reason);
  117. return true;
  118. });
  119. OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.SetPowerOnOff}", (out string reason, int time, object[] param) =>
  120. {
  121. bool isOn = Convert.ToBoolean((string)param[0]);
  122. if (_doOn != null)
  123. {
  124. if (!_doOn.SetValue(isOn, out reason))
  125. return false;
  126. }
  127. reason = $"set {Module}.{Name} heater on";
  128. return true;
  129. });
  130. return true;
  131. }
  132. public void EnableControl(bool enable)
  133. {
  134. if (_enableHeatUp == enable)
  135. return;
  136. _enableHeatUp = enable;
  137. if (!_enableHeatUp)
  138. {
  139. EV.PostInfoLog(Module, "Disable control heater temperature");
  140. }
  141. }
  142. public void Stop()
  143. {
  144. }
  145. public void Terminate()
  146. {
  147. }
  148. public void Monitor()
  149. {
  150. MonitorAutoHeaterUp();
  151. MonitorOutOfRange();
  152. }
  153. private void MonitorAutoHeaterUp()
  154. {
  155. if (!_enableHeatUp)
  156. {
  157. HeaterOnSetPoint = false;
  158. return;
  159. }
  160. if (_scEnableAlarm.BoolValue && Feedback > _scAlarmMaxValue.DoubleValue)
  161. {
  162. HeaterOnSetPoint = false;
  163. return;
  164. }
  165. if (_scEnableAutoAdjust.BoolValue)
  166. {
  167. if (Feedback > _scAutoAdjustMaxValue.DoubleValue)
  168. {
  169. HeaterOnSetPoint = false;
  170. }
  171. if (Feedback < _scAutoAdjustMinValue.DoubleValue)
  172. {
  173. HeaterOnSetPoint = true;
  174. }
  175. }
  176. }
  177. private void MonitorOutOfRange()
  178. {
  179. if (!_scEnableAlarm.BoolValue)
  180. {
  181. _outOfRangeChecker.RST = true;
  182. AlarmOutOfRange.Reset();
  183. return;
  184. }
  185. _outOfRangeChecker.Monitor(Feedback, _scAlarmMinValue.DoubleValue, _scAlarmMaxValue.DoubleValue, _scAlarmTime.IntValue);
  186. if (_outOfRangeChecker.Trig)
  187. {
  188. AlarmOutOfRange.Description = $"{Display} out of range [{_scAlarmMinValue.DoubleValue:F1},{_scAlarmMaxValue.DoubleValue:F1}] {Unit} for {_scAlarmTime.IntValue:F0} seconds";
  189. AlarmOutOfRange.Set();
  190. }
  191. }
  192. public void Reset()
  193. {
  194. AlarmOutOfRange.Reset();
  195. }
  196. public bool ResetOutOfRangeChecker()
  197. {
  198. _outOfRangeChecker.Reset(_scAlarmTime.IntValue);
  199. return true;
  200. }
  201. }
  202. }