IoPressureControl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.RT.Tolerance;
  8. using Aitex.Core.Util;
  9. using System;
  10. using System.Xml;
  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. _alarmChecker.Reset(_scAlarmTime.DoubleValue);
  31. _warningChecker.Reset(_scWarningTime.DoubleValue);
  32. _recipeWarningChecker.RST = true;
  33. _recipeAlarmChecker.RST = true;
  34. }
  35. }
  36. _enableTolerance = value;
  37. }
  38. }
  39. public bool IsIndependentControl
  40. {
  41. get
  42. {
  43. if (_scIsIndependentControl != null)
  44. return _scIsIndependentControl.BoolValue;
  45. return false;
  46. }
  47. }
  48. public bool IsTvInstalled
  49. {
  50. get
  51. {
  52. if (_scTvInstalled != null)
  53. return _scTvInstalled.BoolValue;
  54. return false;
  55. }
  56. }
  57. public bool IsBoostPumpInstalled
  58. {
  59. get
  60. {
  61. if (_scIsBoostPumpInstalled != null)
  62. return _scIsBoostPumpInstalled.BoolValue;
  63. return false;
  64. }
  65. }
  66. public bool EnableBoostControl
  67. {
  68. get
  69. {
  70. return _diLogicProcessGasFlowing == null || _diLogicProcessGasFlowing.Value;
  71. }
  72. }
  73. public readonly IoThrottleValve ThrottleValve;
  74. public readonly IoPressureMeter PressureGauge;
  75. public readonly IoPressureMeter ProcessGauge;
  76. public readonly IoPressureMeter ForelineGauge;
  77. //public readonly IoBoostPump _boost;
  78. //public readonly IoPump DryPump;
  79. private ToleranceChecker _alarmChecker = new ToleranceChecker();
  80. private ToleranceChecker _warningChecker = new ToleranceChecker();
  81. private readonly SCConfigItem _scAlarmRange;
  82. private readonly SCConfigItem _scAlarmTime;
  83. private readonly SCConfigItem _scWarningRange;
  84. private readonly SCConfigItem _scWarningTime;
  85. private readonly SCConfigItem _scIsIndependentControl;
  86. private readonly SCConfigItem _scIsBoostPumpInstalled;
  87. private readonly SCConfigItem _scTvInstalled;
  88. private readonly DIAccessor _diLogicProcessGasFlowing;
  89. private readonly R_TRIG _trigPressureGauge = new R_TRIG();
  90. private readonly R_TRIG _trigProcessGauge = new R_TRIG();
  91. private readonly R_TRIG _trigForelineGauge = new R_TRIG();
  92. // Properties
  93. //
  94. public double TargetPressure { get; set; }
  95. private string PressureOutOfTolerance = "PressureOutOfTolerance";
  96. private float _recipeAlarmRange;
  97. private float _recipeWarningRange;
  98. private int _ignoreTimeMS;
  99. private ToleranceChecker _recipeAlarmChecker = new ToleranceChecker();
  100. private ToleranceChecker _recipeWarningChecker = new ToleranceChecker();
  101. private DeviceTimer _ignoreTimer = new DeviceTimer();
  102. public IoPressureControl(string module, XmlElement node, string ioModule = "")
  103. {
  104. base.Module = module;
  105. base.Name = node.GetAttribute("id");
  106. base.Display = node.GetAttribute("display");
  107. base.DeviceID = node.GetAttribute("schematicId");
  108. _diLogicProcessGasFlowing = ParseDiNode("diLogicProcessGasFlowing", node, ioModule);
  109. _scAlarmRange = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmRange");
  110. _scAlarmTime = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmTime");
  111. _scWarningRange = SC.GetConfigItem($"{Module}.GasFlowPressureWarningRange");
  112. _scWarningTime = SC.GetConfigItem($"{Module}.GasFlowPressureWarningTime");
  113. _scIsIndependentControl = SC.GetConfigItem($"{Module}.IsIndependentControl");
  114. _scIsBoostPumpInstalled = SC.GetConfigItem($"{Module}.EnableBoosterPump");
  115. _scTvInstalled = SC.GetConfigItem($"{Module}.EnableThrottleValve");
  116. //_enableTolerance = true;
  117. ThrottleValve = ParseDeviceNode<IoThrottleValve>(Module, "tv", node);
  118. PressureGauge = ParseDeviceNode<IoPressureMeter>(Module, "pressureMeter", node);
  119. ProcessGauge = ParseDeviceNode<IoPressureMeter>(Module, "processMeter", node);
  120. ForelineGauge = ParseDeviceNode<IoPressureMeter>(Module, "forelineMeter", node);
  121. //DryPump = ParseDeviceNode<IoPump>(Module, "drypump", node);
  122. }
  123. public bool Initialize()
  124. {
  125. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", _setTVPressure);
  126. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", _setTVPosition);
  127. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", _setTVMode);
  128. //DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetBoostPressure}", _setBoostPressure);
  129. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", _setChamberPressure);
  130. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", (out string reason, int time, object[] param) =>
  131. {
  132. _setChamberPressure(out reason, 0, param);
  133. return true;
  134. });
  135. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", (out string reason, int time, object[] param) =>
  136. {
  137. _setTVMode(out reason, 0, param);
  138. return true;
  139. });
  140. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", (out string reason, int time, object[] param) =>
  141. {
  142. _setTVPressure(out reason, 0, param);
  143. return true;
  144. });
  145. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", (out string reason, int time, object[] param) =>
  146. {
  147. _setTVPosition(out reason, 0, param);
  148. return true;
  149. });
  150. OP.Subscribe($"{Module}.{Name}.SetRecipeTolerance", (out string reason, int time, object[] param) =>
  151. {
  152. reason = string.Empty;
  153. _ignoreTimeMS = Convert.ToInt32(param[0]) * 1000;
  154. _recipeWarningRange = Convert.ToSingle(param[1]);
  155. _recipeAlarmRange = Convert.ToSingle(param[2]);
  156. _recipeAlarmChecker.RST = true;
  157. _recipeWarningChecker.RST = true;
  158. //if (_recipeIgnoreTimeMS > 0)
  159. _ignoreTimer.Start(0);
  160. return true;
  161. });
  162. EV.Subscribe(new EventItem("Event", PressureOutOfTolerance, "Pressure Out Of Tolerance", EventLevel.Alarm, EventType.HostNotification));
  163. return true;
  164. }
  165. //public void StartPump(bool on)
  166. //{
  167. // this.DryPump?.Start(on);
  168. //}
  169. public void FullOpenThrottleValve()
  170. {
  171. this.ThrottleValve.PressureMode = PressureCtrlMode.TVPositionCtrl;
  172. this.ThrottleValve.PositionSetpoint = 100;
  173. }
  174. private bool? _setTVPressure(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.TVPositionCtrl)
  183. {
  184. reason = "Throttle valve is in position control mode, can not set pressure";
  185. return false;
  186. }
  187. ThrottleValve.PressureSetpoint = (short)target;
  188. ThrottleValve.PositionSetpoint = 0.0f;
  189. TargetPressure = ThrottleValve.PressureSetpoint;
  190. reason = $"TV pressure set to {target} mTorr";
  191. return true;
  192. }
  193. private bool? _setTVPosition(out string reason, int time, object[] param)
  194. {
  195. double target = Convert.ToDouble((string)param[0]);
  196. if (!IsTvInstalled)
  197. {
  198. reason = "Throttle valve not config";
  199. return true;
  200. }
  201. if (ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)
  202. {
  203. reason = "Throttle valve is in pressure control mode, can not set position";
  204. return false;
  205. }
  206. ThrottleValve.PressureSetpoint = 0.0f;
  207. ThrottleValve.PositionSetpoint = (short)target;
  208. reason = $"TV position set to {target}";
  209. return true;
  210. }
  211. private bool? _setTVMode(out string reason, int time, object[] param)
  212. {
  213. reason = string.Empty;
  214. if (!IsTvInstalled)
  215. {
  216. reason = "Throttle valve not config";
  217. return true;
  218. }
  219. ThrottleValve.PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);
  220. reason = $"TV mode set to {ThrottleValve.PressureMode}";
  221. return true;
  222. }
  223. private bool? _setChamberPressure(out string reason, int time, object[] param)
  224. {
  225. double setpoint = Convert.ToDouble((string)param[0]);
  226. TargetPressure = setpoint;
  227. reason = $"Chamber pressure set to {setpoint} mTorr";
  228. return true;
  229. }
  230. public void Terminate()
  231. {
  232. }
  233. public void Monitor()
  234. {
  235. CheckTolerance();
  236. _trigProcessGauge.CLK = ProcessGauge.GaugeAlarm;
  237. if (_trigProcessGauge.Q) EV.PostAlarmLog(Module, "Process pressure gauge Alarm");
  238. _trigPressureGauge.CLK = PressureGauge.GaugeAlarm;
  239. if (_trigPressureGauge.Q) EV.PostAlarmLog(Module, "Chamber pressure gauge Alarm");
  240. _trigForelineGauge.CLK = ForelineGauge.GaugeAlarm;
  241. if (_trigForelineGauge.Q) EV.PostAlarmLog(Module, "Foreline pressure gauge Alarm");
  242. }
  243. public void CheckTolerance()
  244. {
  245. if (!EnableTolerance)
  246. return;
  247. if (ThrottleValve != null && IsTvInstalled && ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)
  248. {
  249. return;
  250. }
  251. double alarmRange = _scAlarmRange.DoubleValue;
  252. double alarmTime = _scAlarmTime.DoubleValue;
  253. ToleranceChecker alarmChecker = _alarmChecker;
  254. if ((_recipeAlarmRange > 0) && (_recipeAlarmRange / 100.0 * TargetPressure < _scAlarmRange.DoubleValue))
  255. {
  256. alarmRange = _recipeAlarmRange / 100.0 * TargetPressure;
  257. alarmChecker = _recipeAlarmChecker;
  258. _alarmChecker.RST = true;
  259. }
  260. else
  261. {
  262. _recipeAlarmChecker.RST = true;
  263. }
  264. if (_ignoreTimer.GetElapseTime() > _ignoreTimeMS)
  265. {
  266. alarmChecker.Monitor(ProcessGauge.Value, TargetPressure - Math.Abs(alarmRange), TargetPressure + Math.Abs(alarmRange), alarmTime);
  267. if (alarmChecker.Trig)
  268. {
  269. EV.PostAlarmLog(Module, $" Pressure={ProcessGauge.Value}, TargetPressure={TargetPressure}, out of tolerance({TargetPressure - Math.Abs(alarmRange)},{TargetPressure + Math.Abs(alarmRange)}) in {alarmTime:0} seconds");
  270. }
  271. }
  272. double warningRange = _scWarningRange.DoubleValue;
  273. double warningTime = _scWarningTime.DoubleValue;
  274. ToleranceChecker warningChecker = _warningChecker;
  275. if ((_recipeWarningRange > 0) && (_recipeWarningRange / 100.0 * TargetPressure < _scWarningRange.DoubleValue))
  276. {
  277. warningRange = _recipeWarningRange / 100.0 * TargetPressure;
  278. warningChecker = _recipeWarningChecker;
  279. _warningChecker.RST = true;
  280. }
  281. else
  282. {
  283. _recipeWarningChecker.RST = true;
  284. }
  285. if (_ignoreTimer.GetElapseTime() > _ignoreTimeMS)
  286. {
  287. warningChecker.Monitor(ProcessGauge.Value, TargetPressure - Math.Abs(warningRange), TargetPressure + Math.Abs(warningRange), warningTime);
  288. if (warningChecker.Trig)
  289. {
  290. EV.PostWarningLog(Module, $" Pressure={ProcessGauge.Value}, TargetPressure={TargetPressure}, out of tolerance({TargetPressure - Math.Abs(warningRange)},{TargetPressure + Math.Abs(warningRange)}) in {warningTime:0} seconds");
  291. }
  292. }
  293. }
  294. public void Reset()
  295. {
  296. _trigProcessGauge.RST = true;
  297. _trigPressureGauge.RST = true;
  298. _trigForelineGauge.RST = true;
  299. if (_scAlarmTime != null)
  300. {
  301. _alarmChecker.Reset(_scAlarmTime.DoubleValue);
  302. }
  303. _alarmChecker.RST = true;
  304. _warningChecker.RST = true;
  305. _recipeWarningChecker.RST = true;
  306. _recipeAlarmChecker.RST = true;
  307. }
  308. }
  309. }