IoPump.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.OperationCenter;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Pumps;
  12. namespace Aitex.Core.RT.Device.Unit
  13. {
  14. public class IoPump : BaseDevice, IDevice, IPump
  15. {
  16. public bool IsRunning
  17. {
  18. get
  19. {
  20. if (_diRunning != null)
  21. return _diRunning.Value;
  22. if (_diPowerOn != null)
  23. return _diPowerOn.Value;
  24. return true; //默认常开
  25. }
  26. }
  27. public bool IsWarning
  28. {
  29. get
  30. {
  31. return _diWarning != null && _diWarning.Value;
  32. }
  33. }
  34. public bool IsError
  35. {
  36. get
  37. {
  38. return _diError != null && _diError.Value;
  39. }
  40. }
  41. public bool IsPumpOverloadAlarm
  42. {
  43. get
  44. {
  45. return _diOverloadAlarm != null && _diOverloadAlarm.Value;
  46. }
  47. }
  48. public bool HasError
  49. {
  50. get
  51. {
  52. return IsPumpOverloadAlarm || IsError;
  53. }
  54. }
  55. public bool IsN2OK
  56. {
  57. get
  58. {
  59. if (_diN2OK == null)
  60. return true;
  61. return _diN2OK.Value;
  62. }
  63. }
  64. public bool IsExhaustPressureOK
  65. {
  66. get
  67. {
  68. if (_diExhaustPressureOK == null)
  69. return true;
  70. return _diExhaustPressureOK.Value;
  71. }
  72. }
  73. private AITPumpData DeviceData
  74. {
  75. get
  76. {
  77. AITPumpData data = new AITPumpData()
  78. {
  79. DeviceName = Name,
  80. DeviceSchematicId = DeviceID,
  81. DisplayName = Display,
  82. DeviceModule = Module,
  83. Module = Module,
  84. IsOn = IsRunning,
  85. IsError = IsError,
  86. IsOverLoad = IsPumpOverloadAlarm,
  87. };
  88. return data;
  89. }
  90. }
  91. private DIAccessor _diRunning = null;
  92. private DIAccessor _diOverloadAlarm;
  93. private DIAccessor _diPowerOn;
  94. private DIAccessor _diStart;
  95. private DIAccessor _diStop;
  96. private DIAccessor _diN2OK;
  97. private DIAccessor _diExhaustPressureOK;
  98. private DIAccessor _diError;
  99. private DIAccessor _diWarning;
  100. private DOAccessor _doStart;
  101. private DOAccessor _doPowerOn;
  102. private R_TRIG _trigWarning = new R_TRIG();
  103. private R_TRIG _trigError = new R_TRIG();
  104. private R_TRIG _trigOverload = new R_TRIG();
  105. private R_TRIG _trigN2OK = new R_TRIG();
  106. private R_TRIG _trigExhaustPressureOK = new R_TRIG();
  107. public IoPump(string module, XmlElement node, string ioModule = "")
  108. {
  109. var attrModule = node.GetAttribute("module");
  110. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  111. base.Name = node.GetAttribute("id");
  112. base.Display = node.GetAttribute("display");
  113. base.DeviceID = node.GetAttribute("schematicId");
  114. _diError = ParseDiNode("diAlarm", node, ioModule);
  115. _diRunning = ParseDiNode("diRunning", node, ioModule);
  116. _diWarning = ParseDiNode("diWarning", node, ioModule);
  117. _diOverloadAlarm = ParseDiNode("diOverloadAlarm", node, ioModule);
  118. _diPowerOn = ParseDiNode("diPowerOn", node, ioModule);
  119. _diStart = ParseDiNode("diStart", node, ioModule);
  120. _diStop = ParseDiNode("diStop", node, ioModule);
  121. _diN2OK = ParseDiNode("diN2OK", node, ioModule);
  122. _diExhaustPressureOK = ParseDiNode("diExhaustPressureOK", node, ioModule);
  123. _doStart = ParseDoNode("doStartStop", node, ioModule);
  124. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  125. }
  126. public bool Initialize()
  127. {
  128. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  129. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.SetOnOff}" , SetPumpOnOff);
  130. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOn}", SetPumpOn);
  131. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOff}", SetPumpOff);
  132. return true;
  133. }
  134. private bool SetPumpOn(out string reason, int time, object[] param)
  135. {
  136. return SetPump(out reason, time, true);
  137. }
  138. private bool SetPumpOff(out string reason, int time, object[] param)
  139. {
  140. return SetPump(out reason, time, false);
  141. }
  142. private bool SetPumpOnOff(out string reason, int time, object[] param)
  143. {
  144. return SetPump(out reason, time, Convert.ToBoolean((string)param[0]));
  145. }
  146. public bool SetPump(out string reason, int time, bool isOn)
  147. {
  148. if (isOn)
  149. {
  150. if (IsError)
  151. {
  152. reason = "Can not set pump on, pump in error";
  153. return false;
  154. }
  155. if (IsPumpOverloadAlarm)
  156. {
  157. reason = "Can not set pump on, pump is overload";
  158. return false;
  159. }
  160. if (!IsN2OK)
  161. {
  162. reason = "Can not set pump on, pump N2 is not OK";
  163. return false;
  164. }
  165. if (!IsExhaustPressureOK)
  166. {
  167. reason = "Can not set pump on, pump exhaust pressure is not OK";
  168. return false;
  169. }
  170. }
  171. reason = string.Empty;
  172. if (_doStart != null)
  173. {
  174. _doStart.Value = isOn;
  175. }
  176. else if (_doPowerOn != null)
  177. {
  178. _doPowerOn.Value = isOn;
  179. }
  180. else
  181. {
  182. reason = "Do not support host control";
  183. return false;
  184. }
  185. return true;
  186. }
  187. public bool SetMainPowerOnOff(bool isOn, out string reason)
  188. {
  189. reason = string.Empty;
  190. return true;
  191. }
  192. public void Terminate()
  193. {
  194. }
  195. public void Monitor()
  196. {
  197. try
  198. {
  199. _trigWarning.CLK = IsWarning;
  200. if (_trigWarning.Q)
  201. {
  202. EV.PostWarningLog(Module, $"{Name} waring");
  203. }
  204. _trigError.CLK = IsError;
  205. if (_trigError.Q)
  206. {
  207. EV.PostAlarmLog(Module, $"{Name} error");
  208. if (_doPowerOn != null && _doPowerOn.Value)
  209. {
  210. _doPowerOn.Value = false;
  211. EV.PostInfoLog(Module, $"set {Name} power off");
  212. }
  213. if (_doStart != null && _doStart.Value)
  214. {
  215. _doStart.Value = false;
  216. EV.PostInfoLog(Module, $"set {Name} off");
  217. }
  218. }
  219. _trigOverload.CLK = IsPumpOverloadAlarm;
  220. if (_trigOverload.Q)
  221. {
  222. EV.PostAlarmLog(Module, $"{Name} overload");
  223. if (_doPowerOn != null && _doPowerOn.Value)
  224. {
  225. _doPowerOn.Value = false;
  226. EV.PostInfoLog(Module, $"set {Name} power off");
  227. }
  228. if (_doStart != null && _doStart.Value)
  229. {
  230. _doStart.Value = false;
  231. EV.PostInfoLog(Module, $"set {Name} off");
  232. }
  233. }
  234. _trigN2OK.CLK = !IsN2OK;
  235. if (_trigN2OK.Q)
  236. {
  237. EV.PostWarningLog(Module, $"{Name} N2 is not OK");
  238. }
  239. _trigExhaustPressureOK.CLK = !IsExhaustPressureOK;
  240. if (_trigExhaustPressureOK.Q)
  241. {
  242. EV.PostWarningLog(Module, $"{Name} exhaust pressure is not OK");
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. LOG.Write(ex);
  248. }
  249. }
  250. public void Reset()
  251. {
  252. _trigOverload.RST = true;
  253. _trigWarning.RST = true;
  254. _trigError.RST = true;
  255. _trigN2OK.RST = true;
  256. _trigExhaustPressureOK.RST = true;
  257. }
  258. }
  259. }