HongHuTM.cs 17 KB

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