WaferStatusHandler.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using MECF.Framework.Common.DataCenter;
  2. using OpenSEMI.ClientBase;
  3. using OpenSEMI.Core.Msg;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Threading;
  12. namespace CyberX8_MainPages.Unity
  13. {
  14. public class WaferStatusHandler : IHandler
  15. {
  16. public static readonly List<string> ReverseModules = new List<string>() { "LLA","LLB", "LP1", "LP2", "LP3","VCE1","Dummy1", "Dummy2" };
  17. public WaferStatusHandler(Func<string, List<WaferInfo>> funcGetWaferStatus, List<string> allModules)
  18. {
  19. this.WaferStatusDic = new Dictionary<string, ModuleWaferManager>();
  20. this.looper = new MsgPool(500, Do);
  21. this.GetWaferStatusByModule = funcGetWaferStatus;
  22. //init wafer status dictionary
  23. allModules.ForEach(key => { InitWafersByModule(key); });
  24. }
  25. public void Handle()
  26. {
  27. this.looper.Run();
  28. }
  29. private void InitWafersByModule(string moduleID)
  30. {
  31. lock (lockObj)
  32. {
  33. if (!this.WaferStatusDic.ContainsKey(moduleID))
  34. {
  35. this.WaferStatusDic.Add(moduleID, new ModuleWaferManager(moduleID));
  36. List<WaferInfo> mWafers = GetWaferStatusByModule(moduleID);
  37. if (mWafers != null)
  38. {
  39. ModuleWaferManager modinfowithwafer = this.WaferStatusDic[moduleID];
  40. for (int i = 0; i < mWafers.Count; i++)
  41. {
  42. modinfowithwafer.Wafers.Add(mWafers[i]);
  43. }
  44. if (ReverseModules.Contains(moduleID))
  45. {
  46. modinfowithwafer.Wafers.Reverse();
  47. }
  48. }
  49. }
  50. }
  51. }
  52. private void Do(MsgPool pool)
  53. {
  54. lock (lockObj)
  55. {
  56. if (Application.Current == null || Application.Current.Dispatcher == null)
  57. return;
  58. foreach (KeyValuePair<string, ModuleWaferManager> pair in WaferStatusDic)
  59. {
  60. List<WaferInfo> mWafers = GetWaferStatusByModule(pair.Key);
  61. Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
  62. {
  63. if (mWafers != null && mWafers.Count == pair.Value.Wafers.Count)
  64. {
  65. int index;
  66. bool isCassettePresent = true;
  67. if (pair.Key.Contains("LP"))
  68. {
  69. isCassettePresent = (bool)QueryDataClient.Instance.Service.GetData($"{pair.Key}.CassettePlaced");
  70. if (!isCassettePresent) pair.Value.IsReset = true;
  71. }
  72. for (int i = 0; i < mWafers.Count; i++)
  73. {
  74. //status used in UI control
  75. if (ReverseModules.Contains(pair.Key))
  76. index = mWafers.Count - i - 1;
  77. else
  78. index = i;
  79. pair.Value.Wafers[i].WaferStatus = mWafers[index].WaferStatus;
  80. pair.Value.Wafers[i].WaferID = mWafers[index].WaferID;
  81. pair.Value.Wafers[i].SourceName = mWafers[index].SourceName;
  82. if (!string.IsNullOrEmpty(mWafers[index].SequenceName) || !isCassettePresent)
  83. {
  84. pair.Value.Wafers[i].SequenceName = mWafers[index].SequenceName;
  85. }
  86. }
  87. }
  88. });
  89. }
  90. }
  91. }
  92. public Dictionary<string, ModuleWaferManager> WaferStatusDic { get; private set; }
  93. public MsgPool looper { get; private set; }
  94. private Func<string, List<WaferInfo>> GetWaferStatusByModule;
  95. private static object lockObj = new object();
  96. }
  97. }