HongHuTM.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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 _VCESlitDoorOpenEnable;
  36. private readonly IoSensor _PMASlitDoorOpenEnable;
  37. private readonly IoSensor _PMBSlitDoorOpenEnable;
  38. private readonly IoSensor _PMCSlitDoorOpenEnable;
  39. private readonly IoSensor _VCESlitDoorCloseEnable;
  40. private readonly IoSensor _PMASlitDoorCloseEnable;
  41. private readonly IoSensor _PMBSlitDoorCloseEnable;
  42. private readonly IoSensor _PMCSlitDoorCloseEnable;
  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. //private readonly IoSensor _VCEATMSensor;
  50. //private readonly IoSensor _TMATMSensor;
  51. //控制门信号
  52. private readonly IoCylinder _VCESlitDoor;
  53. private readonly IoCylinder _PMASlitDoor;
  54. private readonly IoCylinder _PMBSlitDoor;
  55. private readonly IoCylinder _PMCSlitDoor;
  56. private readonly IoMfc _TMMfc;
  57. private readonly IoPressureMeter _TMPressure;
  58. //private readonly IoPressureMeter _TMPiplinePressure;
  59. private readonly IoPressureMeter _VCEPressure;
  60. //private readonly IoPressureMeter _VCEPiplinePressure;
  61. private readonly PumpBase _TMPump;
  62. //控压
  63. //安装的module
  64. private string _allInstalledModules { get { return SC.GetStringValue("System.InstalledModules").ToString(); } }
  65. #endregion
  66. #region 暴露变量
  67. //ATM VAC信号
  68. public bool IsTMATM => _TMPressure.Value >= SC.GetValue<double>($"{Module}.ATMTargetPressure");
  69. public bool IsVCEATM => _VCEPressure.Value >= SC.GetValue<double>("VCE1.ATMTargetPressure");
  70. public bool IsTMVAC => _TMVACSensor.Value;
  71. public bool IsVCEVAC => _VCEVACSensor.Value;
  72. public bool? IsTMPumpRunning => _TMPump?.IsRunning;
  73. //valve开关状态
  74. public bool IsTMFastPumpOpen => _TMFastPumpValve.Status;
  75. public bool IsTMSoftPumpOpen => _TMSoftPumpValve.Status;
  76. public bool IsTMFastVentOpen => _TMFastVentValve.Status;
  77. public bool IsTMSoftVentOpen => _TMSoftVentValve.Status;
  78. public bool IsVCEFastPumpOpen => _VCEFastPumpValve.Status;
  79. public bool IsVCESoftPumpOpen => _VCESoftPumpValve.Status;
  80. public bool IsVCEFastVentOpen => _VCEFastVentValve.Status;
  81. public bool IsVCESoftVentOpen => _VCESoftVentValve.Status;
  82. public bool IsTMVentValveOpen => IsTMFastVentOpen && IsTMSoftVentOpen;
  83. public bool IsVCEVentValveOpen => IsVCEFastVentOpen && IsVCESoftVentOpen;
  84. //SlitDoor
  85. public bool VCESlitDoorClosed => _VCESlitDoor.State == CylinderState.Close;
  86. public bool PMASlitDoorClosed
  87. {
  88. get
  89. {
  90. if (_allInstalledModules.Contains("PMA"))
  91. return _PMASlitDoor.State == CylinderState.Close;
  92. else
  93. return true;
  94. }
  95. }
  96. public bool PMBSlitDoorClosed
  97. {
  98. get
  99. {
  100. if (_allInstalledModules.Contains("PMB"))
  101. return _PMBSlitDoor.State == CylinderState.Close;
  102. else
  103. return true;
  104. }
  105. }
  106. public bool PMCSlitDoorClosed
  107. {
  108. get
  109. {
  110. if (_allInstalledModules.Contains("PMC"))
  111. return _PMCSlitDoor.State == CylinderState.Close;
  112. else
  113. return true;
  114. }
  115. }
  116. public bool VCESlitDoorOpen => _VCESlitDoor.State == CylinderState.Open;
  117. public bool PMASlitDoorOpen
  118. {
  119. get
  120. {
  121. if (_allInstalledModules.Contains("PMA"))
  122. return _PMASlitDoor.State == CylinderState.Open;
  123. else
  124. return true;
  125. }
  126. }
  127. public bool PMBSlitDoorOpen
  128. {
  129. get
  130. {
  131. if (_allInstalledModules.Contains("PMB"))
  132. return _PMBSlitDoor.State == CylinderState.Open;
  133. else
  134. return true;
  135. }
  136. }
  137. public bool PMCSlitDoorOpen
  138. {
  139. get
  140. {
  141. if (_allInstalledModules.Contains("PMC"))
  142. return _PMCSlitDoor.State == CylinderState.Open;
  143. else
  144. return true;
  145. }
  146. }
  147. public bool AllPMSlitDoorClosed
  148. {
  149. get
  150. {
  151. if (PMASlitDoorClosed && PMBSlitDoorClosed && PMCSlitDoorClosed)
  152. return true;
  153. else
  154. return false;
  155. }
  156. }
  157. public bool VCESlitDoorOpenEnable => _VCESlitDoorOpenEnable.Value;
  158. public bool PMASlitDoorOpenEnable => _PMASlitDoorOpenEnable.Value;
  159. public bool PMBSlitDoorOpenEnable => _PMBSlitDoorOpenEnable.Value;
  160. public bool PMCSlitDoorOpenEnable => _PMCSlitDoorOpenEnable.Value;
  161. public bool VCESlitDoorCloseEnable => _VCESlitDoorCloseEnable.Value;
  162. public bool PMASlitDoorCloseEnable => _PMASlitDoorCloseEnable.Value;
  163. public bool PMBSlitDoorCloseEnable => _PMBSlitDoorCloseEnable.Value;
  164. public bool PMCSlitDoorCloseEnable => _PMCSlitDoorCloseEnable.Value;
  165. //Robot动作
  166. public bool TMExtendVCEEnable => _TMExtendVCEEnable.Value;
  167. public bool TMExtendPMAEnable => _TMExtendPMAEnable.Value;
  168. public bool TMExtendPMBEnable => _TMExtendPMBEnable.Value;
  169. public bool TMExtendPMCEnable => _TMExtendPMCEnable.Value;
  170. public double TMPressure => _TMPressure.Value;
  171. public double VCEPressure => _VCEPressure.Value;
  172. enum PumpState
  173. {
  174. Idle,
  175. TMUsing,
  176. VCEUsing,
  177. }
  178. PumpState _PumpingState = PumpState.Idle;
  179. #endregion
  180. public HongHuTM() : base(ModuleName.SETM.ToString())
  181. {
  182. Module = ModuleName.SETM.ToString();
  183. _TMFastPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMFastPumpValve}");
  184. _TMSoftPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMSoftPumpValve}");
  185. _VCESoftPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCESoftPumpValve}");
  186. _VCEFastPumpValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCEFastPumpValve}");
  187. _TMFastVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMFastVentValve}");
  188. _TMSoftVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.TMSoftVentValve}");
  189. _VCESoftVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCESoftVentValve}");
  190. _VCEFastVentValve = DEVICE.GetDevice<IoValve>($"{Module}.{VenusDevice.VCEFastVentValve}");
  191. _VCESlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCESlitDoorOpenEnable}");
  192. _PMASlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMASlitDoorOpenEnable}");
  193. _PMBSlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMBSlitDoorOpenEnable}");
  194. _VCESlitDoorCloseEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCESlitDoorCloseEnable}");
  195. _PMASlitDoorCloseEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMASlitDoorCloseEnable}");
  196. _PMBSlitDoorCloseEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMBSlitDoorCloseEnable}");
  197. _TMVACSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMVACSensor}");
  198. _VCEVACSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCEVACSensor}");
  199. //_TMATMSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.TMATMSensor}");
  200. //_VCEATMSensor = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.VCEATMSensor}");
  201. _VCESlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.VCESlitDoor}");
  202. _PMASlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMASlitDoor}");
  203. _PMBSlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMBSlitDoor}");
  204. if (_allInstalledModules.Contains("PMC"))
  205. {
  206. _PMCSlitDoorOpenEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMCSlitDoorOpenEnable}");
  207. _PMCSlitDoor = DEVICE.GetDevice<IoCylinder>($"{Module}.{VenusDevice.PMCSlitDoor}");
  208. _PMCSlitDoorCloseEnable = DEVICE.GetDevice<IoSensor>($"{Module}.{VenusDevice.PMCSlitDoorCloseEnable}");
  209. }
  210. _TMMfc = DEVICE.GetDevice<IoMfc>($"{Module}.TM_MFC1");
  211. _TMPressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.TMPressure");
  212. //_TMPiplinePressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.TMPipelinePressure");
  213. _VCEPressure = DEVICE.GetDevice<IoPressureMeter>($"{Module}.VCEPressure");
  214. if (SC.GetValue<int>($"{Module}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  215. {
  216. if (SC.GetValue<int>($"{Module}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  217. {
  218. _TMPump = DEVICE.GetDevice<SkyPump>($"{Module}.{VenusDevice.MainPump}");
  219. }
  220. else if (SC.GetValue<int>($"{Module}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  221. {
  222. _TMPump = DEVICE.GetDevice<EdwardsPump>($"{Module}.{VenusDevice.MainPump}");
  223. }
  224. }
  225. DATA.Subscribe($"{Module}.VCESlitDoorClosed", () => VCESlitDoorClosed);
  226. DATA.Subscribe($"{Module}.PMASlitDoorClosed", () => PMASlitDoorClosed);
  227. DATA.Subscribe($"{Module}.PMBSlitDoorClosed", () => PMBSlitDoorClosed);
  228. DATA.Subscribe($"{Module}.PMCSlitDoorClosed", () => PMCSlitDoorClosed);
  229. DATA.Subscribe($"{Module}.PumpIsRunning", () => IsTMPumpRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  230. DATA.Subscribe($"{Module}.TMIsATM", ()=> IsTMATM);
  231. DATA.Subscribe($"{Module}.VCEIsATM", ()=> IsVCEATM);
  232. OP.Subscribe($"{Module}.ControlPump", (cmd, args) =>
  233. {
  234. _TMPump.SetPumpOnOff((bool)args[0]);
  235. return true;
  236. });
  237. OP.Subscribe($"{Module}.SetSlitDoor", (cmd, args) =>
  238. {
  239. var module = (ModuleName)Enum.Parse(typeof(ModuleName), args[0].ToString());
  240. return TurnSlitDoor(module, (bool)args[1]);
  241. });
  242. }
  243. #region IO控制方法
  244. //slitdoor
  245. //2023/11/1 增加两边压差比较
  246. public bool TurnSlitDoor(ModuleName mod, bool bOn)
  247. {
  248. double MaxPressureDifference = SC.GetValue<double>("System.PMTMMaxPressureDifference");
  249. switch (mod)
  250. {
  251. case ModuleName.VCE1:
  252. if (bOn && Math.Abs(_TMPressure.Value - _VCEPressure.Value)> MaxPressureDifference)
  253. {
  254. LOG.Write(eEvent.ERR_TM, ModuleName.SETM, $"cannot open door cause pressure, TM Pressure:{_TMPressure.Value} and VCE Pressure:{_VCEPressure.Value}");
  255. return false;
  256. }
  257. return _VCESlitDoor.SetCylinder(bOn, out _);
  258. case ModuleName.PMA:
  259. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  260. return false;
  261. return _PMASlitDoor.SetCylinder(bOn, out _);
  262. case ModuleName.PMB:
  263. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  264. return false;
  265. return _PMBSlitDoor.SetCylinder(bOn, out _);
  266. case ModuleName.PMC:
  267. if (bOn && !CanOpenSlitDoor(mod, MaxPressureDifference))
  268. return false;
  269. return _PMCSlitDoor.SetCylinder(bOn, out _);
  270. }
  271. return false;
  272. }
  273. //valve
  274. public void TurnFastPumpValve(ModuleName mod, bool bOn)
  275. {
  276. switch (mod)
  277. {
  278. case ModuleName.SETM:
  279. _TMFastPumpValve.TurnValve(bOn, out string _);
  280. break;
  281. case ModuleName.VCE1:
  282. _VCEFastPumpValve.TurnValve(bOn, out string _);
  283. break;
  284. }
  285. }
  286. public void TurnSoftPumpValve(ModuleName mod, bool bOn)
  287. {
  288. switch (mod)
  289. {
  290. case ModuleName.SETM:
  291. _TMSoftPumpValve.TurnValve(bOn, out string _);
  292. break;
  293. case ModuleName.VCE1:
  294. _VCESoftPumpValve.TurnValve(bOn, out string _);
  295. break;
  296. }
  297. }
  298. public void TurnFastVentValve(ModuleName mod, bool bOn)
  299. {
  300. switch (mod)
  301. {
  302. case ModuleName.SETM:
  303. _TMFastVentValve.TurnValve(bOn, out string _);
  304. break;
  305. case ModuleName.VCE1:
  306. _VCEFastVentValve.TurnValve(bOn, out string _);
  307. break;
  308. }
  309. }
  310. public void TurnSoftVentValve(ModuleName mod, bool bOn)
  311. {
  312. switch (mod)
  313. {
  314. case ModuleName.SETM:
  315. _TMSoftVentValve.TurnValve(bOn, out string _);
  316. break;
  317. case ModuleName.VCE1:
  318. _VCESoftVentValve.TurnValve(bOn, out string _);
  319. break;
  320. }
  321. }
  322. public bool CloseAllSlitDoor()
  323. {
  324. TurnSlitDoor(ModuleName.VCE1, false);
  325. if (_allInstalledModules.Contains("PMA"))
  326. TurnSlitDoor(ModuleName.PMA,false);
  327. if (_allInstalledModules.Contains("PMB"))
  328. TurnSlitDoor(ModuleName.PMB, false);
  329. if (_allInstalledModules.Contains("PMC"))
  330. TurnSlitDoor(ModuleName.PMC, false);
  331. return true;
  332. }
  333. public void HomeVceSlitDoor()
  334. {
  335. //由SlitDoor的状态对其下发同样的指令
  336. if (VCESlitDoorClosed == true)
  337. TurnSlitDoor(ModuleName.VCE1, false);
  338. else
  339. TurnSlitDoor(ModuleName.VCE1, true);
  340. }
  341. public void CloseVentValve()
  342. {
  343. _TMSoftVentValve.TurnValve(false, out _);
  344. _TMFastVentValve.TurnValve(false, out _);
  345. _VCESoftVentValve.TurnValve(false, out _);
  346. _VCEFastVentValve.TurnValve(false, out _);
  347. }
  348. public override bool CheckSlitValveOpen(ModuleName mod)
  349. {
  350. switch (mod)
  351. {
  352. case ModuleName.VCE1:
  353. return VCESlitDoorOpen;
  354. case ModuleName.PMA:
  355. return PMASlitDoorOpen;
  356. case ModuleName.PMB:
  357. return PMBSlitDoorOpen;
  358. case ModuleName.PMC:
  359. return PMCSlitDoorOpen;
  360. }
  361. return false;
  362. }
  363. public bool CheckPumpValveClosed(ModuleName mod)
  364. {
  365. switch (mod)
  366. {
  367. case ModuleName.SETM:
  368. return !IsTMFastPumpOpen && !IsTMSoftPumpOpen;
  369. case ModuleName.VCE1:
  370. return !IsVCEFastPumpOpen && !IsVCESoftPumpOpen;
  371. }
  372. return true;
  373. }
  374. public bool CheckVentValveClosed(ModuleName mod)
  375. {
  376. switch (mod)
  377. {
  378. case ModuleName.SETM:
  379. if (IsTMVentValveOpen)
  380. {
  381. LOG.Write(eEvent.ERR_TM, ModuleName.SETM, "TM Vent Valve not closed");
  382. return false;
  383. }
  384. break;
  385. case ModuleName.VCE1:
  386. if (IsVCEVentValveOpen)
  387. {
  388. LOG.Write(eEvent.ERR_TM, ModuleName.VCE1, "VCE1 Vent Valve not closed");
  389. return false;
  390. }
  391. break;
  392. }
  393. return true;
  394. }
  395. public void SetTMFlow(int flowValue)
  396. {
  397. _TMMfc.SetPoint = (flowValue);
  398. }
  399. public double GetModulePressure(ModuleName mod)
  400. {
  401. switch (mod)
  402. {
  403. case ModuleName.SETM:
  404. return TMPressure;
  405. case ModuleName.VCE1:
  406. return VCEPressure;
  407. }
  408. return 0.0;
  409. }
  410. public bool TryGetPump(ModuleName mod)
  411. {
  412. //Self
  413. if ((mod == ModuleName.VCE1 && _PumpingState == PumpState.VCEUsing) || (mod == ModuleName.SETM && _PumpingState == PumpState.TMUsing))
  414. return true;
  415. //Idle
  416. if (mod == ModuleName.SETM && !IsTMFastPumpOpen && !IsTMSoftPumpOpen && _PumpingState == PumpState.Idle)
  417. {
  418. _PumpingState = PumpState.TMUsing;
  419. return true;
  420. }
  421. if (mod == ModuleName.VCE1 && !IsVCEFastPumpOpen && !IsVCESoftPumpOpen && _PumpingState == PumpState.Idle)
  422. {
  423. _PumpingState = PumpState.VCEUsing;
  424. return true;
  425. }
  426. LOG.Write(eEvent.WARN_DEFAULT_WARN, mod, "无法打开,另一个泵正在用!");
  427. //locked
  428. return false;
  429. }
  430. public void ReleasePump(ModuleName Module)
  431. {
  432. //release pump (must do it by user)
  433. if ((Module == ModuleName.SETM && _PumpingState == PumpState.TMUsing) || (Module == ModuleName.VCE1 && _PumpingState == PumpState.VCEUsing))
  434. _PumpingState = PumpState.Idle;
  435. }
  436. #endregion
  437. #region 工具方法
  438. private bool CanOpenSlitDoor(ModuleName mod,double MaxPressureDifference)
  439. {
  440. if (Singleton<RouteManager>.Instance.GetPM(mod) == null || RouteManager.IsATMMode)
  441. return true;
  442. else
  443. {
  444. double PMPressure = Singleton<RouteManager>.Instance.GetPM(mod).ChamberPressure;
  445. if (Math.Abs(mbar2mtorrConvert(_TMPressure.Value) - PMPressure) <= MaxPressureDifference || (Singleton<RouteManager>.Instance.GetPM(mod).IsAtm && IsTMATM))
  446. {
  447. return true;
  448. }
  449. else
  450. {
  451. LOG.Write(eEvent.ERR_TM, ModuleName.SETM, $"cannot open door cause pressure, TM Pressure:{_TMPressure.Value} and {mod} pressure:{PMPressure}");
  452. return false;
  453. }
  454. }
  455. }
  456. private double mbar2mtorrConvert(double mbar) => mbar * 0.75 * 1000;
  457. #endregion
  458. }
  459. }