Photo.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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( PhotoParam prm,ISEMControl sem)
  17. {
  18. this.log = NLog.LogManager.GetCurrentClassLogger();
  19. this.prm = prm ?? throw new ArgumentNullException(nameof(prm));
  20. this.iSEM = sem ?? throw new ArgumentNullException(nameof(sem));
  21. }
  22. public bool TakePhoto()
  23. {
  24. if (!iSEM.SetMagnification(prm.Mag))
  25. {
  26. return false;
  27. }
  28. //float current = iSEM.GetMagnification();
  29. //while (Math.Abs(current - prm.mag) > 1)
  30. //{
  31. // iSEM.SetMagnification(prm.mag);
  32. // Thread.Sleep(200);
  33. // current = iSEM.GetMagnification();
  34. //}
  35. Thread.Sleep(500);
  36. iSEM.CmdFocusScanSpeed(prm.scanSpeed);//iSEM.CmdSaveRate();
  37. //add by sun 2020 - 12 - 15 增加不同样品扫描速度参数,每大类样品3种扫描速度 end
  38. Thread.Sleep(200);
  39. float cycle_time = iSEM.GetCycleTime();
  40. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  41. if (!GetImage(prm.savePath))
  42. {
  43. log.Error("SEM拍照失败", false);
  44. return false;
  45. }
  46. iSEM.CmdFocusScanSpeed(prm.scanSpeedAfter);//CmdFocusRate(4);
  47. cycle_time = iSEM.GetCycleTime();
  48. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  49. return true;
  50. }
  51. //拍图
  52. public bool GetImage(String a_fileName)
  53. {
  54. log.Info("获取分辨率开始!", true);
  55. //3. 获取分辨率
  56. int[] ImageSize = iSEM.GetImageStore();
  57. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  58. {
  59. return false;
  60. }
  61. short width = (short)ImageSize[0];
  62. short height = (short)ImageSize[1];
  63. log.Info("获取分辨率结束!" + a_fileName + "====" + width + "*" + height, true);
  64. //4. 抓图
  65. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  66. {
  67. log.Info("抓图失败!", true);
  68. return false;
  69. }
  70. return true;
  71. }
  72. }
  73. }