IoBoostPump.cs 7.9 KB

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