OTSControlFunExport.h 14 KB

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