IoPressureControl.cs 11 KB

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