123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
-
- using FEIApiControl;
- using OTSCLRINTERFACE;
- using OTSDataType;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSModelSharp.ServiceInterface
- {
- public class ScanController : IScanController
- {
- private OTSCLRINTERFACE.COTSControlFunExport scan;
- static ScanController scanctrl=null;
- public static APIClass ApiClass = null;
- private static bool isFEI = false;
- int imageWidth = 0;
- int imageHeight = 0;
- public static ScanController GetScanController()
- {
- if (FileHelper.GetXMLInformations("SemControllerName") == "FEI")
- {
- isFEI = true;
- }
- if (scanctrl == null)
- {
- scanctrl = new ScanController();
- }
- return scanctrl;
- }
- private ScanController()
- {
- if (isFEI)
- {
- ApiClass = new APIClass();
- }
- else
- {
- this.scan = SemController.hw;
- }
- }
- public CBSEImgClr AcquireBSEImage(int matrixIndex, int reads, int dwell)
- {
- if (isFEI)
- {
- Rectangle r = new Rectangle();
- CBSEImgClr bse = new CBSEImgClr(r);
- bse.InitImageData(imageWidth, imageHeight);
- byte[] imgData = new byte[imageWidth * imageHeight];
- if (!ApiClass.RunAcquireImage(imageWidth, imageHeight, dwell, "", ref imgData))
- {
- return null;
- }
- bse.SetImageData(imgData, imageWidth, imageHeight);
- return bse;
- }
- else
- {
- if (!scan.IsConnected())
- {
- return null;
- }
- Rectangle r = new Rectangle();
- CBSEImgClr bse = new CBSEImgClr(r);
- if (!scan.AcquireBSEImage(matrixIndex, reads, dwell, ref bse))
- {
- return null;
- }
- return bse;
- }
- }
- public bool Init()
- {
- if (isFEI)
- {
- string FEIIP = FileHelper.GetXMLInformations("FEIIP");
- string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
- if (FEIIP == "" || FEIPORT == "")
- {
- NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
- return false;
- }
- if (ApiClass.isConnect())
- {
- return true;
- }
- return ApiClass.Connect(FEIIP, FEIPORT);
- }
- else
- {
- return scan.ScanInit();
- }
- }
- public bool SetDwellTime(long val)
- {
- if (isFEI)
- {
- return true;
- }
- else
- {
- if (!scan.IsConnected())
- {
- return false;
- }
- return scan.SetDwellTime((int)val);
- }
- }
- public bool SetImageSize(int width,int height)
- {
- imageWidth = width;
- imageHeight = height;
- if (isFEI)
- {
- return ApiClass.SetResolution(imageWidth, imageHeight);
- }
- else
- {
- if (!scan.IsConnected())
- {
- return false;
- }
- return scan.SetImageSize(width, height);
- }
- }
- public static int GetScanImage(int iWidth, int iHeigh, string DwellTime, ref byte[] bImageData)
- {
- if (FileHelper.GetXMLInformations("SemControllerName") == "FEI")
- {
- ScanController m_ScanHardwareMgr = ScanController.GetScanController();
- m_ScanHardwareMgr.Init();
- m_ScanHardwareMgr.SetImageSize(iWidth, iHeigh);
- bImageData = m_ScanHardwareMgr.AcquireBSEImage(0, 0, int.Parse(DwellTime)).GetImageDataPtr();
- return 1;
- }
- else
- {
- //电镜设置对象
- var cfun = COTSControlFunExport.GetControllerInstance();
- int GetImgCount = 0;
- try
- {
- //连接电镜
- bool IsConnec = cfun.ConncetSem();
- if (!IsConnec)
- {
- return 0;
- }
- //实例电镜初始化
- bool IsScan = cfun.ScanInit();
- if (!IsScan)
- {
- return 0;
- }
- int a_ExternalMode = 0;
- //获取终止模式
- a_ExternalMode = cfun.GetSemExternalMode();
- //保存初始模式变量
- int a_oldMode = 0;
- //获取初始模式
- if (!cfun.GetSemScanMode(ref a_oldMode))
- {
- return 0;
- }
- //设置当前模式
- if (!cfun.SetSemScanMode(a_ExternalMode))
- {
- return 0;
- }
- #region BeamBlank
- int a_nBeamBlank = 0;
- //获取参数
- if (!cfun.GetSemBeamBlank(ref a_nBeamBlank))
- {
- cfun.SetSemScanMode(a_oldMode);
- return 0;
- }
- //设置参数
- if (!cfun.SetSemBeamBlank(false))
- {
- cfun.SetSemScanMode(a_oldMode);
- return 0;
- }
- #endregion
- #region 获得放大倍数
- //获得放大倍数
- double a_dMagnification = 0;
- //m_MsrApp.m_LogFunExport.TraceLog("APP_GetSemMagnification-----begin------");
- //获取参数
- if (!cfun.GetSemMagnification(ref a_dMagnification))
- {
- cfun.SetSemScanMode(a_oldMode);
- return 0;
- }
- //m_MsrApp.m_LogFunExport.TraceLog("APP_GetSemMagnification_a_dMagnification:" + a_dMagnification + "------");
- //m_MsrApp.m_LogFunExport.TraceLog("APP_GetSemMagnification-----end------");
- #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);
- return 0;
- }
- #endregion
- #region 设置图像分辨率
- //设置宽度
- if (!cfun.SetImageSize(iWidth, iHeigh))
- {
- cfun.SetSemScanMode(a_oldMode);
- return 0;
- }
- #endregion
- #region 采集时间
- //采集时间
- int nDwellTime = Convert.ToInt32(DwellTime);
- //设置采集时间
- if (!cfun.SetDwellTime(nDwellTime))
- {
- cfun.SetSemScanMode(a_oldMode);
- return 0;
- }
- #endregion
- #region MatrixSize
- //获得放大倍数
- int a_MatrixSize = 0;
- Size size = new Size();
- //获取参数
- 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);
- }
- }
- catch (Exception ex)
- {
- NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
- }
- return GetImgCount;
- }
- }
- }
- }
|