SRDLotTrackUtil.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.SRD;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Threading.Tasks;
  12. namespace CyberX8_RT.Modules.SRD
  13. {
  14. public class SRDLotTrackUtil
  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 ExportSRDLotTrack(string moduleName, List<SRDLotTrackData> datas, LotTrackFileHeaderCommonData headerData, bool isAuto)
  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. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleNameString.ToEnum(moduleName), 0);
  37. if (waferInfo != null && !string.IsNullOrEmpty(waferInfo.LotId))
  38. {
  39. strPath = waferInfo.LotTrackPath;
  40. }
  41. else
  42. {
  43. LOG.WriteLog(eEvent.ERR_SRD, moduleName, $"{moduleName} is failed to write LotTrackDatas");
  44. return;
  45. }
  46. fi = new FileInfo(PathManager.GetLotTrackFilePath() + strPath);
  47. }
  48. else
  49. {
  50. strPath = $"{moduleName}_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff")}.csv";
  51. fi = new FileInfo(PathManager.GetLotTrackFilePath() + $"Manual\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\" + strPath);
  52. }
  53. //目录不存在则创建
  54. if (!fi.Directory.Exists)
  55. {
  56. fi.Directory.Create();
  57. }
  58. FileStream fs = new FileStream(fi.FullName, System.IO.FileMode.Append, System.IO.FileAccess.Write);
  59. StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
  60. if (!isAuto)
  61. {
  62. sw.WriteLine(fi.FullName);
  63. sw.WriteLine($"Date:{DateTime.Now.ToShortDateString()}");
  64. sw.WriteLine($"ToolID:{headerData.ToolID}");
  65. sw.WriteLine($"SW Version:{headerData.SoftWareVersion}");
  66. }
  67. sw.WriteLine(moduleName);
  68. sw.WriteLine($"Recipe:{headerData.Recipe}");
  69. sw.WriteLine($"ProcessTime:{headerData.ProcessTime}");
  70. sw.Write(CVS_SPLIT_CHAR);
  71. string str = $"TimeStamp{CVS_SPLIT_CHAR}StateMachine{CVS_SPLIT_CHAR}WaterPressure{CVS_SPLIT_CHAR}WaterFlow{CVS_SPLIT_CHAR}" +
  72. $"RotationSpeed{CVS_SPLIT_CHAR}WaterOn{CVS_SPLIT_CHAR}LoaderDIEnable{CVS_SPLIT_CHAR}ChuckVacuumOn{CVS_SPLIT_CHAR}ChuckVacuumPressure";
  73. sw.WriteLine(str);
  74. for (int i = 0; i < datas.Count; i++)
  75. {
  76. SRDLotTrackData data = datas[i];
  77. string tmp = $"{CVS_SPLIT_CHAR}{data.TimeStamp.ToString("HH:mm:ss")}{CVS_SPLIT_CHAR}{data.StateMachine}{CVS_SPLIT_CHAR}{data.WaterPressure}{CVS_SPLIT_CHAR}{data.WaterFlow}{CVS_SPLIT_CHAR}" +
  78. $"{data.RotationSpeed}{CVS_SPLIT_CHAR}{data.WaterOn}{CVS_SPLIT_CHAR}{data.LoaderDIEnable}{CVS_SPLIT_CHAR}{data.ChuckVacuumOn}{CVS_SPLIT_CHAR}{data.ChuckVacuumPressure}";
  79. sw.WriteLine(tmp);
  80. }
  81. sw.WriteLine("");
  82. sw.Close();
  83. fs.Close();
  84. }
  85. catch
  86. {
  87. LOG.WriteLog(eEvent.ERR_SRD, moduleName, $"{moduleName} LotTrack file writing is failed!");
  88. }
  89. });
  90. }
  91. }
  92. }