IoPressureControl.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.RT.Tolerance;
  8. using Aitex.Platform;
  9. namespace Aitex.Core.RT.Device.Unit
  10. {
  11. public class IoPressureControl : BaseDevice, IDevice
  12. {
  13. private bool _enableTolerance;
  14. public bool EnableTolerance
  15. {
  16. get
  17. {
  18. return _enableTolerance;
  19. }
  20. set
  21. {
  22. if (_enableTolerance != value)
  23. {
  24. EV.PostMessage(Module, EventEnum.GeneralInfo, value ? "Start monitor pressure stability" : "Stop monitor pressure stability");
  25. if (value)
  26. {
  27. _tolerance.Reset(_scAlarmTime.Value);
  28. }
  29. }
  30. _enableTolerance = value;
  31. }
  32. }
  33. public bool IsIndependentControl
  34. {
  35. get
  36. {
  37. if (_scIsIndependentControl != null)
  38. return _scIsIndependentControl.Value;
  39. return false;
  40. }
  41. }
  42. public bool IsTvInstalled
  43. {
  44. get
  45. {
  46. if (_scTvInstalled != null)
  47. return _scTvInstalled.Value;
  48. return false;
  49. }
  50. }
  51. public bool IsBoostPumpInstalled
  52. {
  53. get
  54. {
  55. if (_scIsBoostPumpInstalled != null)
  56. return _scIsBoostPumpInstalled.Value;
  57. return false;
  58. }
  59. }
  60. public bool EnableBoostControl
  61. {
  62. get
  63. {
  64. return _diLogicProcessGasFlowing == null || _diLogicProcessGasFlowing.Value;
  65. }
  66. }
  67. private IoThrottleValve _tv;
  68. private IoPressureMeter _pressureMeter;
  69. private IoBoostPump _boost;
  70. private double _pressureSetPoint;
  71. private ToleranceChecker _tolerance = new ToleranceChecker();
  72. private SCItem<double> _scAlarmRange = null;
  73. private SCItem<double> _scAlarmTime = null;
  74. private SCItem<bool> _scIsIndependentControl = null;
  75. private SCItem<bool> _scIsBoostPumpInstalled = null;
  76. private SCItem<bool> _scTvInstalled = null;
  77. private DIAccessor _diLogicProcessGasFlowing;
  78. public IoPressureControl(string module, XmlElement node)
  79. {
  80. base.Module = module;
  81. base.Name = node.GetAttribute("id");
  82. base.Display = node.GetAttribute("display");
  83. base.DeviceID = node.GetAttribute("schematicId");
  84. _diLogicProcessGasFlowing = ParseDiNode("diLogicProcessGasFlowing", node);
  85. _scAlarmRange = ParseScNodeDouble("scGasFlowPressureAlarmRange", node);
  86. _scAlarmTime = ParseScNodeDouble("scGasFlowPressureAlarmTime", node);
  87. _scIsIndependentControl = ParseScNodeBool("scIsIndependentControl", node);
  88. _scIsBoostPumpInstalled = ParseScNodeBool("scIsBoostPumpInstalled", node);
  89. _scTvInstalled = ParseScNodeBool("scTvInstalled", node);
  90. _tv = ParseDeviceNode<IoThrottleValve>("tv", node);
  91. _pressureMeter = ParseDeviceNode<IoPressureMeter>("pressureMeter", node);
  92. _boost = ParseDeviceNode<IoBoostPump>("boost", node);
  93. }
  94. public bool Initialize()
  95. {
  96. DEVICE.Register(String.Format("{0}.{1}", Name, AITPressureControlOperation.SetTVPressure), (out string reason, int time, object[] param) =>
  97. {
  98. double target = Convert.ToDouble((string)param[0]);
  99. if (!IsTvInstalled)
  100. {
  101. reason = string.Format("Throttle valve not config");
  102. return true;
  103. }
  104. if (_tv.PressureMode == PressureCtrlMode.TVPositionCtrl)
  105. {
  106. reason = "Throttle valve is in positon conrol mode, can not set pressure";
  107. return false;
  108. }
  109. _tv.PressureSetpoint = (float)target;
  110. reason = string.Format("TV pressure set to {0} mtorr", target);
  111. return true;
  112. });
  113. DEVICE.Register(String.Format("{0}.{1}", Name, AITPressureControlOperation.SetTVPosition), (out string reason, int time, object[] param) =>
  114. {
  115. double target = Convert.ToDouble((string)param[0]);
  116. if (!IsTvInstalled)
  117. {
  118. reason = string.Format("Throttle valve not config");
  119. return true;
  120. }
  121. if (_tv.PressureMode == PressureCtrlMode.TVPressureCtrl)
  122. {
  123. reason = "Throttle valve is in pressure conrol mode, can not set position";
  124. return false;
  125. }
  126. _tv.PositionSetpoint = (float)target;
  127. reason = string.Format("TV position set to {0}", target);
  128. return true;
  129. });
  130. DEVICE.Register(String.Format("{0}.{1}", Name, AITPressureControlOperation.SetTVMode), (out string reason, int time, object[] param) =>
  131. {
  132. reason = string.Empty;
  133. if (!IsTvInstalled)
  134. {
  135. reason = string.Format("Throttle valve not config");
  136. return true;
  137. }
  138. _tv.PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);
  139. reason = string.Format("TV mode set to {0}", _tv.PressureMode);
  140. return true;
  141. });
  142. DEVICE.Register(String.Format("{0}.{1}", Name, AITPressureControlOperation.SetBoostPressure), (out string reason, int time, object[] param) =>
  143. {
  144. if (!IsBoostPumpInstalled)
  145. {
  146. reason = string.Format("boost pump not set up");
  147. return false;
  148. }
  149. double setpoint = Convert.ToDouble((string)param[0]);
  150. if (!_boost.SetPressure(setpoint, out reason))
  151. {
  152. return false;
  153. }
  154. _pressureSetPoint = setpoint;
  155. reason = string.Format("Boost pump pressure set to {0} mTorr", setpoint);
  156. return true;
  157. });
  158. DEVICE.Register(String.Format("{0}.{1}", Name, AITPressureControlOperation.SetChamberPressure), (out string reason, int time, object[] param) =>
  159. {
  160. double setpoint = Convert.ToDouble((string)param[0]);
  161. _pressureSetPoint = setpoint;
  162. reason = string.Format("Chamber pressure set to {0} mTorr", setpoint);
  163. return true;
  164. });
  165. return true;
  166. }
  167. public void Terminate()
  168. {
  169. }
  170. public void Monitor()
  171. {
  172. CheckTolerance();
  173. if (_boost != null && IsBoostPumpInstalled)
  174. {
  175. _boost.SetEnable((IsIndependentControl && EnableBoostControl) ? (int) BoostPumpEnable.Enable : (int) BoostPumpEnable.Disable);
  176. }
  177. }
  178. public void CheckTolerance()
  179. {
  180. if (!EnableTolerance)
  181. return;
  182. if (_tv!=null && IsTvInstalled && _tv.PressureMode == PressureCtrlMode.TVPositionCtrl)
  183. return;
  184. _tolerance.Monitor(_pressureMeter.Value, _pressureSetPoint - Math.Abs(_scAlarmRange.Value), _pressureSetPoint + Math.Abs(_scAlarmRange.Value), _scAlarmTime.Value);
  185. if (_tolerance.Trig)
  186. {
  187. EV.PostMessage(Module, EventEnum.ProcessPressureToleranceAlarm, Module, Display,
  188. String.Format("Out of range in {0} seconds", _scAlarmTime.Value.ToString("0")));
  189. }
  190. }
  191. public void Reset()
  192. {
  193. _tolerance.Reset(_scAlarmTime.Value);
  194. }
  195. }
  196. }