HongHuTM.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Device.Bases;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  12. using System;
  13. using IoMfc = Venus_RT.Devices.IODevices.IoMfc;
  14. using IoPressureMeter = Venus_RT.Devices.IODevices.IoPressureMeter;
  15. using Venus_Core;
  16. using Venus_RT.Modules;
  17. namespace Venus_RT.Devices
  18. {
  19. public class HongHuTM : TM
  20. {
  21. /// <summary>
  22. /// 针对VenusSE设计
  23. /// </summary>
  24. #region io 信号抽象
  25. //控制阀信号
  26. private readonly IoValve _TMFastPumpValve;
  27. private readonly IoValve _TMSoftPumpValve;
  28. private readonly IoValve _VCESoftPumpValve;
  29. private readonly IoValve _VCEFastPumpValve;
  30. private readonly IoValve _TMFastVentValve;
  31. private readonly IoValve _TMSoftVentValve;
  32. private readonly IoValve _VCESoftVentValve;
  33. private readonly IoValve _VCEFastVentValve;
  34. //判断信号
  35. private readonly IoSensor _VCESlitDoorOpen;
  36. private readonly IoSensor _PMASlitDoorOpen;
  37. private readonly IoSensor _PMBSlitDoorOpen;
  38. private readonly IoSensor _PMCSlitDoorOpen;
  39. private readonly IoSensor _VCESlitDoorOpenEnable;
  40. private readonly IoSensor _PMASlitDoorOpenEnable;
  41. private readonly IoSensor _PMBSlitDoorOpenEnable;
  42. private readonly IoSensor _PMCSlitDoorOpenEnable;
  43. private readonly IoSensor _TMExtendVCEEnable;
  44. private readonly IoSensor _TMExtendPMAEnable;
  45. private readonly IoSensor _TMExtendPMBEnable;
  46. private readonly IoSensor _TMExtendPMCEnable;
  47. private readonly IoSensor _TMVACSensor;
  48. private readonly IoSensor _VCEVACSensor;
  49. //控制门信号
  50. private readonly IoCylinder _VCESlitDoor;
  51. private readonly IoCylinder _PMASlitDoor;
  52. private readonly IoCylinder _PMBSlitDoor;
  53. private readonly IoCylinder _PMCSlitDoor;
  54. private readonly IoMfc _TMMfc;
  55. private readonly IoPressureMeter _TMPressure;
  56. private readonly IoPressureMeter _TMPiplinePressure;
  57. private readonly IoPressureMeter _VCEPressure;
  58. private readonly IoPressureMeter _VCEPiplinePressure;
  59. private readonly PumpBase _TMPump;
  60. //控压
  61. //安装的module
  62. private string _allInstalledModules { get { return SC.GetStringValue("System.InstalledModules").ToString(); } }
  63. #endregion
  64. #region 暴露变量
  65. //ATM VAC信号
  66. public bool IsTMATM => _TMPressure.Value >= SC.GetValue<double>($"{Module}.ATMTargetPressure");
  67. public bool IsVCEATM => _VCEPressure.Value >= SC.GetValue<double>("VCE1.ATMTargetPressure");
  68. public bool IsTMVAC => _TMVACSensor.Value;
  69. public bool IsVCEVAC => _VCEVACSensor.Value;
  70. public bool? IsTMPumpRunning => _TMPump?.IsRunning;
  71. //valve开关状态
  72. public bool IsTMFastPumpOpen => _TMFastPumpValve.Status;
  73. public bool IsTMSoftPumpOpen => _TMSoftPumpValve.Status;
  74. public bool IsTMFastVentOpen => _TMFastVentValve.Status;
  75. public bool IsTMSoftVentOpen => _TMSoftVentValve.Status;
  76. public bool IsVCEFastPumpOpen => _VCEFastPumpValve.Status;
  77. public bool IsVCESoftPumpOpen => _VCESoftPumpValve.Status;
  78. public bool IsVCEFastVentOpen => _VCEFastVentValve.Status;
  79. public bool IsVCESoftVentOpen => _VCESoftVentValve.Status;
  80. public bool IsTMVentValveOpen => IsTMFastVentOpen && IsTMSoftVentOpen;
  81. public bool IsVCEVentValveOpen => IsVCEFastVentOpen && IsVCESoftVentOpen;
  82. //SlitDoor
  83. public bool VCESlitDoorClosed => _VCESlitDoor.State == CylinderState.Close;
  84. public bool PMASlitDoorClosed
  85. {
  86. get
  87. {
  88. if (_allInstalledModules.Contains("PMA"))
  89. return _PMASlitDoor.State == CylinderState.Close;
  90. else
  91. return true;
  92. }
  93. }
  94. public bool PMBSlitDoorClosed
  95. {
  96. get
  97. {
  98. if (_allInstalledModules.Contains("PMB"))
  99. return _PMBSlitDoor.State == CylinderState.Close;
  100. else
  101. return true;
  102. }
  103. }
  104. public bool PMCSlitDoorClosed
  105. {
  106. get
  107. {
  108. if (_allInstalledModules.Contains("PMC"))
  109. return _PMCSlitDoor.State == CylinderState.Close;
  110. else
  111. return true;
  112. }
  113. }
  114. public bool AllPMSlitDoorClosed
  115. {
  116. get
  117. {
  118. if (PMASlitDoorClosed && PMBSlitDoorClosed && PMCSlitDoorClosed)
  119. return true;
  120. else
  121. return false;
  122. }
  123. }
  124. public bool VCESlitDoorOpenEnable => _VCESlitDoorOpenEnable.Value;
  125. public bool PMASlitDoorOpenEnable => _PMASlitDoorOpenEnable.Value;
  126. public bool PMBSlitDoorOpenEnable => _PMBSlitDoorOpenEnable.Value;
  127. public bool PMCSlitDoorOpenEnable => _PMCSlitDoorOpenEnable.Value;
  128. //Robot动作
  129. public bool TMExtendVCEEnable => _TMExtendVCEEnable.Value;
  130. public bool TMExtendPMAEnable => _TMExtendPMAEnable.Value;
  131. public bool TMExtendPMBEnable => _TMExtendPMBEnable.Value;
  132. public bool TMExtendPMCEnable => _TMExtendPMCEnable.Value;
  133. public double TMPressure => _TMPressure.Value;
  134. public double VCEPressure => _VCEPressure.Value;
  135. enum PumpState
  136. {
  137. Idle,
  138. TMUsing,
  139. VCEUsing,
  140. }
  141. PumpState _PumpingState = PumpState.Idle;
  142. #endregion
  143. public HongHuTM() : base(ModuleName.SETM.ToString())
  144. {
  145. Module = ModuleName.SETM.ToString();
  146. _TMFastPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMFastPumpValve}");
  147. _TMSoftPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMSoftPumpValve}");
  148. _VCESoftPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCESoftPumpValve}");
  149. _VCEFastPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCEFastPumpValve}");
  150. _TMFastVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMFastVentValve}");
  151. _TMSoftVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMSoftVentValve}");
  152. _VCESoftVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCESoftVentValve}");
  153. _VCEFastVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCEFastVentValve}");
  154. _VCESlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCESlitDoorOpenEnable}");
  155. _PMASlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMASlitDoorOpenEnable}");
  156. _PMBSlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMBSlitDoorOpenEnable}");
  157. _PMCSlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMCSlitDoorOpenEnable}");
  158. _TMExtendVCEEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMExtendVCEEnable}");
  159. _TMExtendPMAEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMExtendPMAEnable}");
  160. _TMExtendPMBEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMExtendPMBEnable}");
  161. _TMExtendPMCEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMExtendPMCEnable}");
  162. _TMVACSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMVACSensor}");
  163. _VCEVACSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCEVACSensor}");
  164. _VCESlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.VCESlitDoor}");
  165. _PMASlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMASlitDoor}");
  166. _PMBSlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMBSlitDoor}");
  167. _PMCSlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMCSlitDoor}");
  168. _TMMfc = DEVICE.GetDevice<IoMfc>($"{Module}.TM_MFC1");
  169. _TMPressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.TMPressure");
  170. _TMPiplinePressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.TMPipelinePressure");
  171. _VCEPressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.VCEPressure");
  172. _VCEPiplinePressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.VCEPipelinePressure");
  173. if (SC.GetValue<int>($"{Module}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  174. {
  175. if (SC.GetValue<int>($"{Module}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  176. {
  177. _TMPump = DEVICE.GetDevice<SkyPump>($"{Module}.{VenusDevice.MainPump}");
  178. }
  179. else if (SC.GetValue<int>($"{Module}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  180. {
  181. _TMPump = DEVICE.GetDevice<EdwardsPump>($"{Module}.{VenusDevice.MainPump}");
  182. }
  183. }
  184. DATA.Subscribe($"{Module}.VCESlitDoorClosed", () => VCESlitDoorClosed);
  185. DATA.Subscribe($"{Module}.PMASlitDoorClosed", () => PMASlitDoorClosed);
  186. DATA.Subscribe($"{Module}.PMBSlitDoorClosed", () => PMBSlitDoorClosed);
  187. DATA.Subscribe($"{Module}.PMCSlitDoorClosed", () => PMCSlitDoorClosed);
  188. DATA.Subscribe($"{Module}.PumpIsRunning", () => IsTMPumpRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  189. DATA.Subscribe($"{Module}.TMIsATM", ()=> IsTMATM);
  190. DATA.Subscribe($"{Module}.VCEIsATM", ()=> IsVCEATM);
  191. OP.Subscribe($"{Module}.ControlPump", (cmd, args) =>
  192. {
  193. _TMPump.SetPumpOnOff((bool)args[0]);
  194. return true;
  195. });
  196. OP.Subscribe($"{Module}.SetSlitDoor", (cmd, args) =>
  197. {
  198. var module = (ModuleName)Enum.Parse(typeof(ModuleName), args[0].ToString());
  199. return TurnSlitDoor(module, (bool)args[1]);
  200. });
  201. }
  202. #region IO控制方法
  203. //slitdoor
  204. //2023/11/1 增加两边压差比较
  205. public bool TurnSlitDoor(ModuleName mod, bool bOn)
  206. {
  207. double MaxPressureDifference = SC.GetValue<double>("System.PMTMMaxPressureDifference");
  208. switch (mod)
  209. {
  210. case ModuleName.VCE1:
  211. if (bOn && Math.Abs(_TMPressure.Value - _VCEPressure.Value)> MaxPressureDifference)
  212. {
  213. LOG.Write(eEvent.ERR_TM, ModuleName.SETM, $"cannot open door cause pressure, TM Pressure:{_TMPressure.Value} and VCE Pressure:{_VCEPressure.Value}");
  214. return false;
  215. }
  216. return _VCESlitDoor.SetCylinder(bOn, out _);
  217. case ModuleName.PMA:
  218. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  219. return false;
  220. return _PMASlitDoor.SetCylinder(bOn, out _);
  221. case ModuleName.PMB:
  222. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  223. return false;
  224. return _PMBSlitDoor.SetCylinder(bOn, out _);
  225. case ModuleName.PMC:
  226. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  227. return false;
  228. return _PMCSlitDoor.SetCylinder(bOn, out _);
  229. }
  230. return false;
  231. }
  232. //valve
  233. public void TurnFastPumpValve(ModuleName mod, bool bOn)
  234. {
  235. switch (mod)
  236. {
  237. case ModuleName.SETM:
  238. _TMFastPumpValve.TurnValve(bOn, out string _);
  239. break;
  240. case ModuleName.VCE1:
  241. _VCEFastPumpValve.TurnValve(bOn, out string _);
  242. break;
  243. }
  244. }
  245. public void TurnSoftPumpValve(ModuleName mod, bool bOn)
  246. {
  247. switch (mod)
  248. {
  249. case ModuleName.SETM:
  250. _TMSoftPumpValve.TurnValve(bOn, out string _);
  251. break;
  252. case ModuleName.VCE1:
  253. _VCESoftPumpValve.TurnValve(bOn, out string _);
  254. break;
  255. }
  256. }
  257. public void TurnFastVentValve(ModuleName mod, bool bOn)
  258. {
  259. switch (mod)
  260. {
  261. case ModuleName.SETM:
  262. _TMFastVentValve.TurnValve(bOn, out string _);
  263. break;
  264. case ModuleName.VCE1:
  265. _VCEFastVentValve.TurnValve(bOn, out string _);
  266. break;
  267. }
  268. }
  269. public void TurnSoftVentValve(ModuleName mod, bool bOn)
  270. {
  271. switch (mod)
  272. {
  273. case ModuleName.SETM:
  274. _TMSoftVentValve.TurnValve(bOn, out string _);
  275. break;
  276. case ModuleName.VCE1:
  277. _VCESoftVentValve.TurnValve(bOn, out string _);
  278. break;
  279. }
  280. }
  281. public bool CloseAllSlitDoor()
  282. {
  283. _VCESlitDoor.SetCylinder(false, out _);
  284. if (_allInstalledModules.Contains("PMA"))
  285. _PMASlitDoor.SetCylinder(false, out _);
  286. if (_allInstalledModules.Contains("PMB"))
  287. _PMBSlitDoor.SetCylinder(false, out _);
  288. if (_allInstalledModules.Contains("PMC"))
  289. _PMCSlitDoor.SetCylinder(false, out _);
  290. return true;
  291. }
  292. public void HomeVceSlitDoor()
  293. {
  294. //由SlitDoor的状态对其下发同样的指令
  295. if (VCESlitDoorClosed == true)
  296. _VCESlitDoor.SetCylinder(false, out _);
  297. else
  298. _VCESlitDoor.SetCylinder(true, out _);
  299. }
  300. public void CloseVentValve()
  301. {
  302. _TMSoftVentValve.TurnValve(false, out _);
  303. _TMFastVentValve.TurnValve(false, out _);
  304. _VCESoftVentValve.TurnValve(false, out _);
  305. _VCEFastVentValve.TurnValve(false, out _);
  306. }
  307. public bool CheckPumpValveClosed(ModuleName mod)
  308. {
  309. switch (mod)
  310. {
  311. case ModuleName.SETM:
  312. return !IsTMFastPumpOpen && !IsTMSoftPumpOpen;
  313. case ModuleName.VCE1:
  314. return !IsVCEFastPumpOpen && !IsVCESoftPumpOpen;
  315. }
  316. return true;
  317. }
  318. public bool CheckVentValveClosed(ModuleName mod)
  319. {
  320. switch (mod)
  321. {
  322. case ModuleName.SETM:
  323. if (IsTMVentValveOpen)
  324. {
  325. LOG.Write(eEvent.ERR_TM, ModuleName.SETM, "TM Vent Valve not closed");
  326. return false;
  327. }
  328. break;
  329. case ModuleName.VCE1:
  330. if (IsVCEVentValveOpen)
  331. {
  332. LOG.Write(eEvent.ERR_TM, ModuleName.VCE1, "VCE1 Vent Valve not closed");
  333. return false;
  334. }
  335. break;
  336. }
  337. return true;
  338. }
  339. public void SetTMFlow(int flowValue)
  340. {
  341. _TMMfc.SetPoint = (flowValue);
  342. }
  343. public double GetModulePressure(ModuleName mod)
  344. {
  345. switch (mod)
  346. {
  347. case ModuleName.SETM:
  348. return TMPressure;
  349. case ModuleName.VCE1:
  350. return VCEPressure;
  351. }
  352. return 0.0;
  353. }
  354. public bool TryGetPump(ModuleName mod)
  355. {
  356. //Self
  357. if ((mod == ModuleName.VCE1 && _PumpingState == PumpState.VCEUsing) || (mod == ModuleName.SETM && _PumpingState == PumpState.TMUsing))
  358. return true;
  359. //Idle
  360. if (mod == ModuleName.SETM && !IsTMFastPumpOpen && !IsTMSoftPumpOpen && _PumpingState == PumpState.Idle)
  361. {
  362. _PumpingState = PumpState.TMUsing;
  363. return true;
  364. }
  365. if (mod == ModuleName.VCE1 && !IsVCEFastPumpOpen && !IsVCESoftPumpOpen && _PumpingState == PumpState.Idle)
  366. {
  367. _PumpingState = PumpState.VCEUsing;
  368. return true;
  369. }
  370. LOG.Write(eEvent.WARN_DEFAULT_WARN, mod, "无法打开,另一个泵正在用!");
  371. //locked
  372. return false;
  373. }
  374. public void ReleasePump(ModuleName Module)
  375. {
  376. //release pump (must do it by user)
  377. if ((Module == ModuleName.SETM && _PumpingState == PumpState.TMUsing) || (Module == ModuleName.VCE1 && _PumpingState == PumpState.VCEUsing))
  378. _PumpingState = PumpState.Idle;
  379. }
  380. #endregion
  381. #region 工具方法
  382. private bool CanOpenSlitDoor(ModuleName mod,double MaxPressureDifference)
  383. {
  384. if (Singleton<RouteManager>.Instance.GetPM(mod) == null || RouteManager.IsATMMode)
  385. return true;
  386. else
  387. {
  388. double PMPressure = Singleton<RouteManager>.Instance.GetPM(mod).ChamberPressure;
  389. if (Math.Abs(_TMPressure.Value - PMPressure) > MaxPressureDifference)
  390. {
  391. LOG.Write(eEvent.ERR_TM, $"cannot open door cause pressure, TM Pressure:{_TMPressure.Value} and {mod} pressure:{PMPressure}");
  392. return false;
  393. }
  394. else
  395. return true;
  396. }
  397. }
  398. #endregion
  399. }
  400. }