ParameterConfigManager.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. using Aitex.Core.RT.ConfigCenter;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.SCCore;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using static MECF.Framework.Common.Utilities.Parameter;
  12. namespace MECF.Framework.Common.Utilities
  13. {
  14. public static class ParameterConfigManager
  15. {
  16. private static bool _isInit = false;
  17. private static void InitializeAllBlocks()
  18. {
  19. if (_isInit) return;
  20. string key = "System.SetUp.BlockNumber";
  21. // string numberVlaue = SC.IsEnable ? SC.GetStringValue(key) : QueryDataClient.Instance.Service.GetConfig(key)?.ToString();
  22. string numberVlaue ="3Block";
  23. var numberOfBlock = int.Parse((numberVlaue.Replace("Block", "")));
  24. ParameterManager.Instance.NumberOfBlocks = numberOfBlock;
  25. ParameterManager.InitializeBlock();
  26. SCValue SCBlock = null;
  27. switch (numberOfBlock)
  28. {
  29. case 2:
  30. SCBlock = new SCValue2Block();
  31. break;
  32. case 3:
  33. SCBlock = new SCValue3Block();
  34. break;
  35. case 4:
  36. SCBlock = new SCValue4Block();
  37. break;
  38. default:
  39. break;
  40. }
  41. SCBlock.SetKeys();
  42. var scValue = CONFIG.IsEnable ? CONFIG.PollConfig(SCBlock.GetKeys()) : QueryDataClient.Instance.Service.PollConfig(SCBlock.GetKeys());
  43. SCBlock.Update(scValue);
  44. SCBlock.SetParameterValue(ParameterManager.Instance);
  45. _isInit = true;
  46. }
  47. public static void ResetInitializeAllBlocks()
  48. {
  49. string key = "System.SetUp.BlockNumber";
  50. string numberVlaue = SC.IsEnable ? SC.GetStringValue(key) : QueryDataClient.Instance.Service.GetConfig(key)?.ToString();
  51. var numberOfBlock = int.Parse((numberVlaue.Replace("Block", "")));
  52. ParameterManager.Instance.NumberOfBlocks = numberOfBlock;
  53. ParameterManager.InitializeBlock();
  54. SCValue SCBlock = null;
  55. switch (numberOfBlock)
  56. {
  57. case 2:
  58. SCBlock = new SCValue2Block();
  59. break;
  60. case 3:
  61. SCBlock = new SCValue3Block();
  62. break;
  63. case 4:
  64. SCBlock = new SCValue4Block();
  65. break;
  66. default:
  67. break;
  68. }
  69. SCBlock.SetKeys();
  70. var scValue = CONFIG.IsEnable ? CONFIG.PollConfig(SCBlock.GetKeys()) : QueryDataClient.Instance.Service.PollConfig(SCBlock.GetKeys());
  71. SCBlock.Update(scValue);
  72. SCBlock.SetParameterValue(ParameterManager.Instance);
  73. }
  74. public static string GetChemicalSupplySystem(string module)
  75. {
  76. string strRet = string.Empty;
  77. var tempString = module.Replace("PM", "").Split('_');
  78. string strCurrentBlock = tempString[0];
  79. string strCurrentModule = tempString.Length > 1 ? tempString[1] : string.Empty;
  80. string strDispenseConfig = string.Empty;
  81. string key = $"System.SetUp.Block{strCurrentBlock}.{strCurrentModule}.DispenseConfig";
  82. if (SC.IsEnable)
  83. strDispenseConfig = SC.GetStringValue(key).ToString();
  84. else
  85. strDispenseConfig = QueryDataClient.Instance.Service.GetConfig(key).ToString();
  86. string[] listDispense = strDispenseConfig.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  87. for (int x = 0; x < listDispense.Length; x++)
  88. {
  89. string[] sigDispense = listDispense[x].Split(':');
  90. if (sigDispense[1].Split(',')[1].ToLower().Contains("true"))
  91. {
  92. strRet = sigDispense[1].Split(',')[8];
  93. if (strRet == "-") continue;
  94. break;
  95. }
  96. }
  97. strRet = strRet.Replace("CSS", "").Replace(" ", "");
  98. return strRet;
  99. }
  100. public static string GetParameterValueByIndex(string module, int firstIndex, int secondIndex)
  101. {
  102. string strRet = string.Empty;
  103. var tempString = module.Replace("PM", "").Split('_');
  104. string strCurrentBlock = tempString[0];
  105. string strCurrentModule = tempString.Length > 1 ? tempString[1] : string.Empty;
  106. string strDispenseConfig = string.Empty;
  107. string key = $"System.SetUp.Block{strCurrentBlock}.{strCurrentModule}.DispenseConfig";
  108. if (SC.IsEnable)
  109. strDispenseConfig = SC.GetStringValue(key).ToString();
  110. else
  111. strDispenseConfig = QueryDataClient.Instance.Service.GetConfig(key).ToString();
  112. string[] listDispense = strDispenseConfig.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  113. for (int x = 0; x < listDispense.Length; x++)
  114. {
  115. string[] sigDispense = listDispense[x].Split(':');
  116. if (sigDispense[1].Split(',')[1].ToLower().Contains("true"))
  117. {
  118. string[] firstStrs = sigDispense[1].Split(',');
  119. if (firstStrs.Length > firstIndex)
  120. {
  121. string[] secondStrs = firstStrs[firstIndex].Split('/');
  122. if (secondStrs.Length > secondIndex)
  123. strRet = secondStrs[secondIndex];
  124. }
  125. }
  126. }
  127. return strRet;
  128. }
  129. public static string GetParameterValueByIndex(string module, string device, int firstIndex, int secondIndex)
  130. {
  131. string strRet = string.Empty;
  132. var tempString = module.Replace("PM", "").Split('_');
  133. string strCurrentBlock = tempString[0];
  134. string strCurrentModule = tempString.Length > 1 ? tempString[1] : string.Empty;
  135. string strDispenseConfig = string.Empty;
  136. string key = $"System.SetUp.Block{strCurrentBlock}.{strCurrentModule}.DispenseConfig";
  137. if (SC.IsEnable)
  138. strDispenseConfig = SC.GetStringValue(key).ToString();
  139. else
  140. strDispenseConfig = QueryDataClient.Instance.Service.GetConfig(key).ToString();
  141. string[] listDispense = strDispenseConfig.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  142. for (int x = 0; x < listDispense.Length; x++)
  143. {
  144. string[] sigDispense = listDispense[x].Split(':');
  145. if (!sigDispense[0].Replace(".", "").ToLower().Contains(device))
  146. {
  147. continue;
  148. }
  149. if (sigDispense[1].Split(',')[1].ToLower().Contains("true"))
  150. {
  151. string[] firstStrs = sigDispense[1].Split(',');
  152. if (firstStrs.Length > firstIndex)
  153. {
  154. string[] secondStrs = firstStrs[firstIndex].Split('/');
  155. if (secondStrs.Length > secondIndex)
  156. strRet = secondStrs[secondIndex];
  157. }
  158. }
  159. }
  160. return strRet;
  161. }
  162. private static DeviceModule GetDeviceModuleByID(string ID)
  163. {
  164. InitializeAllBlocks();
  165. ID = ID.Replace("PM", "").Replace("_", "-");
  166. return ParameterManager.Instance.SpinerDeviceModule.First(x => x.ID == ID);
  167. }
  168. public static string GetDispenseRange(string moduleName, string deviceName, int index)
  169. {
  170. string strRet = string.Empty;
  171. var tempString = moduleName.Split('_');
  172. string strCurrentBlock = tempString[0];
  173. string strCurrentModule = tempString.Length > 1 ? tempString[1] : string.Empty;
  174. string strDispenseConfig = string.Empty;
  175. string key = $"System.SetUp.Block{strCurrentBlock}.{strCurrentModule}.DispenseConfig";
  176. if (SC.IsEnable)
  177. strDispenseConfig = SC.GetStringValue(key).ToString();
  178. else
  179. strDispenseConfig = QueryDataClient.Instance.Service.GetConfig(key).ToString(); string[] listDispense = strDispenseConfig.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  180. for (int x = 0; x < listDispense.Length; x++)
  181. {
  182. string[] sigDispense = listDispense[x].Split(':');
  183. if (!sigDispense[0].Contains(deviceName))
  184. {
  185. continue;
  186. }
  187. if (sigDispense[1].Split(',')[1].ToLower().Contains("true"))
  188. {
  189. strRet = sigDispense[1].Split(',')[7].Split('/')[index];
  190. }
  191. }
  192. return strRet;
  193. }
  194. public static int GetSpinOffTime(string name)
  195. {
  196. int ret = -1;
  197. DeviceModule moudle = GetDeviceModuleByID(name);
  198. if (moudle !=null)
  199. {
  200. int.TryParse(moudle.ModuleSpiner.SpinOutTime,out ret);
  201. }
  202. return ret;
  203. }
  204. public static float GetSpinOffSpeed(string name)
  205. {
  206. float ret = -1;
  207. DeviceModule moudle = GetDeviceModuleByID(name);
  208. if (moudle != null)
  209. {
  210. float.TryParse(moudle.ModuleSpiner.SpinOutSpeed, out ret);
  211. }
  212. return ret;
  213. }
  214. public static List<float> GetSpinModulePara(string name, string armName, string pos)
  215. {
  216. //Arm1 resist arm
  217. //Arm2 ebr arm
  218. //Arm3 spin
  219. //Arm4 nozzle change
  220. DeviceModule moudle = GetDeviceModuleByID(name);
  221. if (moudle is null)
  222. return null;
  223. object obj = null;
  224. switch (armName)
  225. {
  226. case "Arm1":
  227. obj = moudle.ModuleSpiner.NozzleArmInformat1;
  228. break;
  229. case "Arm2":
  230. obj = moudle.ModuleSpiner.NozzleArmInformat2;
  231. break;
  232. case "Arm4":
  233. obj = moudle.ModuleSpiner.NozzleChanger;
  234. break;
  235. }
  236. if (obj == null)
  237. return null;
  238. List<float> listRet = new List<float>();
  239. float position = 0;
  240. float speed = 0;
  241. float acc = 0;
  242. float dec = 0;
  243. float unit = 0;
  244. if (obj is NozzleArmInformat)
  245. {
  246. NozzleArmInformat arm = obj as NozzleArmInformat;
  247. float.TryParse(arm.MotorPulsesRate, out unit);
  248. if (pos.ToLower().Contains("begin"))
  249. pos = "Begin";
  250. if (pos.ToLower().Contains("end"))
  251. pos = "End";
  252. var prop = arm.GetType().GetProperty(pos);
  253. if (prop != null)
  254. {
  255. TransferArmRecipePositionData data = prop.GetValue(arm) as TransferArmRecipePositionData;
  256. float.TryParse(data.Position, out position);
  257. float.TryParse(data.Acceleration, out acc);
  258. float.TryParse(data.Deceleration, out dec);
  259. }
  260. }
  261. else if (obj is NozzleChanger)
  262. {
  263. NozzleChanger arm = obj as NozzleChanger;
  264. float.TryParse(arm.MotorPulseRate, out unit);
  265. int.TryParse(pos, out int index);
  266. if (index > 0 && index <= arm.NozzleChangerData.Count)
  267. {
  268. NozzleChangerData data = arm.NozzleChangerData[index - 1];
  269. float.TryParse(data.Position, out position);
  270. }
  271. }
  272. listRet.Add(position);
  273. listRet.Add(speed);
  274. listRet.Add(acc);
  275. listRet.Add(dec);
  276. listRet.Add(unit);
  277. return listRet;
  278. }
  279. public static List<string> GetSpinModulePositions(string name, string armName)
  280. {
  281. DeviceModule moudle = GetDeviceModuleByID(name);
  282. if (moudle is null)
  283. return null;
  284. object obj = null;
  285. switch (armName)
  286. {
  287. case "Arm1":
  288. obj = moudle.ModuleSpiner.NozzleArmInformat1;
  289. break;
  290. case "Arm2":
  291. obj = moudle.ModuleSpiner.NozzleArmInformat2;
  292. break;
  293. case "Arm4":
  294. obj = moudle.ModuleSpiner.NozzleChanger;
  295. break;
  296. }
  297. if (obj == null)
  298. return null;
  299. List<string> listRet = new List<string>();
  300. if (obj is NozzleArmInformat)
  301. {
  302. foreach (var item in obj.GetType().GetProperties())
  303. {
  304. if (item.PropertyType == typeof(TransferArmRecipePositionData))
  305. {
  306. listRet.Add(item.Name);
  307. }
  308. }
  309. }
  310. else if (obj is NozzleChanger)
  311. {
  312. NozzleChanger arm = obj as NozzleChanger;
  313. foreach (var item in arm.NozzleChangerData.Where(x => x.IsNozzleChangerEnable.ToLower() == "yes"))
  314. {
  315. listRet.Add(item.ID);
  316. }
  317. }
  318. return listRet;
  319. }
  320. public static bool SetStnParas(string module, string hand, Dictionary<string, double> robotStnParas)
  321. {
  322. var name = module.Replace("PM", "").Replace("_", ".");
  323. Dictionary<string, object> scItems = new Dictionary<string, object>();
  324. foreach (var item in robotStnParas.Keys)
  325. {
  326. if (item == "StartOffset" || item == "EndOffset")
  327. {
  328. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.Zaxis.{item}", robotStnParas[item]);
  329. }
  330. else
  331. {
  332. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.{hand}.{item}", robotStnParas[item]);
  333. }
  334. }
  335. SystemConfigManager.Instance.SetItemValues(scItems);
  336. return true;
  337. }
  338. public static bool SetCassetteStnParas(string module, string hand, Dictionary<string, double> robotStnParas)
  339. {
  340. if (module.Contains("Cassette"))
  341. {
  342. var name = module.Replace("Cassette", "1.");
  343. Dictionary<string, object> scItems = new Dictionary<string, object>();
  344. foreach (var item in robotStnParas.Keys)
  345. {
  346. if (item == "StartOffset" || item == "EndOffset")
  347. {
  348. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.Zaxis.{item}", robotStnParas[item]);
  349. }
  350. else
  351. {
  352. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.{hand}.{item}", robotStnParas[item]);
  353. }
  354. }
  355. SystemConfigManager.Instance.SetItemValues(scItems);
  356. }
  357. else if (module.Contains("PM"))
  358. {
  359. var name = module.Replace("PM", "").Replace("_", ".");
  360. Dictionary<string, object> scItems = new Dictionary<string, object>();
  361. foreach (var item in robotStnParas.Keys)
  362. {
  363. if (item == "StartOffset" || item == "EndOffset")
  364. {
  365. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.Zaxis.{item}", robotStnParas[item]);
  366. }
  367. else
  368. {
  369. scItems.Add($"System.SetUp.Block{name}.TransferArmPosition.{hand}.{item}", robotStnParas[item]);
  370. }
  371. }
  372. SystemConfigManager.Instance.SetItemValues(scItems);
  373. }
  374. return true;
  375. }
  376. private static Dictionary<string, string> dicCSMappingKey = new Dictionary<string, string>() {
  377. {"FB_THICKNESS","WaferThickness"},
  378. {"Z_WAF","FirstSlotposition"},
  379. {"PITCH","SlotPitch"},
  380. {"MAP_START","MappingStartPosition"},
  381. {"MAP_END","MappingEndPosition"},
  382. {"NSLOTS","SlotNo"}
  383. };
  384. public static bool SetCassetteStnMappingParas(string module, string strData)
  385. {
  386. Dictionary<string, int> dicData = new Dictionary<string, int>();
  387. List<string> lstData = strData.Replace("STN 1", "").Trim(' ').Split(' ').ToList();
  388. for (int i = 0; i < lstData.Count; i=i+2)
  389. {
  390. if(dicCSMappingKey.ContainsKey(lstData[i]))
  391. dicData.Add(dicCSMappingKey[lstData[i]], int.Parse(lstData[i + 1]));
  392. }
  393. var name = module.Replace("Cassette", "1.");
  394. Dictionary<string, object> scItems = new Dictionary<string, object>();
  395. foreach (var item in dicData.Keys)
  396. {
  397. scItems.Add($"System.SetUp.Block{name}.{item}", dicData[item]);
  398. }
  399. SystemConfigManager.Instance.SetItemValues(scItems);
  400. return true;
  401. }
  402. public static Dictionary<string,object> GetCassetteStnMappingParas(string module)
  403. {
  404. Dictionary<string, object> ret = new Dictionary<string, object>();
  405. var name = module.Replace("Cassette", "1.");
  406. foreach (var item in dicCSMappingKey)
  407. {
  408. string key = $"System.SetUp.Block{name}.{item.Value}";
  409. object data = SC.GetValue<int>(key);
  410. ret.Add(item.Key, data);
  411. }
  412. return ret;
  413. }
  414. public static EunmTransferOrder GetTransferOrder(string key)
  415. {
  416. string configKey = $"Parameter.TransferOutOrInOrder.{key}";
  417. string value = SC.IsEnable ? SC.GetStringValue(configKey) : QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  418. EunmTransferOrder ret = EunmTransferOrder.ByTop;
  419. switch (value)
  420. {
  421. case "Top":
  422. ret = EunmTransferOrder.ByTop;
  423. break;
  424. case "Bottom":
  425. ret = EunmTransferOrder.ByBottom;
  426. break;
  427. case "Slot":
  428. ret = EunmTransferOrder.BySlot;
  429. break;
  430. }
  431. return ret;
  432. }
  433. public static MonitorEditData GetMonitorData(string moduleIndex, string controlName)
  434. {
  435. InitializeAllBlocks();
  436. return ParameterManager.Instance.MonitorData.FirstOrDefault(x => x.Module == moduleIndex.Replace("_", "-") && x.MeasDateName.ToLower().Contains(controlName.ToLower()));
  437. }
  438. public static List<KeyValuePair<string, DispenseConfig>> GetDPConigData(string moduleIndex)
  439. {
  440. InitializeAllBlocks();
  441. return ParameterManager.Instance.ModuleDispenseConfigList[$"{moduleIndex.Replace("_", "-")}"].Where(x => x.Value.IsChecked).ToList();
  442. }
  443. public static FlowSensorData GetDPConigFlowSensorData(string moduleIndex, string deviceName)
  444. {
  445. InitializeAllBlocks();
  446. return ParameterManager.Instance.ModuleDispenseConfigList[moduleIndex].FirstOrDefault(x => x.Value.IsChecked && x.Key == deviceName).Value?.FlowSensorData;
  447. }
  448. }
  449. }