IoPressureControl.cs 11 KB

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