IoPressureControl.cs 9.3 KB

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