Photo.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 bool TakePhoto()
  34. {
  35. if (!iSEM.SetMagnification(prm.Mag))
  36. {
  37. return false;
  38. }
  39. Thread.Sleep(500);
  40. //iSEM.SetReduced(402, 384, 200, 200);
  41. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");
  42. iSEM.SetAutoVideoBrightnessAndContrast();
  43. Thread.Sleep(3000);
  44. //iSEM.CloseReduced();
  45. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//iSEM.CmdSaveRate();
  46. //add by sun 2020 - 12 - 15 增加不同样品扫描速度参数,每大类样品3种扫描速度 end
  47. Thread.Sleep(200);
  48. float cycle_time = iSEM.GetCycleTime();
  49. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  50. if (!GetImage(prm.savePath))
  51. {
  52. log.Error("SEM拍照失败", false);
  53. return false;
  54. }
  55. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
  56. cycle_time = iSEM.GetCycleTime();
  57. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  58. return true;
  59. }
  60. //拍图
  61. public bool GetImage(String a_fileName)
  62. {
  63. log.Info("获取分辨率开始!", true);
  64. //3. 获取分辨率
  65. int[] ImageSize = iSEM.GetImageStore();
  66. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  67. {
  68. return false;
  69. }
  70. short width = (short)ImageSize[0];
  71. short height = (short)ImageSize[1];
  72. log.Info("获取分辨率结束!" + a_fileName + "====" + width + "*" + height, true);
  73. //4. 抓图
  74. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  75. {
  76. log.Info("抓图失败!", true);
  77. return false;
  78. }
  79. return true;
  80. }
  81. }
  82. }