IoPump.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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.Common.Event;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Pumps;
  13. namespace FurnaceRT.Equipments.Systems
  14. {
  15. public class IoPump : BaseDevice, IDevice, IPump
  16. {
  17. public bool IsRunning
  18. {
  19. get
  20. {
  21. if (_diRunning != null)
  22. return _diRunning.Value;
  23. if (_diPowerOn != null)
  24. return _diPowerOn.Value;
  25. return true; //默认常开
  26. }
  27. }
  28. public bool IsWarning
  29. {
  30. get
  31. {
  32. return _diWarning != null && _diWarning.Value;
  33. }
  34. }
  35. public bool IsError
  36. {
  37. get
  38. {
  39. return _diError != null && _diError.Value;
  40. }
  41. }
  42. public bool IsPumpOverloadAlarm
  43. {
  44. get
  45. {
  46. return _diOverloadAlarm != null && _diOverloadAlarm.Value;
  47. }
  48. }
  49. public bool HasError
  50. {
  51. get
  52. {
  53. return IsPumpOverloadAlarm || IsError;
  54. }
  55. }
  56. public bool IsN2OK
  57. {
  58. get
  59. {
  60. if (_diN2OK == null)
  61. return true;
  62. return _diN2OK.Value;
  63. }
  64. }
  65. public bool IsExhaustPressureOK
  66. {
  67. get
  68. {
  69. if (_diExhaustPressureOK == null)
  70. return true;
  71. return _diExhaustPressureOK.Value;
  72. }
  73. }
  74. private AITPumpData DeviceData
  75. {
  76. get
  77. {
  78. AITPumpData data = new AITPumpData()
  79. {
  80. DeviceName = Name,
  81. DeviceSchematicId = DeviceID,
  82. DisplayName = Display,
  83. DeviceModule = Module,
  84. Module = Module,
  85. IsOn = IsRunning,
  86. IsError = IsError,
  87. IsOverLoad = IsPumpOverloadAlarm,
  88. };
  89. return data;
  90. }
  91. }
  92. private DIAccessor _diRunning = null;
  93. private DIAccessor _diOverloadAlarm;
  94. private DIAccessor _diPowerOn;
  95. private DIAccessor _diStart;
  96. private DIAccessor _diStop;
  97. private DIAccessor _diN2OK;
  98. private DIAccessor _diExhaustPressureOK;
  99. private DIAccessor _diError;
  100. private DIAccessor _diWarning;
  101. private DOAccessor _doStart;
  102. private DOAccessor _doPowerOn;
  103. private R_TRIG _trigWarning = new R_TRIG();
  104. private R_TRIG _trigError = new R_TRIG();
  105. private R_TRIG _trigOverload = new R_TRIG();
  106. private R_TRIG _trigN2OK = new R_TRIG();
  107. private R_TRIG _trigExhaustPressureOK = new R_TRIG();
  108. public AlarmEventItem PumpWarning { get; set; }
  109. public AlarmEventItem PumpError { get; set; }
  110. public AlarmEventItem PumpOverload { get; set; }
  111. public AlarmEventItem PumpN2NotOK { get; set; }
  112. public AlarmEventItem PumpExhaustPressureNotOK { get; set; }
  113. public IoPump(string module, XmlElement node, string ioModule = "")
  114. {
  115. var attrModule = node.GetAttribute("module");
  116. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  117. base.Name = node.GetAttribute("id");
  118. base.Display = node.GetAttribute("display");
  119. base.DeviceID = node.GetAttribute("schematicId");
  120. _diError = ParseDiNode("diAlarm", node, ioModule);
  121. _diRunning = ParseDiNode("diRunning", node, ioModule);
  122. _diWarning = ParseDiNode("diWarning", node, ioModule);
  123. _diOverloadAlarm = ParseDiNode("diOverloadAlarm", node, ioModule);
  124. _diPowerOn = ParseDiNode("diPowerOn", node, ioModule);
  125. _diStart = ParseDiNode("diStart", node, ioModule);
  126. _diStop = ParseDiNode("diStop", node, ioModule);
  127. _diN2OK = ParseDiNode("diN2OK", node, ioModule);
  128. _diExhaustPressureOK = ParseDiNode("diExhaustPressureOK", node, ioModule);
  129. _doStart = ParseDoNode("doStartStop", node, ioModule);
  130. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  131. }
  132. public bool Initialize()
  133. {
  134. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  135. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.SetOnOff}" , SetPumpOnOff);
  136. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOn}", SetPumpOn);
  137. OP.Subscribe($"{Module}.{Name}.{AITPumpOperation.PumpOff}", SetPumpOff);
  138. PumpWarning = SubscribeAlarm(new AlarmEventItem()
  139. {
  140. EventEnum = $"{Module}.{Name}PumpWarning",
  141. Description = $"{Name} warning ",
  142. Solution = "No information available. Press[Clear] to delete alarm message.",
  143. Explaination = "No information available.",
  144. AutoRecovery = false,
  145. Level = EventLevel.Warning,
  146. Action = EventAction.Clear,
  147. Category = "TubeAlarm",
  148. }, () => { Reset(); return true; });
  149. PumpError = SubscribeAlarm(new AlarmEventItem()
  150. {
  151. EventEnum = $"{Module}.{Name}PumpError",
  152. Description = $"{Name} error ",
  153. Solution = "No information available. Press[Clear] to delete alarm message.",
  154. Explaination = "No information available.",
  155. AutoRecovery = false,
  156. Level = EventLevel.Alarm,
  157. Action = EventAction.Clear,
  158. Category = "TubeAlarm",
  159. }, () => { Reset(); return true; });
  160. PumpOverload = SubscribeAlarm(new AlarmEventItem()
  161. {
  162. EventEnum = $"{Module}.{Name}PumpOverload",
  163. Description = $"{Name} overload ",
  164. Solution = "No information available. Press[Clear] to delete alarm message.",
  165. Explaination = "No information available.",
  166. AutoRecovery = false,
  167. Level = EventLevel.Alarm,
  168. Action = EventAction.Clear,
  169. Category = "TubeAlarm",
  170. }, () => { Reset(); return true; });
  171. PumpN2NotOK = SubscribeAlarm(new AlarmEventItem()
  172. {
  173. EventEnum = $"{Module}.{Name}PumpN2NotOK",
  174. Description = $"{Name} N2 not ok ",
  175. Solution = "No information available. Press[Clear] to delete alarm message.",
  176. Explaination = "No information available.",
  177. AutoRecovery = false,
  178. Level = EventLevel.Alarm,
  179. Action = EventAction.Clear,
  180. Category = "TubeAlarm",
  181. }, () => { Reset(); return true; });
  182. PumpExhaustPressureNotOK = SubscribeAlarm(new AlarmEventItem()
  183. {
  184. EventEnum = $"{Module}.{Name}PumpExhaustPressureNotOK",
  185. Description = $"{Name} exhaust pressure not ok ",
  186. Solution = "No information available. Press[Clear] to delete alarm message.",
  187. Explaination = "No information available.",
  188. AutoRecovery = false,
  189. Level = EventLevel.Alarm,
  190. Action = EventAction.Clear,
  191. Category = "TubeAlarm",
  192. }, () => { Reset(); return true; });
  193. return true;
  194. }
  195. private bool SetPumpOn(out string reason, int time, object[] param)
  196. {
  197. return SetPump(out reason, time, true);
  198. }
  199. private bool SetPumpOff(out string reason, int time, object[] param)
  200. {
  201. return SetPump(out reason, time, false);
  202. }
  203. private bool SetPumpOnOff(out string reason, int time, object[] param)
  204. {
  205. return SetPump(out reason, time, Convert.ToBoolean((string)param[0]));
  206. }
  207. public bool SetPump(out string reason, int time, bool isOn)
  208. {
  209. if (isOn)
  210. {
  211. if (IsError)
  212. {
  213. reason = "Can not set pump on, pump in error";
  214. return false;
  215. }
  216. if (IsPumpOverloadAlarm)
  217. {
  218. reason = "Can not set pump on, pump is overload";
  219. return false;
  220. }
  221. if (!IsN2OK)
  222. {
  223. reason = "Can not set pump on, pump N2 is not OK";
  224. return false;
  225. }
  226. if (!IsExhaustPressureOK)
  227. {
  228. reason = "Can not set pump on, pump exhaust pressure is not OK";
  229. return false;
  230. }
  231. }
  232. reason = string.Empty;
  233. if (_doStart != null)
  234. {
  235. _doStart.Value = isOn;
  236. }
  237. else if (_doPowerOn != null)
  238. {
  239. _doPowerOn.Value = isOn;
  240. }
  241. else
  242. {
  243. reason = "Do not support host control";
  244. return false;
  245. }
  246. return true;
  247. }
  248. public bool SetMainPowerOnOff(bool isOn, out string reason)
  249. {
  250. reason = string.Empty;
  251. return true;
  252. }
  253. public void Terminate()
  254. {
  255. }
  256. public void Monitor()
  257. {
  258. try
  259. {
  260. //_trigWarning.CLK = IsWarning;
  261. //if (_trigWarning.Q)
  262. //{
  263. // PumpWarning.Set();
  264. //}
  265. //_trigError.CLK = IsError;
  266. //if (_trigError.Q)
  267. //{
  268. // PumpError.Set();
  269. // if (_doPowerOn != null && _doPowerOn.Value)
  270. // {
  271. // _doPowerOn.Value = false;
  272. // EV.PostInfoLog(Module, $"set {Name} power off");
  273. // }
  274. // if (_doStart != null && _doStart.Value)
  275. // {
  276. // _doStart.Value = false;
  277. // EV.PostInfoLog(Module, $"set {Name} off");
  278. // }
  279. //}
  280. //_trigOverload.CLK = IsPumpOverloadAlarm;
  281. //if (_trigOverload.Q)
  282. //{
  283. // PumpOverload.Set();
  284. // if (_doPowerOn != null && _doPowerOn.Value)
  285. // {
  286. // _doPowerOn.Value = false;
  287. // EV.PostInfoLog(Module, $"set {Name} power off");
  288. // }
  289. // if (_doStart != null && _doStart.Value)
  290. // {
  291. // _doStart.Value = false;
  292. // EV.PostInfoLog(Module, $"set {Name} off");
  293. // }
  294. //}
  295. //_trigN2OK.CLK = !IsN2OK;
  296. //if (_trigN2OK.Q)
  297. //{
  298. // PumpN2NotOK.Set();
  299. //}
  300. //_trigExhaustPressureOK.CLK = !IsExhaustPressureOK;
  301. //if (_trigExhaustPressureOK.Q)
  302. //{
  303. // PumpExhaustPressureNotOK.Set();
  304. //}
  305. }
  306. catch (Exception ex)
  307. {
  308. LOG.Write(ex);
  309. }
  310. }
  311. public void Reset()
  312. {
  313. _trigWarning.RST = true;
  314. _trigError.RST = true;
  315. _trigOverload.RST = true;
  316. _trigN2OK.RST = true;
  317. _trigExhaustPressureOK.RST = true;
  318. if (PumpWarning != null)
  319. PumpWarning.IsAcknowledged = true;
  320. if (PumpError != null)
  321. PumpError.IsAcknowledged = true;
  322. if (PumpOverload != null)
  323. PumpOverload.IsAcknowledged = true;
  324. if (PumpN2NotOK != null)
  325. PumpN2NotOK.IsAcknowledged = true;
  326. if (PumpExhaustPressureNotOK != null)
  327. PumpExhaustPressureNotOK.IsAcknowledged = true;
  328. //PumpWarning.Reset();
  329. //PumpError.Reset();
  330. //PumpOverload.Reset();
  331. //PumpN2NotOK.Reset();
  332. //PumpExhaustPressureNotOK.Reset();
  333. }
  334. }
  335. }