Photo.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using NLog;
  8. using SmartSEMControl;
  9. namespace MeasureThread
  10. {
  11. class Photo : IPhoto
  12. {
  13. NLog.Logger log;
  14. private PhotoParam prm;
  15. private ISEMControl iSEM;
  16. public Photo( ISEMControl sem)
  17. {
  18. this.log = NLog.LogManager.GetCurrentClassLogger();
  19. this.iSEM = sem ?? throw new ArgumentNullException(nameof(sem));
  20. }
  21. public void SetPhotoParam(PhotoParam a_prm)
  22. {
  23. this.prm = a_prm ?? throw new ArgumentNullException(nameof(a_prm));
  24. }
  25. public PhotoParam GetParam()
  26. {
  27. if (prm == null)
  28. {
  29. prm = new PhotoParam();
  30. }
  31. return prm;
  32. }
  33. public void EnforceBrightness()
  34. {
  35. float b = iSEM.GetBrightness();
  36. Thread.Sleep(100);
  37. iSEM.SetBrightness(b + 1);
  38. Thread.Sleep(200);
  39. }
  40. public void EnforceContrast()
  41. {
  42. float c= iSEM.GetContrast();
  43. Thread.Sleep(100);
  44. iSEM.SetContrast(c + 1);
  45. Thread.Sleep(200);
  46. }
  47. public bool TakePhoto()
  48. {
  49. if (!iSEM.SetMagnification(prm.Mag))
  50. {
  51. return false;
  52. }
  53. float set = prm.Mag;
  54. Thread.Sleep(500);
  55. float current = iSEM.GetMagnification();
  56. while (Math.Abs(current - set) > 1)
  57. {
  58. iSEM.SetMagnification(set);
  59. Thread.Sleep(200);
  60. current = iSEM.GetMagnification();
  61. }
  62. iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//iSEM.CmdSaveRate();
  63. Thread.Sleep(200);
  64. float cycle_time = iSEM.GetCycleTime();
  65. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  66. //拍照前改变速度,延时
  67. iSEM.CmdLineScan();
  68. Thread.Sleep(200);
  69. cycle_time = iSEM.GetCycleTime();
  70. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  71. if (!GetImage(prm.savePath))
  72. {
  73. log.Error("SEM拍照失败", false);
  74. return false;
  75. }
  76. iSEM.CmdPixelScan();
  77. Thread.Sleep(200);
  78. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
  79. cycle_time = iSEM.GetCycleTime();
  80. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  81. return true;
  82. }
  83. //拍图
  84. public bool GetImage(String a_fileName)
  85. {
  86. log.Info("获取分辨率开始!", true);
  87. //3. 获取分辨率
  88. int[] ImageSize = iSEM.GetImageStore();
  89. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  90. {
  91. return false;
  92. }
  93. short width = (short)ImageSize[0];
  94. short height = (short)ImageSize[1];
  95. log.Info("获取分辨率结束!" + a_fileName + "====" + width + "*" + height, true);
  96. //4. 抓图
  97. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  98. {
  99. log.Info("抓图失败!", true);
  100. return false;
  101. }
  102. return true;
  103. }
  104. }
  105. }