123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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( ISEMControl sem)
- {
- this.log = NLog.LogManager.GetCurrentClassLogger();
-
- this.iSEM = sem ?? throw new ArgumentNullException(nameof(sem));
- }
- public void SetPhotoParam(PhotoParam a_prm)
- {
- this.prm = a_prm ?? throw new ArgumentNullException(nameof(a_prm));
- }
- public PhotoParam GetParam()
- {
- if (prm == null)
- {
- prm = new PhotoParam();
- }
- return prm;
- }
- public void EnforceBrightness()
- {
- float b = iSEM.GetBrightness();
- Thread.Sleep(100);
- iSEM.SetBrightness(b + 1);
- Thread.Sleep(200);
- }
- public void EnforceContrast()
- {
- float c= iSEM.GetContrast();
- Thread.Sleep(100);
- iSEM.SetContrast(c + 1);
- Thread.Sleep(200);
- }
- public bool TakePhoto()
- {
-
- if (!iSEM.SetMagnification(prm.Mag))
- {
- return false;
- }
- float set = prm.Mag;
- Thread.Sleep(500);
- float current = iSEM.GetMagnification();
- while (Math.Abs(current - set) > 1)
- {
- iSEM.SetMagnification(set);
- Thread.Sleep(200);
- current = iSEM.GetMagnification();
- }
- iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//iSEM.CmdSaveRate();
-
- Thread.Sleep(200);
- float cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
- //拍照前改变速度,延时
- iSEM.CmdLineScan();
- Thread.Sleep(200);
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
- if (!GetImage(prm.savePath))
- {
- log.Error("SEM拍照失败", false);
- return false;
- }
- iSEM.CmdPixelScan();
- Thread.Sleep(200);
- iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
-
- 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;
- }
- }
- }
|