using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using NLog; using SmartSEMControl; namespace MeasureThread { class Photo : IPhoto { NLog.Logger log; private PhotoParam prm; private ISEMControl iSEM; public Photo( PhotoParam prm,ISEMControl sem) { this.log = NLog.LogManager.GetCurrentClassLogger(); this.prm = prm ?? throw new ArgumentNullException(nameof(prm)); this.iSEM = sem ?? throw new ArgumentNullException(nameof(sem)); } public bool TakePhoto() { if (!iSEM.SetMagnification(prm.Mag)) { return false; } //float current = iSEM.GetMagnification(); //while (Math.Abs(current - prm.mag) > 1) //{ // iSEM.SetMagnification(prm.mag); // Thread.Sleep(200); // current = iSEM.GetMagnification(); //} Thread.Sleep(500); iSEM.CmdFocusScanSpeed(prm.scanSpeed);//iSEM.CmdSaveRate(); //add by sun 2020 - 12 - 15 增加不同样品扫描速度参数,每大类样品3种扫描速度 end Thread.Sleep(200); float cycle_time = iSEM.GetCycleTime(); Thread.Sleep(Convert.ToInt32(cycle_time) + 100); if (!GetImage(prm.savePath)) { log.Error("SEM拍照失败", false); return false; } iSEM.CmdFocusScanSpeed(prm.scanSpeedAfter);//CmdFocusRate(4); cycle_time = iSEM.GetCycleTime(); Thread.Sleep(Convert.ToInt32(cycle_time) + 1000); return true; } //拍图 public bool GetImage(String a_fileName) { log.Info("获取分辨率开始!", true); //3. 获取分辨率 int[] ImageSize = iSEM.GetImageStore(); if (ImageSize[0] == 0 || ImageSize[1] == 0) { return false; } short width = (short)ImageSize[0]; short height = (short)ImageSize[1]; log.Info("获取分辨率结束!" + a_fileName + "====" + width + "*" + height, true); //4. 抓图 if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0)) { log.Info("抓图失败!", true); return false; } return true; } } }