IoPressureControl.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.RT.Tolerance;
  10. using Aitex.Core.Util;
  11. using VirgoRT.Devices.IODevices;
  12. namespace VirgoRT.Devices
  13. {
  14. public class IoPressureControl : BaseDevice, IDevice
  15. {
  16. private bool _enableTolerance;
  17. public bool EnableTolerance
  18. {
  19. get
  20. {
  21. return _enableTolerance;
  22. }
  23. set
  24. {
  25. if (_enableTolerance != value)
  26. {
  27. EV.PostInfoLog(Module, value ? "Start monitor pressure stability" : "Stop monitor pressure stability");
  28. if (value)
  29. {
  30. _tolerance.Reset(_scAlarmTime.DoubleValue);
  31. }
  32. }
  33. _enableTolerance = value;
  34. }
  35. }
  36. public bool IsIndependentControl
  37. {
  38. get
  39. {
  40. if (_scIsIndependentControl != null)
  41. return _scIsIndependentControl.BoolValue;
  42. return false;
  43. }
  44. }
  45. public bool IsTvInstalled
  46. {
  47. get
  48. {
  49. if (_scTvInstalled != null)
  50. return _scTvInstalled.BoolValue;
  51. return false;
  52. }
  53. }
  54. public bool IsBoostPumpInstalled
  55. {
  56. get
  57. {
  58. if (_scIsBoostPumpInstalled != null)
  59. return _scIsBoostPumpInstalled.BoolValue;
  60. return false;
  61. }
  62. }
  63. public bool EnableBoostControl
  64. {
  65. get
  66. {
  67. return _diLogicProcessGasFlowing == null || _diLogicProcessGasFlowing.Value;
  68. }
  69. }
  70. public readonly IoThrottleValve ThrottleValve;
  71. public readonly IoPressureMeter PressureGauge;
  72. public readonly IoPressureMeter ProcessGauge;
  73. public readonly IoPressureMeter ForelineGauge;
  74. //public readonly IoBoostPump _boost;
  75. //public readonly IoPump DryPump;
  76. private readonly ToleranceChecker _tolerance = new ToleranceChecker();
  77. private readonly SCConfigItem _scAlarmRange;
  78. private readonly SCConfigItem _scAlarmTime;
  79. private readonly SCConfigItem _scIsIndependentControl;
  80. private readonly SCConfigItem _scIsBoostPumpInstalled;
  81. private readonly SCConfigItem _scTvInstalled;
  82. private readonly DIAccessor _diLogicProcessGasFlowing;
  83. private readonly R_TRIG _trigPressureGauge = new R_TRIG();
  84. private readonly R_TRIG _trigProcessGauge = new R_TRIG();
  85. private readonly R_TRIG _trigForelineGauge = new R_TRIG();
  86. // Properties
  87. //
  88. public double TargetPressure { get; set; }
  89. private string PressureOutOfTolerance = "PressureOutOfTolerance";
  90. // Constructor
  91. //
  92. public IoPressureControl(string module, XmlElement node, string ioModule = "")
  93. {
  94. base.Module = module;
  95. base.Name = node.GetAttribute("id");
  96. base.Display = node.GetAttribute("display");
  97. base.DeviceID = node.GetAttribute("schematicId");
  98. _diLogicProcessGasFlowing = ParseDiNode("diLogicProcessGasFlowing", node, ioModule);
  99. _scAlarmRange = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmRange");
  100. _scAlarmTime = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmTime");
  101. _scIsIndependentControl = SC.GetConfigItem($"{Module}.IsIndependentControl");
  102. _scIsBoostPumpInstalled = SC.GetConfigItem($"{Module}.EnableBoosterPump");
  103. _scTvInstalled = SC.GetConfigItem($"{Module}.EnableThrottleValve");
  104. //_enableTolerance = true;
  105. ThrottleValve = ParseDeviceNode<IoThrottleValve>(Module, "tv", node);
  106. PressureGauge = ParseDeviceNode<IoPressureMeter>(Module, "pressureMeter", node);
  107. ProcessGauge = ParseDeviceNode<IoPressureMeter>(Module, "processMeter", node);
  108. ForelineGauge = ParseDeviceNode<IoPressureMeter>(Module, "forelineMeter", node);
  109. //DryPump = ParseDeviceNode<IoPump>(Module, "drypump", node);
  110. }
  111. public bool Initialize()
  112. {
  113. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", _setTVPressure);
  114. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", _setTVPosition);
  115. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", _setTVMode);
  116. //DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetBoostPressure}", _setBoostPressure);
  117. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", _setChamberPressure);
  118. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", (out string reason, int time, object[] param) =>
  119. {
  120. _setChamberPressure(out reason, 0, param);
  121. return true;
  122. });
  123. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", (out string reason, int time, object[] param) =>
  124. {
  125. _setTVMode(out reason, 0, param);
  126. return true;
  127. });
  128. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", (out string reason, int time, object[] param) =>
  129. {
  130. _setTVPressure(out reason, 0, param);
  131. return true;
  132. });
  133. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", (out string reason, int time, object[] param) =>
  134. {
  135. _setTVPosition(out reason, 0, param);
  136. return true;
  137. });
  138. EV.Subscribe(new EventItem("Event", PressureOutOfTolerance, "Pressure Out Of Tolerance", EventLevel.Alarm, EventType.HostNotification));
  139. return true;
  140. }
  141. //public void StartPump(bool on)
  142. //{
  143. // this.DryPump?.Start(on);
  144. //}
  145. public void FullOpenThrottleValve()
  146. {
  147. this.ThrottleValve.PressureMode = PressureCtrlMode.TVPositionCtrl;
  148. this.ThrottleValve.PositionSetpoint = 100;
  149. }
  150. private bool? _setTVPressure(out string reason, int time, object[] param)
  151. {
  152. double target = Convert.ToDouble((string)param[0]);
  153. if (!IsTvInstalled)
  154. {
  155. reason = "Throttle valve not config";
  156. return true;
  157. }
  158. if (ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)
  159. {
  160. reason = "Throttle valve is in position control mode, can not set pressure";
  161. return false;
  162. }
  163. ThrottleValve.PressureSetpoint = (short)target;
  164. ThrottleValve.PositionSetpoint = 0.0f;
  165. reason = $"TV pressure set to {target} mTorr";
  166. return true;
  167. }
  168. private bool? _setTVPosition(out string reason, int time, object[] param)
  169. {
  170. double target = Convert.ToDouble((string)param[0]);
  171. if (!IsTvInstalled)
  172. {
  173. reason = "Throttle valve not config";
  174. return true;
  175. }
  176. if (ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)
  177. {
  178. reason = "Throttle valve is in pressure control mode, can not set position";
  179. return false;
  180. }
  181. ThrottleValve.PressureSetpoint = 0.0f;
  182. ThrottleValve.PositionSetpoint = (short)target;
  183. reason = $"TV position set to {target}";
  184. return true;
  185. }
  186. private bool? _setTVMode(out string reason, int time, object[] param)
  187. {
  188. reason = string.Empty;
  189. if (!IsTvInstalled)
  190. {
  191. reason = "Throttle valve not config";
  192. return true;
  193. }
  194. ThrottleValve.PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);
  195. reason = $"TV mode set to {ThrottleValve.PressureMode}";
  196. return true;
  197. }
  198. private bool? _setChamberPressure(out string reason, int time, object[] param)
  199. {
  200. double setpoint = Convert.ToDouble((string)param[0]);
  201. TargetPressure = setpoint;
  202. reason = $"Chamber pressure set to {setpoint} mTorr";
  203. return true;
  204. }
  205. public void Terminate()
  206. {
  207. }
  208. public void Monitor()
  209. {
  210. CheckTolerance();
  211. _trigProcessGauge.CLK = ProcessGauge.GaugeAlarm;
  212. if (_trigProcessGauge.Q) EV.PostAlarmLog(Module, "Process pressure gauge Alarm");
  213. _trigPressureGauge.CLK = PressureGauge.GaugeAlarm;
  214. if (_trigPressureGauge.Q) EV.PostAlarmLog(Module, "Chamber pressure gauge Alarm");
  215. _trigForelineGauge.CLK = ForelineGauge.GaugeAlarm;
  216. if (_trigForelineGauge.Q) EV.PostAlarmLog(Module, "Foreline pressure gauge Alarm");
  217. }
  218. public void CheckTolerance()
  219. {
  220. if (!EnableTolerance)
  221. return;
  222. if (ThrottleValve != null && IsTvInstalled && ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)
  223. return;
  224. _tolerance.Monitor(PressureGauge.Value,
  225. TargetPressure - Math.Abs(_scAlarmRange.DoubleValue),
  226. TargetPressure + Math.Abs(_scAlarmRange.DoubleValue), _scAlarmTime.DoubleValue);
  227. if (_tolerance.Trig)
  228. {
  229. EV.Notify(PressureOutOfTolerance);
  230. EV.PostAlarmLog(Module, $"Gas Flow Pressure Alarm Out of range in {_scAlarmTime.Value:0} seconds");
  231. }
  232. }
  233. public void Reset()
  234. {
  235. _trigProcessGauge.RST = true;
  236. _trigPressureGauge.RST = true;
  237. _trigForelineGauge.RST = true;
  238. if (_scAlarmTime != null)
  239. {
  240. _tolerance.Reset(_scAlarmTime.DoubleValue);
  241. }
  242. }
  243. }
  244. }