IoPressureControl.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. // Constructor
  90. //
  91. public IoPressureControl(string module, XmlElement node, string ioModule = "")
  92. {
  93. base.Module = module;
  94. base.Name = node.GetAttribute("id");
  95. base.Display = node.GetAttribute("display");
  96. base.DeviceID = node.GetAttribute("schematicId");
  97. _diLogicProcessGasFlowing = ParseDiNode("diLogicProcessGasFlowing", node, ioModule);
  98. _scAlarmRange = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmRange");
  99. _scAlarmTime = SC.GetConfigItem($"{Module}.GasFlowPressureAlarmTime");
  100. _scIsIndependentControl = SC.GetConfigItem($"{Module}.IsIndependentControl");
  101. _scIsBoostPumpInstalled = SC.GetConfigItem($"{Module}.EnableBoosterPump");
  102. _scTvInstalled = SC.GetConfigItem($"{Module}.EnableThrottleValve");
  103. //_enableTolerance = true;
  104. ThrottleValve = ParseDeviceNode<IoThrottleValve>(Module, "tv", node);
  105. PressureGauge = ParseDeviceNode<IoPressureMeter>(Module, "pressureMeter", node);
  106. ProcessGauge = ParseDeviceNode<IoPressureMeter>(Module, "processMeter", node);
  107. ForelineGauge = ParseDeviceNode<IoPressureMeter>(Module, "forelineMeter", node);
  108. //DryPump = ParseDeviceNode<IoPump>(Module, "drypump", node);
  109. }
  110. public bool Initialize()
  111. {
  112. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", _setTVPressure);
  113. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", _setTVPosition);
  114. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", _setTVMode);
  115. //DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetBoostPressure}", _setBoostPressure);
  116. DEVICE.Register($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", _setChamberPressure);
  117. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetChamberPressure}", (out string reason, int time, object[] param) =>
  118. {
  119. _setChamberPressure(out reason, 0, param);
  120. return true;
  121. });
  122. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVMode}", (out string reason, int time, object[] param) =>
  123. {
  124. _setTVMode(out reason, 0, param);
  125. return true;
  126. });
  127. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPressure}", (out string reason, int time, object[] param) =>
  128. {
  129. _setTVPressure(out reason, 0, param);
  130. return true;
  131. });
  132. OP.Subscribe($"{Module}.{Name}.{AITPressureControlOperation.SetTVPosition}", (out string reason, int time, object[] param) =>
  133. {
  134. _setTVPosition(out reason, 0, param);
  135. return true;
  136. });
  137. return true;
  138. }
  139. //public void StartPump(bool on)
  140. //{
  141. // this.DryPump?.Start(on);
  142. //}
  143. public void FullOpenThrottleValve()
  144. {
  145. this.ThrottleValve.PressureMode = PressureCtrlMode.TVPositionCtrl;
  146. this.ThrottleValve.PositionSetpoint = 100;
  147. }
  148. private bool? _setTVPressure(out string reason, int time, object[] param)
  149. {
  150. double target = Convert.ToDouble((string)param[0]);
  151. if (!IsTvInstalled)
  152. {
  153. reason = "Throttle valve not config";
  154. return true;
  155. }
  156. if (ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)
  157. {
  158. reason = "Throttle valve is in position control mode, can not set pressure";
  159. return false;
  160. }
  161. ThrottleValve.PressureSetpoint = (short)target;
  162. ThrottleValve.PositionSetpoint = 0.0f;
  163. reason = $"TV pressure set to {target} mTorr";
  164. return true;
  165. }
  166. private bool? _setTVPosition(out string reason, int time, object[] param)
  167. {
  168. double target = Convert.ToDouble((string)param[0]);
  169. if (!IsTvInstalled)
  170. {
  171. reason = "Throttle valve not config";
  172. return true;
  173. }
  174. if (ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)
  175. {
  176. reason = "Throttle valve is in pressure control mode, can not set position";
  177. return false;
  178. }
  179. ThrottleValve.PressureSetpoint = 0.0f;
  180. ThrottleValve.PositionSetpoint = (short)target;
  181. reason = $"TV position set to {target}";
  182. return true;
  183. }
  184. private bool? _setTVMode(out string reason, int time, object[] param)
  185. {
  186. reason = string.Empty;
  187. if (!IsTvInstalled)
  188. {
  189. reason = "Throttle valve not config";
  190. return true;
  191. }
  192. ThrottleValve.PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);
  193. reason = $"TV mode set to {ThrottleValve.PressureMode}";
  194. return true;
  195. }
  196. private bool? _setChamberPressure(out string reason, int time, object[] param)
  197. {
  198. double setpoint = Convert.ToDouble((string)param[0]);
  199. TargetPressure = setpoint;
  200. reason = $"Chamber pressure set to {setpoint} mTorr";
  201. return true;
  202. }
  203. public void Terminate()
  204. {
  205. }
  206. public void Monitor()
  207. {
  208. CheckTolerance();
  209. _trigProcessGauge.CLK = ProcessGauge.GaugeAlarm;
  210. if (_trigProcessGauge.Q) EV.PostAlarmLog(Module, "Process pressure gauge Alarm");
  211. _trigPressureGauge.CLK = PressureGauge.GaugeAlarm;
  212. if (_trigPressureGauge.Q) EV.PostAlarmLog(Module, "Chamber pressure gauge Alarm");
  213. _trigForelineGauge.CLK = ForelineGauge.GaugeAlarm;
  214. if (_trigForelineGauge.Q) EV.PostAlarmLog(Module, "Foreline pressure gauge Alarm");
  215. }
  216. public void CheckTolerance()
  217. {
  218. if (!EnableTolerance)
  219. return;
  220. if (ThrottleValve != null && IsTvInstalled && ThrottleValve.PressureMode == PressureCtrlMode.TVPositionCtrl)
  221. return;
  222. _tolerance.Monitor(PressureGauge.Value,
  223. TargetPressure - Math.Abs(_scAlarmRange.DoubleValue),
  224. TargetPressure + Math.Abs(_scAlarmRange.DoubleValue), _scAlarmTime.DoubleValue);
  225. if (_tolerance.Trig)
  226. {
  227. //EV.PostMessage(Module.ToString(), EventEnum.ProcessPressureToleranceAlarm, Module, Display,
  228. // );
  229. EV.PostAlarmLog(Module, $"Gas Flow Pressure Alarm Out of range in {_scAlarmTime.Value:0} seconds");
  230. }
  231. }
  232. public void Reset()
  233. {
  234. _trigProcessGauge.RST = true;
  235. _trigPressureGauge.RST = true;
  236. _trigForelineGauge.RST = true;
  237. if (_scAlarmTime != null)
  238. {
  239. _tolerance.Reset(_scAlarmTime.DoubleValue);
  240. }
  241. }
  242. }
  243. }