ToolLoader.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Aitex.Common.Util;
  5. using Aitex.Core.Account;
  6. using Aitex.Core.RT.ConfigCenter;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.DataCollection;
  9. using Aitex.Core.RT.DBCore;
  10. using Aitex.Core.RT.Device;
  11. using Aitex.Core.RT.Event;
  12. using Aitex.Core.RT.Log;
  13. using Aitex.Core.RT.OperationCenter;
  14. using Aitex.Core.RT.RecipeCenter;
  15. using Aitex.Core.RT.SCCore;
  16. using Aitex.Core.Util;
  17. using Aitex.Core.WCF;
  18. using EFEM.RT.Backends;
  19. using EFEM.RT.Devices;
  20. using EFEM.RT.Modules;
  21. using EfemRT.Backends;
  22. using MECF.Framework.Common.SCCore;
  23. using MECF.Framework.Common.SubstrateTrackings;
  24. using MECF.Framework.RT.Core.Applications;
  25. using MECF.Framework.RT.Core.Backend;
  26. using MECF.Framework.RT.Core.IoProviders;
  27. namespace EFEM.RT.Systems
  28. {
  29. class ToolLoader : IRtLoader
  30. {
  31. public void Initialize()
  32. {
  33. InitCommonModules();
  34. InitBackend();
  35. InitSystemModules();
  36. }
  37. private void InitSystemModules()
  38. {
  39. Singleton<RouteManager>.Instance.Initialize();
  40. Singleton<EfemEntity>.Instance.SetEfemData();
  41. Singleton<EfemEntity>.Instance.Initialize();
  42. }
  43. private void InitCommonModules()
  44. {
  45. Singleton<LogManager>.Instance.Initialize();
  46. Singleton<ConfigManager>.Instance.Initialize();
  47. Singleton<DatabaseManager>.Instance.Initialize(
  48. System.Configuration.ConfigurationManager.ConnectionStrings["PostgreSQL"].ConnectionString
  49. , RtInstance.DatabaseName
  50. , PathManager.GetCfgDir() + "DBModel.sql");
  51. Singleton<EventManager>.Instance.Initialize(PathManager.GetCfgDir() + "EventDefine.xml");
  52. Singleton<OperationManager>.Instance.Initialize();
  53. Singleton<DataManager>.Instance.Initialize();
  54. Singleton<WcfServiceManager>.Instance.Initialize(new Type[]
  55. {
  56. typeof(AccountService)
  57. });
  58. Singleton<SystemConfigManager>.Instance.Initialize(PathManager.GetCfgDir() + "Efem.sccfg");
  59. DeviceDefineManager.Instance.Initialize(PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "DeviceDefine.xml");
  60. string ioProviderPathFile = PathManager.GetCfgDir() + $"{SC.GetStringValue("System.DeviceType")}\\" + "IoProviderConfig.xml";
  61. Dictionary<string, Dictionary<int, string>> ioMap;
  62. switch (DeviceDefineManager.Instance.GetValue<int>("IoCardQuantity"))
  63. {
  64. case 1:
  65. ioMap = new Dictionary<string, Dictionary<int, string>>()
  66. {
  67. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  68. {"System.Super", new Dictionary<int, string>(){{256, PathManager.GetCfgDir() + $"{SC.GetStringValue("System.DeviceType")}\\" + "\\_diDefineSuper.xml" },
  69. {512, PathManager.GetCfgDir() + $"{SC.GetStringValue("System.DeviceType")}\\" + "\\_doDefineSuper.xml" },
  70. { 1001, PathManager.GetCfgDir() + $"{SC.GetStringValue("System.DeviceType")}\\" + "\\_aiDefineSuper.xml" },
  71. { 2001, PathManager.GetCfgDir() + $"{SC.GetStringValue("System.DeviceType")}\\" + "\\_aoDefineSuper.xml" } } },
  72. };
  73. break;
  74. case 2:
  75. ioMap = new Dictionary<string, Dictionary<int, string>>()
  76. {
  77. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  78. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }}
  79. };
  80. break;
  81. case 3:
  82. ioMap = new Dictionary<string, Dictionary<int, string>>()
  83. {
  84. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  85. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }},
  86. {"System.dio002", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard3.xml" } }}
  87. };
  88. break;
  89. case 4:
  90. ioMap = new Dictionary<string, Dictionary<int, string>>()
  91. {
  92. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  93. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }},
  94. {"System.dio002", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard3.xml" } }},
  95. {"System.dio003", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard4.xml" } }}
  96. };
  97. break;
  98. case 5:
  99. ioMap = new Dictionary<string, Dictionary<int, string>>()
  100. {
  101. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  102. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }},
  103. {"System.dio002", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard3.xml" } }},
  104. {"System.dio003", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard4.xml" } }},
  105. {"System.dio004", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard5.xml" } }}
  106. };
  107. break;
  108. case 6:
  109. ioMap = new Dictionary<string, Dictionary<int, string>>()
  110. {
  111. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  112. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }},
  113. {"System.dio002", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard3.xml" } }},
  114. {"System.dio003", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard4.xml" } }},
  115. {"System.dio004", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard5.xml" } }},
  116. {"System.dio005", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard6.xml" } }},
  117. };
  118. break;
  119. case 7:
  120. ioMap = new Dictionary<string, Dictionary<int, string>>()
  121. {
  122. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard1.xml" } }},
  123. {"System.dio001", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard2.xml" } }},
  124. {"System.dio002", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard3.xml" } }},
  125. {"System.dio003", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard4.xml" } }},
  126. {"System.dio004", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard5.xml" } }},
  127. {"System.dio005", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard6.xml" } }},
  128. {"System.dio006", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineCard7.xml" } }},
  129. };
  130. break;
  131. default:
  132. ioMap = new Dictionary<string, Dictionary<int, string>>()
  133. {
  134. {"System.dio000", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefine.xml" }}}
  135. };
  136. break;
  137. }
  138. if (DeviceDefineManager.Instance.GetValue<bool>("MotionAxisInstalled") ?? false)
  139. {
  140. ioMap.Add("System.MotionAxis", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineMotionAxis.xml" }});
  141. }
  142. if (DeviceDefineManager.Instance.GetValue<bool>("PLCIoInstalled") ?? false)
  143. {
  144. ioMap.Add("System.MainPlc", new Dictionary<int, string>(){{0, PathManager.GetCfgDir()+ $"{SC.GetStringValue("System.DeviceType")}\\" + "_ioDefineMainPlc.xml" }});
  145. }
  146. IoProviderManager.Instance.Initialize(ioProviderPathFile, ioMap);
  147. WaferManager.Instance.Initialize();
  148. Singleton<DeviceManager>.Instance.Initialize(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,
  149. $"Config\\{SC.GetStringValue("System.DeviceType")}\\",
  150. RtInstance.DeviceModelFileName), "EFEM");
  151. //Singleton<DeviceEntity>.Instance.Initialize();
  152. DataCollectionManager.Instance.Initialize("efemdb");
  153. Singleton<EventManager>.Instance.FireEvent += InstanceOnOnEvent;
  154. CarrierConfigurationManager.Instance.Initialize();
  155. Singleton<DeviceEntity>.Instance.Initialize();
  156. }
  157. private void InstanceOnOnEvent(EventItem obj)
  158. {
  159. }
  160. private void InitBackend()
  161. {
  162. RtSystemManager.Instance.AddCustomBackend("Connection", new ConnectionView());
  163. RtSystemManager.Instance.AddCustomBackend("IO", new IOView());
  164. RtSystemManager.Instance.AddCustomBackend("SC", new BackendSCConfigView());
  165. }
  166. public void Terminate()
  167. {
  168. Singleton<RouteManager>.Instance.Terminate();
  169. Singleton<EfemEntity>.Instance.Terminate();
  170. Singleton<DeviceEntity>.Instance.Terminate();
  171. Singleton<DeviceManager>.Instance.Terminate();
  172. IoProviderManager.Instance.Terminate();
  173. Singleton<SystemConfigManager>.Instance.Terminate();
  174. DataCollectionManager.Instance.Terminate();
  175. Singleton<WcfServiceManager>.Instance.Terminate();
  176. Singleton<EventManager>.Instance.Terminate();
  177. Singleton<LogManager>.Instance.Terminate();
  178. Singleton<DatabaseManager>.Instance.Terminate();
  179. }
  180. }
  181. }