IoBoostPump.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.IOCore;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. namespace VirgoRT.Devices
  12. {
  13. public enum BoostPumpEnable
  14. {
  15. Disable = 0,
  16. Enable = 1,
  17. }
  18. public class IoBoostPump : BaseDevice, IDevice
  19. {
  20. private DIAccessor _diBoosterInvAlarm = null;
  21. private DIAccessor _diBoosterInvRun = null;
  22. private DIAccessor _diBreakerState;
  23. private DIAccessor _diPowerOn;
  24. private AOAccessor _aoBoosterEnable = null;
  25. private AOAccessor _aoBoosterSetPoint = null;
  26. private AIAccessor _aiInverterFrequency = null;
  27. private SCConfigItem _scPressureSetPointMaxValue = null;
  28. private SCConfigItem _scEnableFrequency = null;
  29. public bool IsRunning
  30. {
  31. get
  32. {
  33. if (_diPowerOn != null)
  34. return _diPowerOn.Value;
  35. if (_diBreakerState != null)
  36. return _diBreakerState.Value;
  37. return true;
  38. }
  39. }
  40. public bool IsError
  41. {
  42. get
  43. {
  44. return _diBoosterInvAlarm != null && _diBoosterInvAlarm.Value;
  45. }
  46. }
  47. public double PressureSetPointMax
  48. {
  49. get
  50. {
  51. if (_scPressureSetPointMaxValue == null)
  52. return 760000;
  53. return _scPressureSetPointMaxValue.DoubleValue;
  54. }
  55. }
  56. [Subscription(AITBoostPumpDataPropertyName.EnableSetPoint)]
  57. public double EnableSetPoint
  58. {
  59. get
  60. {
  61. if (_aoBoosterEnable == null)
  62. return 0;
  63. return _aoBoosterEnable.Value;
  64. }
  65. }
  66. [Subscription(AITBoostPumpDataPropertyName.PressureSetPoint)]
  67. public double PressureSetPoint
  68. {
  69. get
  70. {
  71. if (_aoBoosterSetPoint == null)
  72. return 0;
  73. return _aoBoosterSetPoint.Value;
  74. }
  75. }
  76. [Subscription(AITBoostPumpDataPropertyName.InverterFrequency)]
  77. public double InverterFrequency
  78. {
  79. get
  80. {
  81. if (_aiInverterFrequency == null)
  82. return 0;
  83. return _aiInverterFrequency.Value;
  84. }
  85. }
  86. public bool EnableFrequency
  87. {
  88. get
  89. {
  90. return _scEnableFrequency == null || _scEnableFrequency.BoolValue;
  91. }
  92. }
  93. private R_TRIG _trigError = new R_TRIG();
  94. public IoBoostPump(string module, XmlElement node, string ioModule = "")
  95. {
  96. base.Module = module;
  97. base.Name = node.GetAttribute("id");
  98. base.Display = node.GetAttribute("display");
  99. base.DeviceID = node.GetAttribute("schematicId");
  100. _diBoosterInvAlarm = ParseDiNode("diBoosterInvAlarm", node, ioModule);
  101. _diBoosterInvRun = ParseDiNode("diBoosterInvRun", node, ioModule);
  102. _diBreakerState = ParseDiNode("diBreakerState", node, ioModule);
  103. _diPowerOn = ParseDiNode("diBoosterPowerOn", node, ioModule);
  104. _aoBoosterEnable = ParseAoNode("aoBoosterEnable", node, ioModule);
  105. _aoBoosterSetPoint = ParseAoNode("aoBoosterSetPoint", node, ioModule);
  106. _aiInverterFrequency = ParseAiNode("aiFrequency", node, ioModule);
  107. _scPressureSetPointMaxValue = ParseScNode("scPressureSetPointMaxValue", node);
  108. _scEnableFrequency = ParseScNode("scEnableFrequency", node);
  109. }
  110. public bool Initialize()
  111. {
  112. DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
  113. {
  114. AITBoostPumpData data = new AITBoostPumpData()
  115. {
  116. DeviceName = Name,
  117. DeviceSchematicId = DeviceID,
  118. DisplayName = Display,
  119. IsError = IsError,
  120. IsRunning = IsRunning,
  121. EnableSetPoint = EnableSetPoint,
  122. PressureSetPoint = PressureSetPoint,
  123. InverterFrequency = InverterFrequency,
  124. PressureSetPointMax = PressureSetPointMax,
  125. EnableFrequency = EnableFrequency,
  126. };
  127. return data;
  128. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  129. DEVICE.Register($"{Module}.{Name}.{AITBoostPumpOperation.SetEnable}", (out string reason, int time, object[] param) =>
  130. {
  131. if (IsError)
  132. {
  133. reason = string.Format("boost pump is in error state, recover before set enable");
  134. return false;
  135. }
  136. int isEnable = Convert.ToInt16((string)param[0]);
  137. if ((isEnable != (int)BoostPumpEnable.Enable) && (isEnable != (int)BoostPumpEnable.Disable))
  138. {
  139. reason = string.Format("boost pump set value {0} is not valid, should be 0 || 1", isEnable);
  140. return false;
  141. }
  142. reason = string.Empty;
  143. _aoBoosterEnable.Value = (short)isEnable;
  144. return true;
  145. });
  146. DEVICE.Register($"{Module}.{Name}.{AITBoostPumpOperation.SetPressure}", (out string reason, int time, object[] param) =>
  147. {
  148. if (IsError)
  149. {
  150. reason = string.Format("boost pump is in error state, recover before set pressure");
  151. return false;
  152. }
  153. double pressureSetPoint = Convert.ToDouble((string)param[0]);
  154. if (pressureSetPoint > PressureSetPointMax)
  155. {
  156. reason = string.Format("boost pump pressure set to {0} is not valid, should be less than {1}", pressureSetPoint, PressureSetPointMax);
  157. return false;
  158. }
  159. _aoBoosterSetPoint.Value = (short)pressureSetPoint;
  160. reason = string.Empty;
  161. return true;
  162. });
  163. return true;
  164. }
  165. public bool SetEnable(int enable)
  166. {
  167. if (IsError)
  168. {
  169. return false;
  170. }
  171. if ((enable != (int)BoostPumpEnable.Enable) && (enable != (int)BoostPumpEnable.Disable))
  172. {
  173. LOG.Error(string.Format("boost pump set value {0} is not valid, should be 0 || 1", enable));
  174. return false;
  175. }
  176. if (_aoBoosterEnable != null)
  177. {
  178. _aoBoosterEnable.Value = (short)enable;
  179. }
  180. return true;
  181. }
  182. public bool SetPressure(double setpoint, out string reason)
  183. {
  184. if (setpoint > PressureSetPointMax)
  185. {
  186. reason = string.Format("boost pump setpoint {0}, should be less than {1}", setpoint, PressureSetPointMax);
  187. return false;
  188. }
  189. reason = string.Empty;
  190. _aoBoosterSetPoint.Value = (short)setpoint;
  191. return true;
  192. }
  193. public void Terminate()
  194. {
  195. }
  196. public void Monitor()
  197. {
  198. try
  199. {
  200. _trigError.CLK = IsError;
  201. if (_trigError.Q)
  202. {
  203. EV.PostMessage(Module, EventEnum.DefaultAlarm, "Booster Inverter Alarm");
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. LOG.Write(ex);
  209. throw ex;
  210. }
  211. }
  212. public void Reset()
  213. {
  214. _trigError.RST = true;
  215. }
  216. }
  217. }