OTSControlFunExport.h 14 KB

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