using OTSCLRINTERFACE; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using OTSModelSharp.ServiceInterface; using OTSDataType; namespace OTSMeasureApp { public class OTSBSEImageFun { //OTSIncAMeasureAppForm m_MsrApp = null; NLog.Logger log ; CImageHandler imageHandle; public OTSBSEImageFun() { log = NLog.LogManager.GetCurrentClassLogger(); imageHandle = new CImageHandler(); } public bool GetBSEImage(COTSImageProcParam ImgProcPrm,double pixelSize, byte[] BSEImage, int iHeight, int iWidth, ref byte[] BSEImageNoBG) { return imageHandle.GetBSEImage(ImgProcPrm,pixelSize, BSEImage, iHeight, iWidth,ref BSEImageNoBG); } public bool GetBSEImage(byte[] BSEImage, int iHeight, int iWidth, int grayStart, int grayEnd, ref byte[] BSEImageNoBG) { return imageHandle.GetBSEImage(BSEImage, iHeight, iWidth, grayStart, grayEnd,ref BSEImageNoBG); } public int GetScanImage(int iWidth, int iHeigh, ref byte[] bImageData) { //电镜设置对象 COTSControlFunExport cfun = COTSControlFunExport.GetControllerInstance(); int GetImgCount = 0; try { //连接电镜 bool IsConnec = cfun.ConncetSem(); if (!IsConnec) { string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ConncetSem() = false Failed"; log.Error(strErrorInfo); return 0; } //实例电镜初始化 bool IsScan = cfun.ScanInit(); if (!IsScan) { string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ScanInit = false Failed"; log.Error(strErrorInfo); return 0; } //int a_ExternalMode = 0; ////获取终止模式 //a_ExternalMode = cfun.GetSemExternalMode(); ////保存初始模式变量 //int a_oldMode = 0; ////获取初始模式 //if (!cfun.GetSemScanMode(ref a_oldMode)) //{ // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemScanMode = false Failed"; // log.Error(strErrorInfo); // return 0; //} ////设置当前模式 //if (!cfun.SetSemScanMode(a_ExternalMode)) //{ // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetSemScanMode = false Failed"; // log.Error(strErrorInfo); // return 0; //} //#region BeamBlank //int a_nBeamBlank = 0; ////获取参数 //if (!cfun.GetSemBeamBlank(ref a_nBeamBlank)) //{ // cfun.SetSemScanMode(a_oldMode); // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemBeamBlank = false Failed"; // log.Error(strErrorInfo); // return 0; //} ////设置参数 //if (!cfun.SetSemBeamBlank(false)) //{ // cfun.SetSemScanMode(a_oldMode); // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetSemBeamBlank = false Failed"; // log.Error(strErrorInfo); // return 0; //} //#endregion //#region 获得放大倍数 ////获得放大倍数 //double a_dMagnification = 0; ////获取参数 //if (!cfun.GetSemMagnification(ref a_dMagnification)) //{ // cfun.SetSemScanMode(a_oldMode); // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemMagnification = false Failed"; // log.Error(strErrorInfo); // return 0; //} //#endregion //#region 获取 电镜 X、Y轴 与角度 ////获取 电镜 X、Y轴 与角度 //double PositionX = 0; //double PositionY = 0; //double PositionR = 0; ////获取参数 //if (!cfun.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR)) //{ // cfun.SetSemScanMode(a_oldMode); // string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemPositionXY = false Failed"; // log.Error(strErrorInfo); // return 0; //} //#endregion #region 设置图像分辨率 //设置宽度 if (!cfun.SetImageSize(iWidth,iHeigh)) { //cfun.SetSemScanMode(a_oldMode); string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetImageSize = false Failed"; log.Error(strErrorInfo); return 0; } #endregion #region 采集时间 //采集时间 int nDwellTime = 4; if (!cfun.SetDwellTime(nDwellTime)) { //cfun.SetSemScanMode(a_oldMode); string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetDwellTime = false Failed"; log.Error(strErrorInfo); return 0; } #endregion #region MatrixSize //获得放大倍数 //int a_MatrixSize = 0; //Size size = new Size(); //获取参数 //size = cfun.GetMatrixSize(a_MatrixSize); //size = cfun.GetMatrixSize(a_MatrixSize); #endregion //获取图像数据 int resultCount = iWidth * iHeigh; GetImgCount = cfun.AcquireBSEImage(0, 0, 0, ref bImageData); //记录日志 if (resultCount == GetImgCount) { //设置为原始 扫描模式 //cfun.SetSemScanMode(a_oldMode); } else { //cfun.SetSemScanMode(a_oldMode); string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.AcquireBSEImage = 0 Failed"; log.Error(strErrorInfo); } } catch (Exception ex) { //记录日志 log.Error(ex.Message.ToString()); string strErrorInfo = "(OTSBSEImageFun.GetScanImage) Exception Error Happend"; log.Error(strErrorInfo); } return GetImgCount; } } }