PrewetLotTrackUtil.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Log;
  4. using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.CommonData.Prewet;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using MECF.Framework.Common.WaferHolder;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Threading.Tasks;
  12. namespace CyberX8_RT.Modules.Prewet
  13. {
  14. public class PrewetLotTrackUtil
  15. {
  16. /// <summary>
  17. /// CSV文件分隔符
  18. /// </summary>
  19. private const char CVS_SPLIT_CHAR = ',';
  20. /// <summary>
  21. /// 导出至csv
  22. /// </summary>
  23. /// <param name="moduleName"></param>
  24. /// <param name="datas"></param>
  25. public static async void ExportPrewetLotTrack(string moduleName, List<PrewetLotTrackData> datas, LotTrackFileHeaderCommonData headerData, bool isAuto, bool isRetry)
  26. {
  27. await Task.Run(() =>
  28. {
  29. try
  30. {
  31. if (datas == null || datas.Count == 0) return;
  32. string strPath;
  33. FileInfo fi;
  34. if (isAuto)
  35. {
  36. WaferHolderInfo whInfo = WaferHolderManager.Instance.GetWaferHolder(moduleName);
  37. if (whInfo == null) return;
  38. WaferInfo waferInfoA = WaferManager.Instance.GetWaferByWaferId(whInfo.WaferAId);
  39. WaferInfo waferInfoB = WaferManager.Instance.GetWaferByWaferId(whInfo.WaferBId);
  40. if (waferInfoA != null && !string.IsNullOrEmpty(waferInfoA.LotId))
  41. {
  42. strPath = waferInfoA.LotTrackPath;
  43. }
  44. else if (waferInfoA != null && !string.IsNullOrEmpty(waferInfoA.LotId))
  45. {
  46. strPath = waferInfoB.LotTrackPath;
  47. }
  48. else
  49. {
  50. LOG.WriteLog(eEvent.ERR_PREWET, moduleName, $"{moduleName} is failed to write LotTrackDatas");
  51. return;
  52. }
  53. fi = new FileInfo(PathManager.GetLotTrackFilePath() + strPath);
  54. }
  55. else
  56. {
  57. strPath = $"{moduleName}_M{DateTime.Now.ToString("MM")}_D{DateTime.Now.ToString("dd")}_H{DateTime.Now.ToString("HH")}_M{DateTime.Now.ToString("mm")}_S{DateTime.Now.ToString("ss")}.csv";
  58. fi = new FileInfo(PathManager.GetLotTrackFilePath() + $"Manual\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\" + strPath);
  59. }
  60. //目录不存在则创建
  61. if (!fi.Directory.Exists)
  62. {
  63. fi.Directory.Create();
  64. }
  65. FileStream fs = new FileStream(fi.FullName, System.IO.FileMode.Append, System.IO.FileAccess.Write);
  66. StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
  67. if (!isAuto)
  68. {
  69. sw.WriteLine(fi.FullName);
  70. sw.WriteLine($"Date:{DateTime.Now.ToShortDateString()}");
  71. sw.WriteLine($"ToolID:{headerData.ToolID}");
  72. sw.WriteLine($"SW Version:{headerData.SoftWareVersion}");
  73. sw.WriteLine($"Sequence Recipe:{headerData.SequenceRecipe}");
  74. }
  75. if ((!isRetry && isAuto) || !isAuto)
  76. {
  77. if (headerData.ProcessTransferList != null)
  78. {
  79. foreach (var item in headerData.ProcessTransferList)
  80. {
  81. sw.WriteLine(item);
  82. }
  83. }
  84. sw.WriteLine(moduleName);
  85. sw.WriteLine($"Recipe:{headerData.Recipe}");
  86. sw.WriteLine($"SingleWafer:{headerData.IsSingleWafe}");
  87. sw.WriteLine($"ProcessTime:{headerData.ProcessTime}");
  88. sw.Write(CVS_SPLIT_CHAR);
  89. string str = $"TimeStamp{CVS_SPLIT_CHAR}StateMachine{CVS_SPLIT_CHAR}Pressure{CVS_SPLIT_CHAR}Flow{CVS_SPLIT_CHAR}PumpMode{CVS_SPLIT_CHAR}" +
  90. $"CurrentScan{CVS_SPLIT_CHAR}ScanOn{CVS_SPLIT_CHAR}PressureTarget{CVS_SPLIT_CHAR}ValveState{CVS_SPLIT_CHAR}PumpSpeed{CVS_SPLIT_CHAR}PumpControlCurrent";
  91. sw.WriteLine(str);
  92. }
  93. for (int i = 0; i < datas.Count; i++)
  94. {
  95. PrewetLotTrackData data = datas[i];
  96. string tmp = $"{CVS_SPLIT_CHAR}{data.TimeStamp.ToString("HH:mm:ss")}{CVS_SPLIT_CHAR}{data.StateMachine}{CVS_SPLIT_CHAR}{data.Pressure.ToString("F3")}{CVS_SPLIT_CHAR}{data.Flow.ToString("F3")}" +
  97. $"{CVS_SPLIT_CHAR}{data.PumpMode}{CVS_SPLIT_CHAR}{data.CurrentScan}{CVS_SPLIT_CHAR}{data.ScanOn}{CVS_SPLIT_CHAR}{data.PressureTarget.ToString("F3")}{CVS_SPLIT_CHAR}" +
  98. $"{data.ValveState}{CVS_SPLIT_CHAR}{data.PumpSpeed}{CVS_SPLIT_CHAR}{data.PumpControlCurrent.ToString("F3")}";
  99. sw.WriteLine(tmp);
  100. }
  101. sw.WriteLine("");
  102. sw.Close();
  103. fs.Close();
  104. }
  105. catch
  106. {
  107. LOG.WriteLog(eEvent.ERR_PREWET, moduleName, $"{moduleName} LotTrack file writing is failed!");
  108. }
  109. });
  110. }
  111. }
  112. }