OTSControlFunExport.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. #pragma once
  2. /**
  3. @file
  4. @brief OTSControl DLL Interface provide for C#
  5. @author xiaoxing.zhang,Anna Hao
  6. @version 1.0.0.0
  7. @date 2017/6/28
  8. - 2017/6/28 1.0.0.0 xiaoxing.zhang developed SEM Interface
  9. - 2017/6/28 1.0.0.0 Anna Hao developed Scan Interface
  10. - 2017/6/29 1.0.0.0 Anna Hao developed EDS Interface
  11. - 2017/7/3 1.0.0.0 xiaoxing.zhang Add log for SemInterface
  12. - 2021 gaoshipeng revised. complete the whole interface so that we can get all infomation through this interface in C#.
  13. */
  14. #include "BSEImg.h"
  15. #include "COTSHardwareMgr.h"
  16. #include "Bruker/OTSBrukerImpl_const.h"
  17. #include <OTSFeatureClr.h>
  18. #include <BSEImgClr.h>
  19. #include <OTSParticleClr.h>
  20. using namespace System;
  21. using namespace System::Drawing;
  22. using namespace System::Collections::Generic;
  23. namespace OTSCLRINTERFACE
  24. {
  25. using namespace OTSController;
  26. public ref class COTSControlFunExport
  27. {
  28. public:
  29. static COTSControlFunExport^ GetControllerInstance()
  30. {
  31. if (theInstance == nullptr)
  32. {
  33. theInstance = gcnew COTSControlFunExport();
  34. }
  35. return theInstance;
  36. }
  37. ~COTSControlFunExport()
  38. {
  39. if (nullptr != m_pHardWareMgr)
  40. {
  41. delete m_pHardWareMgr;
  42. m_pHardWareMgr = nullptr;
  43. }
  44. }
  45. !COTSControlFunExport()
  46. {
  47. if (nullptr != m_pHardWareMgr)
  48. {
  49. delete m_pHardWareMgr;
  50. m_pHardWareMgr = nullptr;
  51. }
  52. }
  53. //get the hardware object according to the configure file.
  54. bool Init()
  55. {
  56. m_pSem = (m_pHardWareMgr->GetSemControllerMgrPtr()).get();
  57. m_pScan = (m_pHardWareMgr->GetScanControllerPtr()).get();
  58. m_pEDS = (m_pHardWareMgr->GetEDSControllerPtr()).get();
  59. if (m_pSem == nullptr || m_pScan == nullptr || m_pEDS == nullptr)
  60. {
  61. return false;
  62. }
  63. else
  64. {
  65. return true;
  66. }
  67. }
  68. //和电镜建立通讯连接
  69. bool ConncetSem()
  70. {
  71. if (!Init())
  72. {
  73. return false;
  74. }
  75. if (m_pSem->IsConnected())
  76. {
  77. return true;
  78. }
  79. BOOL bRev = m_pSem->Connect();
  80. if (bRev)
  81. {
  82. if (ScanInit() && EDSInit())
  83. {
  84. return true;
  85. }
  86. else
  87. {
  88. return false;
  89. }
  90. }
  91. return bRev;
  92. }
  93. bool DisconnectSem()
  94. {
  95. BOOL bRev = m_pSem->Disconnect();
  96. return bRev;
  97. }
  98. bool IsConnected()
  99. {
  100. BOOL bRev = false;
  101. if(m_pSem != nullptr)
  102. {
  103. bRev = m_pSem->IsConnected();
  104. }
  105. return bRev;
  106. }
  107. // 初始化
  108. bool ScanInit()
  109. {
  110. bool bRet = m_pScan->Init();
  111. return bRet;
  112. }
  113. //EDS初始化
  114. //函数名称:bool EDSInit()
  115. //输入参数:无
  116. //输出参数:类型:bool,true,设备申请成功
  117. // false,设备申请失败
  118. bool EDSInit()
  119. {
  120. bool bRet = m_pEDS->Init();
  121. return bRet;
  122. }
  123. //获取当前电镜的ID号
  124. int GetSemType()
  125. {
  126. int ID = 0;
  127. ID = (int)m_pSem->GetType();
  128. return ID;
  129. }
  130. //获得扫描区域大小
  131. Size GetSemScanField100()
  132. {
  133. Size sz;
  134. CSize size = m_pSem->GetScanField100();
  135. sz.Width = size.cx;
  136. sz.Height = size.cy;
  137. return sz;
  138. }
  139. //设置扫描区域大小
  140. void SetSemScanField100(Size sz)
  141. {
  142. CSize size;
  143. size.cx = sz.Width;
  144. size.cy = sz.Height;
  145. m_pSem->SetScanField100(size);
  146. }
  147. bool GetSemBeamBlank(long% a_nBeamBlank)
  148. {
  149. long lBBlank = 0;
  150. BOOL bRev = m_pSem->GetBeamBlank(lBBlank);
  151. a_nBeamBlank = lBBlank;
  152. return bRev;
  153. }
  154. bool SetSemBeamBlank(bool a_nBeamBlank)
  155. {
  156. BOOL bRev = m_pSem->SetBeamBlank(a_nBeamBlank);
  157. return bRev;
  158. }
  159. bool SetSemBeamCurrent(bool a_nBeamCurrent)
  160. {
  161. bool bRev = true;
  162. bRev = m_pSem->SetBeamBlank(a_nBeamCurrent);
  163. return bRev;
  164. }
  165. //获得亮度
  166. bool GetSemBrightness(double% a_dBrightness)
  167. {
  168. double dBriness = 0;
  169. BOOL bRev = m_pSem->GetBrightness(dBriness);
  170. a_dBrightness = dBriness;
  171. return bRev;
  172. }
  173. //设置亮度
  174. bool SetSemBrightness(double a_dBrightness)
  175. {
  176. BOOL bRev = m_pSem->SetBrightness(a_dBrightness);
  177. return bRev;
  178. }
  179. //获得对比度
  180. bool GetSemContrast(double% a_dContrast)
  181. {
  182. double dContrast = 0;
  183. BOOL bRev = m_pSem->GetContrast(dContrast);
  184. a_dContrast = dContrast;
  185. return bRev;
  186. }
  187. //设置对比度
  188. bool SetSemContrast(double a_dContrast)
  189. {
  190. BOOL bRev = m_pSem->SetContrast(a_dContrast);
  191. return bRev;
  192. }
  193. //获得Z轴的工作距离
  194. bool GetSemWorkingDistance(double% a_dWorkingDistance)
  195. {
  196. double dWDistance = 0;
  197. BOOL bRev = m_pSem->GetWorkingDistance(dWDistance);
  198. a_dWorkingDistance = dWDistance;
  199. return bRev;
  200. }
  201. // 设置Z轴工作距离
  202. bool SetSemWorkingDistance(double a_dWorkingDistance)
  203. {
  204. BOOL bRev = m_pSem->SetWorkingDistance(a_dWorkingDistance);
  205. return bRev;
  206. }
  207. // 获得电压值
  208. bool GetSemHighTension(double% a_dKV)
  209. {
  210. double dDKV = 0;
  211. BOOL bRev = m_pSem->GetHighTension(dDKV);
  212. a_dKV = dDKV;
  213. return bRev;
  214. }
  215. // 设置电压值
  216. bool SetSemHighTension(double a_dKV)
  217. {
  218. BOOL bRev = m_pSem->SetHighTension(a_dKV);
  219. return bRev;
  220. }
  221. //获得放大倍数
  222. bool GetSemMagnification(double% a_dMagnification)
  223. {
  224. double dMagni = 0;
  225. BOOL bRev = m_pSem->GetMagnification(dMagni);
  226. a_dMagnification = dMagni;
  227. return bRev;
  228. }
  229. //设置放大倍数
  230. bool SetSemMagnification(double a_dMagnification)
  231. {
  232. BOOL bRev = m_pSem->SetMagnification(a_dMagnification);
  233. return bRev;
  234. }
  235. //获得扫描区域尺寸
  236. bool GetSemScanFieldSize(double% a_dScanFieldSizeX, double% a_dScanFieldSizeY)
  237. {
  238. double dFSizeX = 0;
  239. double dFSizeY = 0;
  240. BOOL bRev = m_pSem->GetScanFieldSize(dFSizeX, dFSizeY);
  241. a_dScanFieldSizeX = dFSizeX;
  242. a_dScanFieldSizeY = dFSizeY;
  243. return bRev;
  244. }
  245. //设置扫描区域尺寸
  246. bool SetSemScanFieldSizeX(double a_dScanFieldSizeX)
  247. {
  248. BOOL bRev = m_pSem->SetScanFieldSizeX(a_dScanFieldSizeX);
  249. return bRev;
  250. }
  251. bool GetSemHTOnOff(bool% a_bHTValue)
  252. {
  253. BOOL bHTV = FALSE;
  254. BOOL bRev = m_pSem->GetHTOnOff(bHTV);
  255. a_bHTValue = bHTV;
  256. return bRev;
  257. }
  258. bool SetSemHTOnOff(bool a_bHTValue)
  259. {
  260. bool bRev = m_pSem->SetHTOnOff(a_bHTValue);
  261. return bRev;
  262. }
  263. //获得电镜位置
  264. bool GetSemPositionXY(double% a_dPositionX, double% a_dPositionY, double% a_dPositionR)
  265. {
  266. double dPosX = 0;
  267. double dPosY = 0;
  268. double dPosR = 0;
  269. BOOL bRev = m_pSem->GetPositionXY(dPosX, dPosY, dPosR);
  270. a_dPositionX = dPosX;
  271. a_dPositionY = dPosY;
  272. a_dPositionR = dPosR;
  273. return bRev;
  274. }
  275. //设置电镜位置
  276. bool SetSemPositionXY(double a_dPositionX, double a_dPositionY, double a_dPositionR)
  277. {
  278. BOOL bRev = m_pSem->SetPositionXY(a_dPositionX, a_dPositionY, a_dPositionR);
  279. return bRev;
  280. }
  281. bool SetSemPositionXY(double a_dPositionX, double a_dPositionY)
  282. {
  283. BOOL bRev = m_pSem->SetPositionXY(a_dPositionX, a_dPositionY);
  284. return bRev;
  285. }
  286. //获得焦点尺寸
  287. bool GetSemSpotSize(double% a_dSpotSize)
  288. {
  289. double dPSize = 0;
  290. BOOL bRev = m_pSem->GetSpotSize(dPSize);
  291. a_dSpotSize = dPSize;
  292. return bRev;
  293. }
  294. //设置焦点尺寸
  295. bool SetSemSpotSize(double a_dSpotSize)
  296. {
  297. BOOL bRev = m_pSem->SetSpotSize(a_dSpotSize);
  298. return bRev;
  299. }
  300. // 获得扫描方式
  301. bool GetSemScanMode(long% a_nScanMode)
  302. {
  303. long lSMode = 0;
  304. BOOL bRev = m_pSem->GetScanMode(lSMode);
  305. a_nScanMode = lSMode;
  306. return bRev;
  307. }
  308. //设置扫描方式
  309. bool SetSemScanMode(long a_nScanMode)
  310. {
  311. BOOL bRev = m_pSem->SetScanMode(a_nScanMode);
  312. return bRev;
  313. }
  314. bool SetSemScanExternal(bool external)
  315. {
  316. bool bRev = false;
  317. try
  318. {
  319. bRev = m_pSem->SetScanExternal(external);
  320. }
  321. catch (const std::exception&)
  322. {
  323. bRev = false;
  324. }
  325. return bRev;
  326. }
  327. int GetSemExternalMode()
  328. {
  329. BOOL bRev = m_pSem->GetExternalMode();
  330. return bRev;
  331. }
  332. //移动电镜到指定的位置
  333. bool MoveSEMToPoint(double dPosX, double dPosY, double dRotation)
  334. {
  335. //double dRota = dRotation;
  336. CPoint cPos;
  337. cPos.x = (LONG)dPosX;
  338. cPos.y = (LONG)dPosY;
  339. bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation);
  340. return bRev;
  341. }
  342. //移动电镜到指定的位置
  343. bool MoveSEMToPoint(double dPosX, double dPosY)
  344. {
  345. double dRotation;
  346. CPoint cPos;
  347. cPos.x = (LONG)dPosX;
  348. cPos.y = (LONG)dPosY;
  349. bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation);
  350. return bRev;
  351. }
  352. //EDS Interface
  353. //获取EDS名称
  354. //函数名称:GetEDSName()
  355. //输入参数:无
  356. //输出参数:类型:int,设备ID标识
  357. String^ GetEDSName()
  358. {
  359. CString a_str = (m_pEDS->GetName());
  360. String^ strOut = gcnew String(a_str);
  361. return strOut;
  362. }
  363. //获取EDS类型,Bruker是3.
  364. //函数名称:int EDSGetType()
  365. //输入参数:无
  366. //输出参数:类型:int,设备ID标识
  367. int EDSGetType()
  368. {
  369. int a_type=(int)m_pEDS->GetType();
  370. //int a_type = (int)EDSController::EDS_ID::BRUKER;
  371. return a_type;
  372. }
  373. //是否支持Xray采集
  374. //函数名称:bool IsSupportSetCollection()
  375. //输入参数:无
  376. //输出参数:类型:bool,true,支持采集
  377. // false,不支持采集
  378. bool IsSupportSetCollection()
  379. {
  380. bool bRet = m_pEDS->IsSupportSetCollection();
  381. return bRet;
  382. }
  383. bool CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, cli::array<unsigned long>^% a_XrayData);
  384. bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize);
  385. bool CollectSpectrum(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData);
  386. bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array<CPosXrayClr^>^% a_XrayData, bool bQuant);
  387. bool GetXRayByPoints(unsigned long a_nMilliseconds, cli::array<Point>^ points, cli::array<COTSParticleClr^>^ parts, bool bQuant);
  388. bool GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  389. 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);
  390. bool GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array<COTSParticleClr^>^ parts, bool bQuant);
  391. bool GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  392. // analysis elements
  393. //bool GetXRayElements(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  394. // analysis elements
  395. bool GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, cli::array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  396. /// Set Amp Time Index for all detectors
  397. bool SetAmpTimeIndex(long a_lvalue)
  398. {
  399. bool bRet = m_pEDS->SetAmpTimeIndex(a_lvalue);
  400. return bRet;
  401. }
  402. /// get live time
  403. float GetLiveTime(void)
  404. {
  405. float fRet = m_pEDS->GetLiveTime();
  406. return fRet;
  407. }
  408. /// get x-ray point collection limit
  409. long GetMaxPointLimit(void)
  410. {
  411. long lRet = m_pEDS->GetMaxPointLimit();
  412. return lRet;
  413. }
  414. DWORD GetNumberOfChannels(void)
  415. {
  416. DWORD nRet = m_pEDS->GetNumberOfChannels();
  417. return nRet;
  418. }
  419. //获取图像数据14741238434
  420. int AcquireBSEImage( cli::array<System::Byte>^% a_ImgData);
  421. //获取图像数据14741238434
  422. bool AcquireBSEImage( CBSEImgClr^% a_ImgData)
  423. {
  424. /*int bRet = 0;
  425. CSize sz;*/
  426. //int height, width;
  427. CBSEImgPtr pbseImg = nullptr;
  428. pbseImg = m_pScan->AcquireBSEImage();
  429. if (pbseImg == nullptr)
  430. {
  431. return false;
  432. }
  433. a_ImgData = gcnew CBSEImgClr(pbseImg);
  434. return true;
  435. }
  436. int GetScanType()
  437. {
  438. int nRet = (int)ScanController::SCANNER_ID::BRUKER;
  439. return nRet;
  440. }
  441. Size GetMatrixSize(int a_nMatrixIndex)
  442. {
  443. CSize cs;
  444. cs = m_pScan->GetMatrixSize(a_nMatrixIndex);
  445. Size aa;
  446. aa.Height = (int)cs.cy;
  447. aa.Width = (int)cs.cx;
  448. return aa;
  449. }
  450. // Start Scan Table
  451. bool StartScanTable(int a_nMatrixIndex, unsigned int nP, cli::array<System::Int16>^ pnxx, cli::array<System::Int16>^ pnyy)
  452. {
  453. int*pnx = new int[nP];
  454. int*pny = new int[nP];
  455. memset(pnx, 0, sizeof(int)*nP);
  456. memset(pny, 0, sizeof(int)*nP);
  457. bool bRet = false;
  458. if (m_pScan->StartScanTable(a_nMatrixIndex, nP, pnx, pny))
  459. {
  460. for (int i = 0; i <(int) nP; i++)
  461. {
  462. pnxx[i] = pnx[i];
  463. pnyy[i] = pny[i];
  464. }
  465. bRet = true;
  466. }
  467. else
  468. {
  469. bRet = false;
  470. }
  471. delete[] pny;
  472. delete[] pnx;
  473. return bRet;
  474. }
  475. // set Image Size
  476. bool SetImageSize(long nWidth,long nHeight)
  477. {
  478. bool bRet = m_pScan->SetImageSize(nWidth,nHeight);
  479. return bRet;
  480. }
  481. /// set dwell time
  482. bool SetDwellTime(long nDwellTime)
  483. {
  484. bool bRet = m_pScan->SetDwellTime(nDwellTime);
  485. return bRet;
  486. }
  487. long GetDwellTimeByIndex(const long a_nIndex)
  488. {
  489. long lRet = m_pScan->GetDwellTimeByIndex(a_nIndex);
  490. return lRet;
  491. }
  492. bool SetDwellTimeByIndex(const long a_nIndex)
  493. {
  494. bool bRet = m_pScan->SetDwellTimeByIndex(a_nIndex);
  495. return bRet;
  496. }
  497. bool SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  498. {
  499. bool bRet =(bool)m_pScan->SetScanFieldSize(a_nWidth, a_nHeight);
  500. return bRet;
  501. }
  502. bool SetEMPosition(const int a_nPosX, const int a_nPosY)
  503. {
  504. bool bRet = (bool)m_pScan->SetScanFieldSize(a_nPosX, a_nPosY);
  505. return bRet;
  506. }
  507. Size GetScanRange()
  508. {
  509. CSize cs = m_pScan->GetScanRange();
  510. Size aa;
  511. aa.Height = (int)cs.cx;
  512. aa.Width = (int)cs.cy;
  513. return aa;
  514. }
  515. int GetScanStepSize()
  516. {
  517. int nRet = m_pScan->GetScanStepSize();
  518. return nRet;
  519. }
  520. int GetInterPixelDwell()
  521. {
  522. int nRet = m_pScan->GetInterPixelDwell();
  523. return nRet;
  524. }
  525. int GetNumberOfReads()
  526. {
  527. int nRet = m_pScan->GetNumberOfReads();
  528. return nRet;
  529. }
  530. double GetMagnification()
  531. {
  532. double nRet = m_pScan->GetMagnification();
  533. return nRet;
  534. }
  535. void SetScanRange(Size cs)
  536. {
  537. CSize sz;
  538. sz.cx = (LONG)cs.Height;
  539. sz.cy = (LONG)cs.Width;
  540. m_pScan->SetScanRange(sz);
  541. }
  542. void SetScanStepSize(int size)
  543. {
  544. m_pScan->SetScanStepSize(size);
  545. }
  546. void SetInterPixelDwell(int i)
  547. {
  548. m_pScan->SetInterPixelDwell(i);
  549. }
  550. void SetNumberOfReads(int i)
  551. {
  552. m_pScan->SetNumberOfReads(i);
  553. }
  554. void SetMagnification(double mag)
  555. {
  556. m_pScan->SetMagnification(mag);
  557. }
  558. bool ScanIsBruker()
  559. {
  560. bool bRet = (bool)m_pScan->IsBruker();
  561. return bRet;
  562. }
  563. bool MoveBeamTo(Point a_beamPos)
  564. {
  565. CPoint pt;
  566. pt.x = a_beamPos.X;
  567. pt.y = a_beamPos.Y;
  568. bool bRet = (bool)m_pScan->MoveBeamTo(pt);
  569. return bRet;
  570. }
  571. bool SetPointScan(int a_nMatrixIndex)
  572. {
  573. bool bRet = (bool)m_pScan->SetPointScan(a_nMatrixIndex);
  574. return bRet;
  575. }
  576. bool StopXrayAcquisition()
  577. {
  578. bool bRet = (bool)m_pEDS->StopXrayAcquistion();
  579. return bRet;
  580. }
  581. private:
  582. COTSControlFunExport()
  583. {
  584. m_pHardWareMgr = new COTSHardwareMgr();
  585. }
  586. COTSSemBase* m_pSem;
  587. COTSScanBase* m_pScan;
  588. COTSEDSBase* m_pEDS;
  589. COTSHardwareMgr* m_pHardWareMgr;
  590. static COTSControlFunExport^ theInstance=nullptr;
  591. };
  592. }