#pragma once /** @file @brief OTSControl DLL Interface provide for C# @author xiaoxing.zhang,Anna Hao @version 1.0.0.0 @date 2017/6/28 - 2017/6/28 1.0.0.0 xiaoxing.zhang developed SEM Interface - 2017/6/28 1.0.0.0 Anna Hao developed Scan Interface - 2017/6/29 1.0.0.0 Anna Hao developed EDS Interface - 2017/7/3 1.0.0.0 xiaoxing.zhang Add log for SemInterface - 2021 gaoshipeng revised. complete the whole interface so that we can get all infomation through this interface in C#. */ #include "BSEImg.h" #include "COTSHardwareMgr.h" #include "Bruker/OTSBrukerImpl_const.h" #include #include #include using namespace System; using namespace System::Drawing; using namespace System::Collections::Generic; namespace OTSCLRINTERFACE { using namespace OTSController; public ref class COTSControlFunExport { public: static COTSControlFunExport^ GetControllerInstance() { if (theInstance == nullptr) { theInstance = gcnew COTSControlFunExport(); } return theInstance; } ~COTSControlFunExport() { if (nullptr != m_pHardWareMgr) { delete m_pHardWareMgr; m_pHardWareMgr = nullptr; } } !COTSControlFunExport() { if (nullptr != m_pHardWareMgr) { delete m_pHardWareMgr; m_pHardWareMgr = nullptr; } } //get the hardware object according to the configure file. bool Init() { m_pSem = (m_pHardWareMgr->GetSemControllerMgrPtr()).get(); m_pScan = (m_pHardWareMgr->GetScanControllerPtr()).get(); m_pEDS = (m_pHardWareMgr->GetEDSControllerPtr()).get(); if (m_pSem == nullptr || m_pScan == nullptr || m_pEDS == nullptr) { return false; } else { return true; } } //和电镜建立通讯连接 bool ConncetSem() { if (!Init()) { return false; } if (m_pSem->IsConnected()) { return true; } BOOL bRev = m_pSem->Connect(); if (bRev) { if (ScanInit() && EDSInit()) { return true; } else { return false; } } return bRev; } bool DisconnectSem() { BOOL bRev = m_pSem->Disconnect(); return bRev; } bool IsConnected() { BOOL bRev = false; if(m_pSem != nullptr) { bRev = m_pSem->IsConnected(); } return bRev; } // 初始化 bool ScanInit() { bool bRet = m_pScan->Init(); return bRet; } //EDS初始化 //函数名称:bool EDSInit() //输入参数:无 //输出参数:类型:bool,true,设备申请成功 // false,设备申请失败 bool EDSInit() { bool bRet = m_pEDS->Init(); return bRet; } //获取当前电镜的ID号 int GetSemType() { int ID = 0; ID = (int)m_pSem->GetType(); return ID; } //获得扫描区域大小 Size GetSemScanField100() { Size sz; CSize size = m_pSem->GetScanField100(); sz.Width = size.cx; sz.Height = size.cy; return sz; } //设置扫描区域大小 void SetSemScanField100(Size sz) { CSize size; size.cx = sz.Width; size.cy = sz.Height; m_pSem->SetScanField100(size); } bool GetSemBeamBlank(long% a_nBeamBlank) { long lBBlank = 0; BOOL bRev = m_pSem->GetBeamBlank(lBBlank); a_nBeamBlank = lBBlank; return bRev; } bool SetSemBeamBlank(bool a_nBeamBlank) { BOOL bRev = m_pSem->SetBeamBlank(a_nBeamBlank); return bRev; } bool SetSemBeamCurrent(bool a_nBeamCurrent) { bool bRev = true; bRev = m_pSem->SetBeamBlank(a_nBeamCurrent); return bRev; } //获得亮度 bool GetSemBrightness(double% a_dBrightness) { double dBriness = 0; BOOL bRev = m_pSem->GetBrightness(dBriness); a_dBrightness = dBriness; return bRev; } //设置亮度 bool SetSemBrightness(double a_dBrightness) { BOOL bRev = m_pSem->SetBrightness(a_dBrightness); return bRev; } //获得对比度 bool GetSemContrast(double% a_dContrast) { double dContrast = 0; BOOL bRev = m_pSem->GetContrast(dContrast); a_dContrast = dContrast; return bRev; } //设置对比度 bool SetSemContrast(double a_dContrast) { BOOL bRev = m_pSem->SetContrast(a_dContrast); return bRev; } //获得Z轴的工作距离 bool GetSemWorkingDistance(double% a_dWorkingDistance) { double dWDistance = 0; BOOL bRev = m_pSem->GetWorkingDistance(dWDistance); a_dWorkingDistance = dWDistance; return bRev; } // 设置Z轴工作距离 bool SetSemWorkingDistance(double a_dWorkingDistance) { BOOL bRev = m_pSem->SetWorkingDistance(a_dWorkingDistance); return bRev; } // 获得电压值 bool GetSemHighTension(double% a_dKV) { double dDKV = 0; BOOL bRev = m_pSem->GetHighTension(dDKV); a_dKV = dDKV; return bRev; } // 设置电压值 bool SetSemHighTension(double a_dKV) { BOOL bRev = m_pSem->SetHighTension(a_dKV); return bRev; } //获得放大倍数 bool GetSemMagnification(double% a_dMagnification) { double dMagni = 0; BOOL bRev = m_pSem->GetMagnification(dMagni); a_dMagnification = dMagni; return bRev; } //设置放大倍数 bool SetSemMagnification(double a_dMagnification) { BOOL bRev = m_pSem->SetMagnification(a_dMagnification); return bRev; } //获得扫描区域尺寸 bool GetSemScanFieldSize(double% a_dScanFieldSizeX, double% a_dScanFieldSizeY) { double dFSizeX = 0; double dFSizeY = 0; BOOL bRev = m_pSem->GetScanFieldSize(dFSizeX, dFSizeY); a_dScanFieldSizeX = dFSizeX; a_dScanFieldSizeY = dFSizeY; return bRev; } //设置扫描区域尺寸 bool SetSemScanFieldSizeX(double a_dScanFieldSizeX) { BOOL bRev = m_pSem->SetScanFieldSizeX(a_dScanFieldSizeX); return bRev; } bool GetSemHTOnOff(bool% a_bHTValue) { BOOL bHTV = FALSE; BOOL bRev = m_pSem->GetHTOnOff(bHTV); a_bHTValue = bHTV; return bRev; } bool SetSemHTOnOff(bool a_bHTValue) { bool bRev = m_pSem->SetHTOnOff(a_bHTValue); return bRev; } //获得电镜位置 bool GetSemPositionXY(double% a_dPositionX, double% a_dPositionY, double% a_dPositionR) { double dPosX = 0; double dPosY = 0; double dPosR = 0; BOOL bRev = m_pSem->GetPositionXY(dPosX, dPosY, dPosR); a_dPositionX = dPosX; a_dPositionY = dPosY; a_dPositionR = dPosR; return bRev; } //设置电镜位置 bool SetSemPositionXY(double a_dPositionX, double a_dPositionY, double a_dPositionR) { BOOL bRev = m_pSem->SetPositionXY(a_dPositionX, a_dPositionY, a_dPositionR); return bRev; } bool SetSemPositionXY(double a_dPositionX, double a_dPositionY) { BOOL bRev = m_pSem->SetPositionXY(a_dPositionX, a_dPositionY); return bRev; } //获得焦点尺寸 bool GetSemSpotSize(double% a_dSpotSize) { double dPSize = 0; BOOL bRev = m_pSem->GetSpotSize(dPSize); a_dSpotSize = dPSize; return bRev; } //设置焦点尺寸 bool SetSemSpotSize(double a_dSpotSize) { BOOL bRev = m_pSem->SetSpotSize(a_dSpotSize); return bRev; } // 获得扫描方式 bool GetSemScanMode(long% a_nScanMode) { long lSMode = 0; BOOL bRev = m_pSem->GetScanMode(lSMode); a_nScanMode = lSMode; return bRev; } //设置扫描方式 bool SetSemScanMode(long a_nScanMode) { BOOL bRev = m_pSem->SetScanMode(a_nScanMode); return bRev; } bool SetSemScanExternal(bool external) { bool bRev = false; try { bRev = m_pSem->SetScanExternal(external); } catch (const std::exception&) { bRev = false; } return bRev; } int GetSemExternalMode() { BOOL bRev = m_pSem->GetExternalMode(); return bRev; } //移动电镜到指定的位置 bool MoveSEMToPoint(double dPosX, double dPosY, double dRotation) { //double dRota = dRotation; CPoint cPos; cPos.x = (LONG)dPosX; cPos.y = (LONG)dPosY; bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation); return bRev; } //移动电镜到指定的位置 bool MoveSEMToPoint(double dPosX, double dPosY) { double dRotation; CPoint cPos; cPos.x = (LONG)dPosX; cPos.y = (LONG)dPosY; bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation); return bRev; } //EDS Interface //获取EDS名称 //函数名称:GetEDSName() //输入参数:无 //输出参数:类型:int,设备ID标识 String^ GetEDSName() { CString a_str = (m_pEDS->GetName()); String^ strOut = gcnew String(a_str); return strOut; } //获取EDS类型,Bruker是3. //函数名称:int EDSGetType() //输入参数:无 //输出参数:类型:int,设备ID标识 int EDSGetType() { int a_type=(int)m_pEDS->GetType(); //int a_type = (int)EDSController::EDS_ID::BRUKER; return a_type; } //是否支持Xray采集 //函数名称:bool IsSupportSetCollection() //输入参数:无 //输出参数:类型:bool,true,支持采集 // false,不支持采集 bool IsSupportSetCollection() { bool bRet = m_pEDS->IsSupportSetCollection(); return bRet; } bool CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, cli::array^% a_XrayData); bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array^% a_XrayData, unsigned long a_nBufferSize); bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array^% a_XrayData); bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array^% a_XrayData, bool bQuant); bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array^ points, cli::array^ parts, bool bQuant); bool GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, cli::array^% a_XrayData, String^% a_strEleResult, bool bQuant); bool GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array^ feas,cli::array^>^% a_XrayData, cli::array^% a_strEleResult, bool bQuant); bool GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array^ parts, bool bQuant); bool GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, cli::array^% a_XrayData, String^% a_strEleResult, bool bQuant); // analysis elements //bool GetXRayElements(unsigned long a_nMilliseconds, cli::array^% a_XrayData, int^% a_nElementNum, String^% a_strResult); // analysis elements bool GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, cli::array^% a_XrayData, int^% a_nElementNum, String^% a_strResult); /// Set Amp Time Index for all detectors bool SetAmpTimeIndex(long a_lvalue) { bool bRet = m_pEDS->SetAmpTimeIndex(a_lvalue); return bRet; } /// get live time float GetLiveTime(void) { float fRet = m_pEDS->GetLiveTime(); return fRet; } /// get x-ray point collection limit long GetMaxPointLimit(void) { long lRet = m_pEDS->GetMaxPointLimit(); return lRet; } DWORD GetNumberOfChannels(void) { DWORD nRet = m_pEDS->GetNumberOfChannels(); return nRet; } //获取图像数据14741238434 int AcquireBSEImage( cli::array^% a_ImgData); //获取图像数据14741238434 bool AcquireBSEImage( CBSEImgClr^% a_ImgData) { /*int bRet = 0; CSize sz;*/ //int height, width; CBSEImgPtr pbseImg = nullptr; pbseImg = m_pScan->AcquireBSEImage(); if (pbseImg == nullptr) { return false; } a_ImgData = gcnew CBSEImgClr(pbseImg); return true; } int GetScanType() { int nRet = (int)ScanController::SCANNER_ID::BRUKER; return nRet; } Size GetMatrixSize(int a_nMatrixIndex) { CSize cs; cs = m_pScan->GetMatrixSize(a_nMatrixIndex); Size aa; aa.Height = (int)cs.cy; aa.Width = (int)cs.cx; return aa; } // Start Scan Table bool StartScanTable(int a_nMatrixIndex, unsigned int nP, cli::array^ pnxx, cli::array^ pnyy) { int*pnx = new int[nP]; int*pny = new int[nP]; memset(pnx, 0, sizeof(int)*nP); memset(pny, 0, sizeof(int)*nP); bool bRet = false; if (m_pScan->StartScanTable(a_nMatrixIndex, nP, pnx, pny)) { for (int i = 0; i <(int) nP; i++) { pnxx[i] = pnx[i]; pnyy[i] = pny[i]; } bRet = true; } else { bRet = false; } delete[] pny; delete[] pnx; return bRet; } // set Image Size bool SetImageSize(long nWidth,long nHeight) { bool bRet = m_pScan->SetImageSize(nWidth,nHeight); return bRet; } /// set dwell time bool SetDwellTime(long nDwellTime) { bool bRet = m_pScan->SetDwellTime(nDwellTime); return bRet; } long GetDwellTimeByIndex(const long a_nIndex) { long lRet = m_pScan->GetDwellTimeByIndex(a_nIndex); return lRet; } bool SetDwellTimeByIndex(const long a_nIndex) { bool bRet = m_pScan->SetDwellTimeByIndex(a_nIndex); return bRet; } bool SetScanFieldSize(const int a_nWidth, const int a_nHeight) { bool bRet =(bool)m_pScan->SetScanFieldSize(a_nWidth, a_nHeight); return bRet; } bool SetEMPosition(const int a_nPosX, const int a_nPosY) { bool bRet = (bool)m_pScan->SetScanFieldSize(a_nPosX, a_nPosY); return bRet; } Size GetScanRange() { CSize cs = m_pScan->GetScanRange(); Size aa; aa.Height = (int)cs.cx; aa.Width = (int)cs.cy; return aa; } int GetScanStepSize() { int nRet = m_pScan->GetScanStepSize(); return nRet; } int GetInterPixelDwell() { int nRet = m_pScan->GetInterPixelDwell(); return nRet; } int GetNumberOfReads() { int nRet = m_pScan->GetNumberOfReads(); return nRet; } double GetMagnification() { double nRet = m_pScan->GetMagnification(); return nRet; } void SetScanRange(Size cs) { CSize sz; sz.cx = (LONG)cs.Height; sz.cy = (LONG)cs.Width; m_pScan->SetScanRange(sz); } void SetScanStepSize(int size) { m_pScan->SetScanStepSize(size); } void SetInterPixelDwell(int i) { m_pScan->SetInterPixelDwell(i); } void SetNumberOfReads(int i) { m_pScan->SetNumberOfReads(i); } void SetMagnification(double mag) { m_pScan->SetMagnification(mag); } bool ScanIsBruker() { bool bRet = (bool)m_pScan->IsBruker(); return bRet; } bool MoveBeamTo(Point a_beamPos) { CPoint pt; pt.x = a_beamPos.X; pt.y = a_beamPos.Y; bool bRet = (bool)m_pScan->MoveBeamTo(pt); return bRet; } bool SetPointScan(int a_nMatrixIndex) { bool bRet = (bool)m_pScan->SetPointScan(a_nMatrixIndex); return bRet; } bool StopXrayAcquisition() { bool bRet = (bool)m_pEDS->StopXrayAcquistion(); return bRet; } private: COTSControlFunExport() { m_pHardWareMgr = new COTSHardwareMgr(); } COTSSemBase* m_pSem; COTSScanBase* m_pScan; COTSEDSBase* m_pEDS; COTSHardwareMgr* m_pHardWareMgr; static COTSControlFunExport^ theInstance=nullptr; }; }