DeviceManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. if (SC.GetValue<int>($"{mod}.Rf.CommunicationType") == (int)CommunicationType.RS232 &&
  151. SC.GetValue<int>($"{mod}.Rf.MFG") == (int)GeneratorMFG.AdTec)
  152. {
  153. AddCustomModuleDevice(new AdTecGenerator(mod, Venus_Core.VenusDevice.Rf));
  154. }
  155. if (jetChamber == JetChamber.Kepler2300)
  156. {
  157. if (SC.GetValue<bool>($"{mod}.InnerChiller.EnableChiller") &&
  158. SC.GetValue<int>($"{mod}.InnerChiller.CommunicationType") == (int)CommunicationType.RS232)
  159. {
  160. if (SC.GetValue<int>($"{mod}.InnerChiller.MFG") == (int)ChillerMFG.SMC)
  161. {
  162. AddCustomModuleDevice(new SMCChiller(mod, "InnerChiller"));
  163. }
  164. else if (SC.GetValue<int>($"{mod}.InnerChiller.MFG") == (int)ChillerMFG.AIRSYS)
  165. {
  166. AddCustomModuleDevice(new AIRSYSChiller(mod, "InnerChiller"));
  167. }
  168. }
  169. if (SC.GetValue<bool>($"{mod}.OuterChiller.EnableChiller") &&
  170. SC.GetValue<int>($"{mod}.OuterChiller.CommunicationType") == (int)CommunicationType.RS232)
  171. {
  172. if (SC.GetValue<int>($"{mod}.OuterChiller.MFG") == (int)ChillerMFG.SMC)
  173. {
  174. AddCustomModuleDevice(new SMCChiller(mod, "OuterChiller"));
  175. }
  176. else if (SC.GetValue<int>($"{mod}.OuterChiller.MFG") == (int)ChillerMFG.AIRSYS)
  177. {
  178. AddCustomModuleDevice(new AIRSYSChiller(mod, "OuterChiller"));
  179. }
  180. }
  181. if (SC.GetValue<bool>($"{mod}.TopChiller.EnableChiller") &&
  182. SC.GetValue<int>($"{mod}.TopChiller.CommunicationType") == (int)CommunicationType.RS232)
  183. {
  184. if (SC.GetValue<int>($"{mod}.TopChiller.MFG") == (int)ChillerMFG.SMC)
  185. {
  186. AddCustomModuleDevice(new SMCChiller(mod, "TopChiller"));
  187. }
  188. else if (SC.GetValue<int>($"{mod}.TopChiller.MFG") == (int)ChillerMFG.AIRSYS)
  189. {
  190. AddCustomModuleDevice(new AIRSYSChiller(mod, "TopChiller"));
  191. }
  192. }
  193. }
  194. if (jetChamber == JetChamber.Kepler2200B)
  195. {
  196. if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  197. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.RS232 &&
  198. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.AdTec)
  199. {
  200. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.RFBox));
  201. }
  202. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  203. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.RS232 &&
  204. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Revtech)
  205. {
  206. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.RFBox, MatchCommunicationType.RS232));
  207. }
  208. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  209. SC.GetValue<int>($"{mod}.RFBox.CommunicationType") == (int)CommunicationType.Ethernet &&
  210. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Revtech)
  211. {
  212. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.RFBox, MatchCommunicationType.Ethernet));
  213. }
  214. else if (SC.GetValue<bool>($"{mod}.RFBox.EnableMatch") &&
  215. SC.GetValue<int>($"{mod}.RFBox.MFG") == (int)MatchMFG.Lz_Ethercat && startEthercatOK)
  216. {
  217. AddCustomModuleDevice(new LzMatch_Ethercat(mod, Venus_Core.VenusDevice.RFBox, v_board_id));
  218. }
  219. }
  220. if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  221. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.RS232 &&
  222. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.AdTec)
  223. {
  224. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.Match));
  225. }
  226. else if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  227. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.RS232 &&
  228. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.Revtech)
  229. {
  230. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.Match, MatchCommunicationType.RS232));
  231. }
  232. else if (SC.GetValue<bool>($"{mod}.Match.EnableMatch") &&
  233. SC.GetValue<int>($"{mod}.Match.CommunicationType") == (int)CommunicationType.Ethernet &&
  234. SC.GetValue<int>($"{mod}.Match.MFG") == (int)MatchMFG.Revtech)
  235. {
  236. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.Match, MatchCommunicationType.Ethernet));
  237. }
  238. if (jetChamber != JetChamber.Kepler2200A && jetChamber != JetChamber.Kepler2200B)
  239. {
  240. if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  241. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.RS232 &&
  242. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.AdTec)
  243. {
  244. AddCustomModuleDevice(new AdTecMatch(mod, Venus_Core.VenusDevice.BiasMatch));
  245. }
  246. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  247. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.RS232 &&
  248. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Revtech)
  249. {
  250. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.BiasMatch, MatchCommunicationType.RS232));
  251. }
  252. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  253. SC.GetValue<int>($"{mod}.BiasMatch.CommunicationType") == (int)CommunicationType.Ethernet &&
  254. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Revtech)
  255. {
  256. AddCustomModuleDevice(new RevtechMatch(mod, Venus_Core.VenusDevice.BiasMatch, MatchCommunicationType.Ethernet));
  257. }
  258. else if (SC.GetValue<bool>($"{mod}.BiasMatch.EnableBiasMatch") &&
  259. SC.GetValue<int>($"{mod}.BiasMatch.MFG") == (int)MatchMFG.Lz_Ethercat && startEthercatOK)
  260. {
  261. AddCustomModuleDevice(new LzMatch_Ethercat(mod, Venus_Core.VenusDevice.BiasMatch, v_board_id));
  262. }
  263. if (SC.GetValue<bool>($"{mod}.BiasRf.EnableBiasRF"))
  264. {
  265. if (SC.GetValue<int>($"{mod}.BiasRf.CommunicationType") == (int)CommunicationType.Ethernet &&
  266. SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.Comet)
  267. {
  268. AddCustomModuleDevice(new CometRF(mod, SC.GetStringValue($"{mod}.BiasRf.IPAddress")));
  269. }
  270. else if (SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.AdTec)
  271. {
  272. AddCustomModuleDevice(new AdTecGenerator(mod, Venus_Core.VenusDevice.BiasRf));
  273. }
  274. else if (SC.GetValue<int>($"{mod}.BiasRf.MFG") == (int)GeneratorMFG.Truplasma_Ethercat && startEthercatOK)
  275. {
  276. AddCustomModuleDevice(new TruPlasmaRF_Ethercat(mod, Venus_Core.VenusDevice.BiasRf, v_board_id));
  277. }
  278. }
  279. AddCustomModuleDevice(new ESC5HighVoltage(mod));
  280. if (SC.GetValue<bool>($"{mod}.Chiller.EnableChiller") &&
  281. SC.GetValue<int>($"{mod}.Chiller.CommunicationType") == (int)CommunicationType.RS232)
  282. {
  283. if (SC.GetValue<int>($"{mod}.Chiller.MFG") == (int)ChillerMFG.SMC)
  284. {
  285. AddCustomModuleDevice(new SMCChiller(mod, "Chiller"));
  286. }
  287. else if (SC.GetValue<int>($"{mod}.Chiller.MFG") == (int)ChillerMFG.AIRSYS)
  288. {
  289. AddCustomModuleDevice(new AIRSYSChiller(mod, "Chiller"));
  290. }
  291. }
  292. if (SC.GetValue<bool>($"{mod}.EPD.IsEnabled") == true)
  293. {
  294. if (SC.GetValue<int>($"{mod}.EPD.EPDType") == 0)
  295. {
  296. AddCustomModuleDevice(new EPDClient(mod));
  297. }
  298. else
  299. {
  300. AddCustomModuleDevice(new EPDDevice(mod));
  301. }
  302. }
  303. }
  304. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  305. {
  306. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  307. {
  308. AddCustomModuleDevice(new SkyPump(mod));
  309. }
  310. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  311. {
  312. AddCustomModuleDevice(new EdwardsPump(mod));
  313. }
  314. }
  315. AddCustomModuleDevice(new AdixenTurboPump(mod));
  316. AddCustomModuleDevice(new PendulumValve(mod));
  317. switch (jetChamber)
  318. {
  319. case JetChamber.Venus:
  320. AddCustomDevice(new JetVenusPM(mod));
  321. break;
  322. case JetChamber.Kepler2300:
  323. AddCustomDevice(new JetKepler2300PM(mod));
  324. break;
  325. case JetChamber.Kepler2200A:
  326. AddCustomDevice(new JetKepler2200APM(mod));
  327. break;
  328. case JetChamber.Kepler2200B:
  329. AddCustomDevice(new JetKepler2200BPM(mod));
  330. break;
  331. case JetChamber.VenusSE:
  332. AddCustomDevice(new JetVenusSEPM(mod));
  333. break;
  334. case JetChamber.VenusDE:
  335. AddCustomDevice(new JetVenusDEPM(mod));
  336. break;
  337. }
  338. }
  339. private void InitTM(ModuleName mod)
  340. {
  341. Initialize(device_model_file_MF, mod.ToString(), mod, mod.ToString());
  342. if (SC.GetValue<int>($"LLA.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  343. {
  344. if (SC.GetValue<int>($"LLA.DryPump.MFG") == (int)DryPumpMFG.SKY)
  345. {
  346. AddCustomModuleDevice(new SkyPump(ModuleName.LLA));
  347. }
  348. else if (SC.GetValue<int>($"LLA.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  349. {
  350. AddCustomModuleDevice(new EdwardsPump(ModuleName.LLA));
  351. }
  352. }
  353. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  354. {
  355. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  356. {
  357. AddCustomModuleDevice(new SkyPump(mod));
  358. }
  359. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  360. {
  361. AddCustomModuleDevice(new EdwardsPump(mod));
  362. }
  363. }
  364. //AddCustomModuleDevice(new SkyPump(mod));
  365. //AddCustomModuleDevice(new SkyPump(ModuleName.LLA));
  366. AddCustomDevice(new JetTM());
  367. }
  368. private void InitSETM(ModuleName mod)
  369. {
  370. Initialize(device_model_file_SEMF, mod.ToString(), mod, mod.ToString());
  371. if (SC.GetValue<int>($"{mod}.DryPump.CommunicationType") == (int)CommunicationType.RS232)
  372. {
  373. if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.SKY)
  374. {
  375. AddCustomModuleDevice(new SkyPump(mod));
  376. }
  377. else if (SC.GetValue<int>($"{mod}.DryPump.MFG") == (int)DryPumpMFG.Edwards)
  378. {
  379. AddCustomModuleDevice(new EdwardsPump(mod));
  380. }
  381. }
  382. AddCustomDevice(new HongHuTM());
  383. }
  384. private WaferSize MapWaferSize(int value)
  385. {
  386. switch (value)
  387. {
  388. case 3: return WaferSize.WS3;
  389. case 4: return WaferSize.WS4;
  390. case 6: return WaferSize.WS6;
  391. case 8: return WaferSize.WS8;
  392. }
  393. return WaferSize.WS0;
  394. }
  395. private bool Invoke(string arg1, object[] args)
  396. {
  397. string name = (string)args[0];
  398. string func = (string)args[1];
  399. object[] param = new object[args.Length - 2];
  400. for (int i = 2; i < args.Length; i++)
  401. param[i - 2] = args[i].ToString();
  402. DEVICE.Do(string.Format("{0}.{1}", name, func), 0, true, param);
  403. return true;
  404. }
  405. public void RTExitPMEvent()
  406. {
  407. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  408. {
  409. DEVICE.GetDevice<JetPMBase>("PMA")?.RTCloseEvent();
  410. }
  411. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  412. {
  413. DEVICE.GetDevice<JetPMBase>("PMB")?.RTCloseEvent();
  414. }
  415. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  416. {
  417. DEVICE.GetDevice<JetPMBase>("PMC")?.RTCloseEvent();
  418. }
  419. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  420. {
  421. DEVICE.GetDevice<JetPMBase>("PMD")?.RTCloseEvent();
  422. }
  423. }
  424. }
  425. }