DeviceManager.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.RT.Device.Custom;
  9. using MECF.Framework.Common.Equipment;
  10. using Venus_RT.Modules;
  11. using Venus_RT.Devices;
  12. using Venus_RT.Devices.EPD;
  13. using Venus_Core;
  14. using Aitex.Common.Util;
  15. using System.Reflection;
  16. using Venus_RT.Devices.AdLinkEthercat;
  17. using System.Windows;
  18. using Aitex.Core.RT.Log;
  19. namespace Venus_RT.Instances
  20. {
  21. public class DeviceEntity : DeviceEntityT<DeviceManager>
  22. {
  23. public DeviceEntity()
  24. {
  25. }
  26. }
  27. public class DeviceManager : DeviceManagerBase
  28. {
  29. private string device_model_file;
  30. private readonly string device_model_file_MF;
  31. private readonly string device_model_file_SEMF;
  32. Int32 v_board_id = -1;
  33. Int32 v_StartAxisID = 0;
  34. Int32 BUS_No = 0;
  35. private bool startEthercatOK;
  36. public DeviceManager()
  37. {
  38. device_model_file_MF = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config\\", "TM", RtInstance.DeviceModelFileName_MF);
  39. device_model_file_SEMF = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config\\", "TM", RtInstance.DeviceModelFileName_SE);
  40. }
  41. public bool InitEthercat()
  42. {
  43. Int32 boardID_InBits = 0;
  44. Int32 mode = 0;
  45. Int32 ret = 0;
  46. Int32 card_name = 0;
  47. Int32 tamp = 0;
  48. Int32 StartAxisID = 0;
  49. Int32 TotalAxisNum = 0;
  50. // Card(Board) initial
  51. ret = APS168.APS_initial(ref boardID_InBits, mode);
  52. if (ret == 0)
  53. {
  54. for (int i = 0; i < 16; i++)
  55. {
  56. tamp = (boardID_InBits >> i) & 1;
  57. if (tamp == 1)
  58. {
  59. ret = APS168.APS_get_card_name(i, ref card_name);
  60. if ((card_name >= (Int32)APS_Define.DEVICE_NAME_EM_2P00)
  61. && (card_name <= (Int32)APS_Define.DEVICE_NAME_EM_FA00))
  62. {
  63. ret = APS168.APS_get_first_axisId(i, ref StartAxisID, ref TotalAxisNum);
  64. //v_card_name = card_name;
  65. v_board_id = i;
  66. v_StartAxisID = StartAxisID;
  67. LOG.Write(eEvent.EV_DEVICE_INFO, ModuleName.System, "Ethercat Initial Success!");
  68. break;
  69. }
  70. }
  71. }
  72. if (v_board_id == -1)
  73. {
  74. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.System, $"Ethercat Board Id search Fail!");
  75. }
  76. else
  77. {
  78. LOG.Write(eEvent.EV_DEVICE_INFO, ModuleName.System, "Ethercat Board Id search Success!");
  79. return true;
  80. }
  81. }
  82. else
  83. {
  84. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.System, $"Ethercat Initial Fail!");
  85. }
  86. return false;
  87. }
  88. public bool StarteEthercat()
  89. {
  90. Int32 ret = 0;
  91. Int32 Board_ID = v_board_id;
  92. ret = APS168.APS_start_field_bus(Board_ID, BUS_No, v_StartAxisID);
  93. if (ret != 0)
  94. {
  95. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.System, $"Ethercat Start field bus Fail");
  96. return false;
  97. }
  98. else
  99. {
  100. LOG.Write(eEvent.EV_DEVICE_INFO, ModuleName.System, $"Ethercat Start field bus Success");
  101. return true;
  102. }
  103. }
  104. public override bool Initialize()
  105. {
  106. if (SC.GetValue<bool>("System.IsEnableEthercat"))
  107. {
  108. if (InitEthercat())
  109. {
  110. if (StarteEthercat())
  111. {
  112. startEthercatOK = true;
  113. }
  114. }
  115. }
  116. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  117. {
  118. JetChamber jetChamber = (JetChamber)SC.GetValue<int>("PMA.ChamberType");
  119. InitPM(ModuleName.PMA, jetChamber);
  120. }
  121. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  122. {
  123. JetChamber jetChamber = (JetChamber)SC.GetValue<int>("PMB.ChamberType");
  124. InitPM(ModuleName.PMB, jetChamber);
  125. }
  126. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  127. {
  128. JetChamber jetChamber = (JetChamber)SC.GetValue<int>("PMC.ChamberType");
  129. InitPM(ModuleName.PMC, jetChamber);
  130. }
  131. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  132. {
  133. JetChamber jetChamber = (JetChamber)SC.GetValue<int>("PMD.ChamberType");
  134. InitPM(ModuleName.PMD, jetChamber);
  135. }
  136. if (ModuleHelper.IsInstalled(ModuleName.TM))
  137. InitTM(ModuleName.TM);
  138. if (ModuleHelper.IsInstalled(ModuleName.SETM))
  139. {
  140. InitSETM(ModuleName.SETM);
  141. }
  142. AddCustomModuleDevice(new VenusSignalTower("System", "SignalTower"));
  143. OP.Subscribe("DeviceOperation", this.Invoke);
  144. return true;
  145. }
  146. private void InitPM(ModuleName mod, JetChamber jetChamber)
  147. {
  148. device_model_file = PathManager.GetCfgDir() + "PM" + "\\" + jetChamber.ToString() + "\\" + $"{jetChamber.ToString()}DeviceModel.xml";
  149. Initialize(device_model_file, jetChamber.ToString(), mod, mod.ToString());
  150. switch (jetChamber)
  151. {
  152. case JetChamber.Kepler2300:
  153. AddAdixenTurboPump(mod);
  154. AddEPD(mod);
  155. AddPendulumValve(mod);
  156. AddChiller(ChillerType.InnerChiller, mod);
  157. AddChiller(ChillerType.OuterChiller, mod);
  158. AddChiller(ChillerType.TopChiller, mod);
  159. AddMatch(mod);
  160. AddBiasMatch(mod);
  161. AddRF(mod);
  162. AddBiasRF(mod);
  163. AddDryPump(mod);
  164. AddCustomDevice(new JetKepler2300PM(mod));
  165. break;
  166. case JetChamber.Kepler2200A:
  167. AddAdixenTurboPump(mod);
  168. AddPendulumValve(mod,PressureType.Pa);
  169. AddMatch(mod);
  170. AddRF(mod);
  171. AddDryPump(mod);
  172. AddCustomDevice(new JetKepler2200APM(mod));
  173. break;
  174. case JetChamber.Kepler2200B:
  175. AddAdixenTurboPump(mod);
  176. AddPendulumValve(mod, PressureType.Pa);
  177. AddMatch(mod);
  178. AddRF(mod);
  179. AddDryPump(mod);
  180. AddRFBox(mod);
  181. AddCustomDevice(new JetKepler2200BPM(mod));
  182. break;
  183. case JetChamber.VenusSE:
  184. AddEscHighVoltage(mod);
  185. AddAdixenTurboPump(mod);
  186. AddEPD(mod);
  187. AddPendulumValve(mod);
  188. AddChiller(ChillerType.Chiller, mod);
  189. AddMatch(mod);
  190. AddBiasMatch(mod);
  191. AddRF(mod);
  192. AddBiasRF(mod);
  193. AddDryPump(mod);
  194. AddCustomDevice(new JetVenusSEPM(mod));
  195. break;
  196. case JetChamber.VenusDE:
  197. AddEscHighVoltage(mod);
  198. AddAdixenTurboPump(mod);
  199. AddEPD(mod);
  200. AddPendulumValve(mod);
  201. AddChiller(ChillerType.Chiller, mod);
  202. AddMatch(mod);
  203. AddBiasMatch(mod);
  204. //AddRF(mod);
  205. AddBiasRF(mod);
  206. AddDryPump(mod);
  207. AddCustomDevice(new JetVenusDEPM(mod));
  208. break;
  209. }
  210. }
  211. private void AddEPD(ModuleName mod)
  212. {
  213. if (SC.GetValue<bool>($"{mod}.EPD.IsEnabled") == true)
  214. {
  215. if (SC.GetValue<int>($"{mod}.EPD.EPDType") == 0)
  216. {
  217. AddCustomModuleDevice(new EPDClient(mod));
  218. }
  219. else
  220. {
  221. AddCustomModuleDevice(new EPDDevice(mod));
  222. }
  223. }
  224. }
  225. private void AddAdixenTurboPump(ModuleName mod)
  226. {
  227. AddCustomModuleDevice(new AdixenTurboPump(mod));
  228. }
  229. private void AddPendulumValve(ModuleName mod,PressureType pressureType=PressureType.mTorr)
  230. {
  231. AddCustomModuleDevice(new PendulumValve(mod,pressureType));
  232. }
  233. private void AddChiller(ChillerType chillerType, ModuleName mod)
  234. {
  235. if (SC.GetValue<bool>($"{mod}.{chillerType}.EnableChiller") &&
  236. SC.GetValue<int>($"{mod}.{chillerType}.CommunicationType") == (int)CommunicationType.RS232)
  237. {
  238. if (SC.GetValue<int>($"{mod}.{chillerType}.MFG") == (int)ChillerMFG.SMC)
  239. {
  240. AddCustomModuleDevice(new SMCChiller(mod, chillerType.ToString()));
  241. }
  242. else if (SC.GetValue<int>($"{mod}.{chillerType}.MFG") == (int)ChillerMFG.AIRSYS)
  243. {
  244. AddCustomModuleDevice(new AIRSYSChiller(mod, chillerType.ToString()));
  245. }
  246. }
  247. }
  248. private void AddMatch(ModuleName mod)
  249. {
  250. if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  251. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.RS232 &&
  252. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.AdTec)
  253. {
  254. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.Match));
  255. }
  256. else if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  257. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.RS232 &&
  258. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.Revtech)
  259. {
  260. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.Match, MatchCommunicationType.RS232));
  261. }
  262. else if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  263. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.Ethernet &&
  264. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.Revtech)
  265. {
  266. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.Match, MatchCommunicationType.Ethernet));
  267. }
  268. }
  269. private void AddRFBox(ModuleName mod)
  270. {
  271. if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  272. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.RS232 &&
  273. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.AdTec)
  274. {
  275. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.RFBox));
  276. }
  277. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  278. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.RS232 &&
  279. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Revtech)
  280. {
  281. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.RFBox, MatchCommunicationType.RS232));
  282. }
  283. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  284. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.Ethernet &&
  285. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Revtech)
  286. {
  287. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.RFBox, MatchCommunicationType.Ethernet));
  288. }
  289. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  290. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Lz_Ethercat && startEthercatOK)
  291. {
  292. AddCustomModuleDevice(new LzMatch_Ethercat(mod, Venus_Core.VenusDevice.RFBox, v_board_id));
  293. }
  294. }
  295. private void AddBiasMatch(ModuleName mod)
  296. {
  297. if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  298. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.RS232 &&
  299. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.AdTec)
  300. {
  301. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.BiasMatch));
  302. }
  303. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  304. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.RS232 &&
  305. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Revtech)
  306. {
  307. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.BiasMatch, MatchCommunicationType.RS232));
  308. }
  309. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  310. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.Ethernet &&
  311. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Revtech)
  312. {
  313. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.BiasMatch, MatchCommunicationType.Ethernet));
  314. }
  315. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  316. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Lz_Ethercat && startEthercatOK)
  317. {
  318. AddCustomModuleDevice(new LzMatch_Ethercat(mod, Venus_Core.VenusDevice.BiasMatch, v_board_id));
  319. }
  320. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  321. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.RS232 &&
  322. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Tru)
  323. {
  324. AddCustomModuleDevice(new TruPlasmaMatch(mod, Venus_Core.VenusDevice.BiasMatch));
  325. }
  326. }
  327. private void AddRF(ModuleName mod)
  328. {
  329. if (SC.GetValue<int>($"{mod}.Rf.CommunicationType") == (int)CommunicationType.RS232 &&
  330. SC.GetValue<int>($"{mod}.Rf.MFG") == (int)GeneratorMFG.AdTec)
  331. {
  332. AddCustomModuleDevice(new AdTecGenerator(mod, Venus_Core.VenusDevice.Rf));
  333. }
  334. }
  335. private void AddBiasRF(ModuleName mod)
  336. {
  337. if (SC.GetValue<bool>($"{mod}.BiasRf.EnableBiasRF"))
  338. {
  339. if (SC.GetValue<int>($"{mod}.BiasRf.CommunicationType") == (int)CommunicationType.Ethernet &&
  340. SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.Comet)
  341. {
  342. AddCustomModuleDevice(new CometRF(mod, SC.GetStringValue($"{mod}.BiasRf.IPAddress")));
  343. }
  344. else if (SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.AdTec)
  345. {
  346. AddCustomModuleDevice(new AdTecGenerator(mod, Venus_Core.VenusDevice.BiasRf));
  347. }
  348. else if (SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.Truplasma)
  349. {
  350. AddCustomModuleDevice(new TruPlasmaRF(mod, Venus_Core.VenusDevice.BiasRf));
  351. }
  352. else if (SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.Truplasma_Ethercat && startEthercatOK)
  353. {
  354. AddCustomModuleDevice(new TruPlasmaRF_Ethercat(mod, Venus_Core.VenusDevice.BiasRf, v_board_id));
  355. }
  356. }
  357. }
  358. private void AddDryPump(ModuleName mod)
  359. {
  360. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  361. {
  362. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  363. {
  364. AddCustomModuleDevice(new SkyPump(mod));
  365. }
  366. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  367. {
  368. AddCustomModuleDevice(new EdwardsPump(mod));
  369. }
  370. }
  371. }
  372. private void AddEscHighVoltage(ModuleName mod)
  373. {
  374. AddCustomModuleDevice(new ESC5HighVoltage(mod));
  375. }
  376. private void InitTM(ModuleName mod)
  377. {
  378. Initialize(device_model_file_MF, mod.ToString(), mod, mod.ToString());
  379. if (SC.GetValue<int>($"LLA.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  380. {
  381. if (SC.GetValue<int>($"LLA.DryPump.MFG") == (int)DryPumpMFG.SKY)
  382. {
  383. AddCustomModuleDevice(new SkyPump(ModuleName.LLA));
  384. }
  385. else if (SC.GetValue<int>($"LLA.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  386. {
  387. AddCustomModuleDevice(new EdwardsPump(ModuleName.LLA));
  388. }
  389. }
  390. if (SC.GetValue<int>($"LLB.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  391. {
  392. if (SC.GetValue<int>($"LLB.DryPump.MFG") == (int)DryPumpMFG.SKY)
  393. {
  394. AddCustomModuleDevice(new SkyPump(ModuleName.LLB));
  395. }
  396. else if (SC.GetValue<int>($"LLB.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  397. {
  398. AddCustomModuleDevice(new EdwardsPump(ModuleName.LLB));
  399. }
  400. }
  401. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  402. {
  403. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  404. {
  405. AddCustomModuleDevice(new SkyPump(mod));
  406. }
  407. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  408. {
  409. AddCustomModuleDevice(new EdwardsPump(mod));
  410. }
  411. }
  412. //AddCustomModuleDevice(new SkyPump(mod));
  413. //AddCustomModuleDevice(new SkyPump(ModuleName.LLA));
  414. AddCustomDevice(new JetTM());
  415. }
  416. private void InitSETM(ModuleName mod)
  417. {
  418. Initialize(device_model_file_SEMF, mod.ToString(), mod, mod.ToString());
  419. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  420. {
  421. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  422. {
  423. AddCustomModuleDevice(new SkyPump(mod));
  424. }
  425. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  426. {
  427. AddCustomModuleDevice(new EdwardsPump(mod));
  428. }
  429. }
  430. AddCustomDevice(new HongHuTM());
  431. }
  432. private WaferSize MapWaferSize(int value)
  433. {
  434. switch (value)
  435. {
  436. case 3: return WaferSize.WS3;
  437. case 4: return WaferSize.WS4;
  438. case 6: return WaferSize.WS6;
  439. case 8: return WaferSize.WS8;
  440. }
  441. return WaferSize.WS0;
  442. }
  443. private bool Invoke(string arg1, object[] args)
  444. {
  445. string name = (string)args[0];
  446. string func = (string)args[1];
  447. object[] param = new object[args.Length - 2];
  448. for (int i = 2; i < args.Length; i++)
  449. param[i - 2] = args[i].ToString();
  450. DEVICE.Do(string.Format("{0}.{1}", name, func), 0, true, param);
  451. return true;
  452. }
  453. public void RTExitPMEvent()
  454. {
  455. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  456. {
  457. DEVICE.GetDevice<JetPMBase>("PMA")?.RTCloseEvent();
  458. }
  459. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  460. {
  461. DEVICE.GetDevice<JetPMBase>("PMB")?.RTCloseEvent();
  462. }
  463. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  464. {
  465. DEVICE.GetDevice<JetPMBase>("PMC")?.RTCloseEvent();
  466. }
  467. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  468. {
  469. DEVICE.GetDevice<JetPMBase>("PMD")?.RTCloseEvent();
  470. }
  471. }
  472. }
  473. }