1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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 bool TakePhoto()
- {
-
- if (!iSEM.SetMagnification(prm.Mag))
- {
- return false;
- }
- Thread.Sleep(500);
- //iSEM.SetReduced(402, 384, 200, 200);
- iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");
- iSEM.SetAutoVideoBrightnessAndContrast();
- Thread.Sleep(3000);
- //iSEM.CloseReduced();
- iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//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("CMD_SCANRATE4");//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;
- }
- }
- }
|