IoGasStick.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Security.Cryptography;
  3. using System.Xml;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Device.Unit;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.Util;
  10. using Venus_RT.Devices.IODevices;
  11. namespace Venus_RT.Devices
  12. {
  13. class IoGasStick : BaseDevice, IDevice
  14. {
  15. private readonly IoValve _DownValve;
  16. private readonly IoValve _UpValve;
  17. //private DIAccessor _diPressureAlarm;
  18. private DOAccessor _doByPassPressureAlarm;
  19. public readonly MfcBase1 _mfc;
  20. // Properties
  21. //
  22. public double FlowSP
  23. {
  24. get => _mfc.SetPoint;
  25. //set => _mfc.SetPoint = value;
  26. }
  27. public bool IsOutOfRange => _mfc.IsOutOfTolerance;
  28. private F_TRIG _trigPressureAlarm = new F_TRIG();
  29. // Constructor
  30. //
  31. public IoGasStick(string module, XmlElement node, string ioModule = "")
  32. {
  33. base.Module = module;
  34. base.Name = node.GetAttribute("id");
  35. base.Display = node.GetAttribute("display");
  36. base.DeviceID = node.GetAttribute("schematicId");
  37. _DownValve = ParseDeviceNode<IoValve>(Module, "downvalve", node);
  38. _UpValve = ParseDeviceNode<IoValve>(Module, "upvalve", node);
  39. _mfc = ParseDeviceNode<MfcBase1>(Module, "mfc", node);
  40. //_diPressureAlarm = ParseDiNode("diPressureAlarm", node, ioModule);
  41. _doByPassPressureAlarm = ParseDoNode("doByPassPressureAlarm", node, ioModule);
  42. }
  43. public bool Initialize()
  44. {
  45. OP.Subscribe($"{Module}.{_mfc.Name}", (out string reason, int time, object[] para) =>
  46. {
  47. reason = "";
  48. double sp = Convert.ToDouble((string)para[0]);
  49. Flow(sp);
  50. return true;
  51. });
  52. return true;
  53. }
  54. public void Flow(double setpoint)
  55. {
  56. if (setpoint >= 0.01)
  57. {
  58. _DownValve.TurnValve(true, out _);
  59. _UpValve?.TurnValve(true, out _);
  60. }
  61. else
  62. {
  63. _DownValve.TurnValve(false, out _);
  64. _UpValve?.TurnValve(false, out _);
  65. }
  66. _mfc.SetPoint = setpoint;
  67. //_mfc.Ramp(setpoint, 1000);
  68. }
  69. public void Pump()
  70. {
  71. _UpValve?.TurnValve(true, out _);
  72. _mfc.SetPoint = _mfc.Scale;
  73. }
  74. public void Monitor()
  75. {
  76. _DownValve.Monitor();
  77. if (_mfc.Name == "MfcN2" && _DownValve?.Status == false)
  78. {
  79. return;
  80. }
  81. _trigPressureAlarm.CLK = _mfc.PressureAlarm;
  82. if (_trigPressureAlarm.Q )
  83. {
  84. eEvent _eEvent;
  85. if (_mfc.SetPoint > 0 && _doByPassPressureAlarm?.Value == false)
  86. {
  87. switch (_mfc.Display)
  88. {
  89. case "Gas1":
  90. _eEvent = eEvent.ERR_MFC1_PRESSURE;
  91. break;
  92. case "Gas2":
  93. _eEvent = eEvent.ERR_MFC2_PRESSURE;
  94. break;
  95. case "Gas3":
  96. _eEvent = eEvent.ERR_MFC3_PRESSURE;
  97. break;
  98. case "Gas4":
  99. _eEvent = eEvent.ERR_MFC4_PRESSURE;
  100. break;
  101. case "Gas5":
  102. _eEvent = eEvent.ERR_MFC5_PRESSURE;
  103. break;
  104. case "Gas6":
  105. _eEvent = eEvent.ERR_MFC6_PRESSURE;
  106. break;
  107. case "Gas7":
  108. _eEvent = eEvent.ERR_MFC7_PRESSURE;
  109. break;
  110. case "Gas8":
  111. _eEvent = eEvent.ERR_MFC8_PRESSURE;
  112. break;
  113. case "N2":
  114. _eEvent = eEvent.ERR_N2_PRESSURE;
  115. break;
  116. default:
  117. _eEvent = eEvent.WARN_DEVICE_INFO;
  118. break;
  119. }
  120. _DownValve.TurnValve(false, out _);
  121. _UpValve?.TurnValve(false, out _);
  122. _mfc.SetPoint = 0;
  123. }
  124. else
  125. {
  126. switch (_mfc.Display)
  127. {
  128. case "Gas1":
  129. _eEvent = eEvent.WARN_MFC1_PRESSURE;
  130. break;
  131. case "Gas2":
  132. _eEvent = eEvent.WARN_MFC2_PRESSURE;
  133. break;
  134. case "Gas3":
  135. _eEvent = eEvent.WARN_MFC3_PRESSURE;
  136. break;
  137. case "Gas4":
  138. _eEvent = eEvent.WARN_MFC4_PRESSURE;
  139. break;
  140. case "Gas5":
  141. _eEvent = eEvent.WARN_MFC5_PRESSURE;
  142. break;
  143. case "Gas6":
  144. _eEvent = eEvent.WARN_MFC6_PRESSURE;
  145. break;
  146. case "Gas7":
  147. _eEvent = eEvent.WARN_MFC7_PRESSURE;
  148. break;
  149. case "Gas8":
  150. _eEvent = eEvent.WARN_MFC8_PRESSURE;
  151. break;
  152. case "N2":
  153. _eEvent = eEvent.WARN_N2_PRESSURE;
  154. break;
  155. default:
  156. _eEvent = eEvent.WARN_DEVICE_INFO;
  157. break;
  158. }
  159. }
  160. LOG.Write(_eEvent, Module, $"{Name}, {_mfc.Display} Pressure Alarm");
  161. }
  162. }
  163. public void Terminate()
  164. {
  165. }
  166. public void Reset()
  167. {
  168. }
  169. public void Stop()
  170. {
  171. _DownValve.TurnValve(false, out _);
  172. _UpValve?.TurnValve(false, out _);
  173. //_mfc.Ramp(0, 1000);
  174. _mfc.SetPoint = 0;
  175. }
  176. }
  177. }