WaferStatusHandler.cs 4.2 KB

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