123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777 |
- #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 <OTSFeatureClr.h>
- #include <BSEImgClr.h>
- #include <OTSParticleClr.h>
- 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<unsigned long>^% a_XrayData);
- bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize);
-
- bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData);
- bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array<CPosXrayClr^>^% a_XrayData, bool bQuant);
-
- bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array<Point>^ points, cli::array<COTSParticleClr^>^ parts, bool bQuant);
-
- bool GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
-
-
- bool GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array<COTSFeatureClr^>^ feas,cli::array<cli::array<unsigned long>^>^% a_XrayData, cli::array<String^>^% a_strEleResult, bool bQuant);
- bool GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array<COTSParticleClr^>^ parts, bool bQuant);
- bool GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
- // analysis elements
- //bool GetXRayElements(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
-
- // analysis elements
- bool GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, cli::array<unsigned long>^% 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<System::Byte>^% 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<System::Int16>^ pnxx, cli::array<System::Int16>^ 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;
- };
- }
|