OTSControlFunExport.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. //获得焦点尺寸
  272. bool GetSemSpotSize(double% a_dSpotSize)
  273. {
  274. double dPSize = 0;
  275. BOOL bRev = m_pSem->GetSpotSize(dPSize);
  276. a_dSpotSize = dPSize;
  277. return bRev;
  278. }
  279. //设置焦点尺寸
  280. bool SetSemSpotSize(double a_dSpotSize)
  281. {
  282. BOOL bRev = m_pSem->SetSpotSize(a_dSpotSize);
  283. return bRev;
  284. }
  285. // 获得扫描方式
  286. bool GetSemScanMode(long% a_nScanMode)
  287. {
  288. long lSMode = 0;
  289. BOOL bRev = m_pSem->GetScanMode(lSMode);
  290. a_nScanMode = lSMode;
  291. return bRev;
  292. }
  293. //设置扫描方式
  294. bool SetSemScanMode(long a_nScanMode)
  295. {
  296. BOOL bRev = m_pSem->SetScanMode(a_nScanMode);
  297. return bRev;
  298. }
  299. bool SetSemScanExternal(bool external)
  300. {
  301. bool bRev = false;
  302. try
  303. {
  304. bRev = m_pSem->SetScanExternal(external);
  305. }
  306. catch (const std::exception&)
  307. {
  308. bRev = false;
  309. }
  310. return bRev;
  311. }
  312. int GetSemExternalMode()
  313. {
  314. BOOL bRev = m_pSem->GetExternalMode();
  315. return bRev;
  316. }
  317. //移动电镜到指定的位置
  318. bool MoveSEMToPoint(double dPosX, double dPosY, double dRotation)
  319. {
  320. //double dRota = dRotation;
  321. CPoint cPos;
  322. cPos.x = (LONG)dPosX;
  323. cPos.y = (LONG)dPosY;
  324. bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation);
  325. return bRev;
  326. }
  327. //移动电镜到指定的位置
  328. bool MoveSEMToPoint(double dPosX, double dPosY)
  329. {
  330. double dRotation;
  331. CPoint cPos;
  332. cPos.x = (LONG)dPosX;
  333. cPos.y = (LONG)dPosY;
  334. bool bRev = m_pSem->MoveSEMToPoint(cPos, dRotation);
  335. return bRev;
  336. }
  337. //EDS Interface
  338. //获取EDS名称
  339. //函数名称:GetEDSName()
  340. //输入参数:无
  341. //输出参数:类型:int,设备ID标识
  342. String^ GetEDSName()
  343. {
  344. CString a_str = (m_pEDS->GetName());
  345. String^ strOut = gcnew String(a_str);
  346. return strOut;
  347. }
  348. //获取EDS类型,Bruker是3.
  349. //函数名称:int EDSGetType()
  350. //输入参数:无
  351. //输出参数:类型:int,设备ID标识
  352. int EDSGetType()
  353. {
  354. int a_type = (int)EDSController::EDS_ID::BRUKER;
  355. return a_type;
  356. }
  357. //是否支持Xray采集
  358. //函数名称:bool IsSupportSetCollection()
  359. //输入参数:无
  360. //输出参数:类型:bool,true,支持采集
  361. // false,不支持采集
  362. bool IsSupportSetCollection()
  363. {
  364. bool bRet = m_pEDS->IsSupportSetCollection();
  365. return bRet;
  366. }
  367. bool CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, array<unsigned long>^% a_XrayData);
  368. bool CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize);
  369. bool CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData);
  370. bool GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant);
  371. bool GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<COTSParticleClr^>^ parts, bool bQuant);
  372. bool GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  373. bool GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSFeatureClr^>^ feas,array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant);
  374. bool GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSParticleClr^>^ parts, bool bQuant);
  375. bool GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  376. // analysis elements
  377. bool GetXRayElements(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  378. // analysis elements
  379. bool GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  380. /// Set Amp Time Index for all detectors
  381. bool SetAmpTimeIndex(long a_lvalue)
  382. {
  383. bool bRet = m_pEDS->SetAmpTimeIndex(a_lvalue);
  384. return bRet;
  385. }
  386. /// get live time
  387. float GetLiveTime(void)
  388. {
  389. float fRet = m_pEDS->GetLiveTime();
  390. return fRet;
  391. }
  392. /// get x-ray point collection limit
  393. long GetMaxPointLimit(void)
  394. {
  395. long lRet = m_pEDS->GetMaxPointLimit();
  396. return lRet;
  397. }
  398. DWORD GetNumberOfChannels(void)
  399. {
  400. DWORD nRet = m_pEDS->GetNumberOfChannels();
  401. return nRet;
  402. }
  403. //获取图像数据14741238434
  404. int AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array<System::Byte>^% a_ImgData);
  405. //获取图像数据14741238434
  406. bool AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, CBSEImgClr^% a_ImgData)
  407. {
  408. /*int bRet = 0;
  409. CSize sz;*/
  410. //int height, width;
  411. CBSEImgPtr pbseImg = nullptr;
  412. pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell);
  413. if (pbseImg == nullptr)
  414. {
  415. return false;
  416. }
  417. a_ImgData = gcnew CBSEImgClr(pbseImg);
  418. return true;
  419. }
  420. int GetScanType()
  421. {
  422. int nRet = (int)ScanController::SCANNER_ID::BRUKER;
  423. return nRet;
  424. }
  425. Size GetMatrixSize(int a_nMatrixIndex)
  426. {
  427. CSize cs;
  428. cs = m_pScan->GetMatrixSize(a_nMatrixIndex);
  429. Size aa;
  430. aa.Height = (int)cs.cy;
  431. aa.Width = (int)cs.cx;
  432. return aa;
  433. }
  434. // Start Scan Table
  435. bool StartScanTable(int a_nMatrixIndex, unsigned int nP, array<System::Int16>^ pnxx, array<System::Int16>^ pnyy)
  436. {
  437. int*pnx = new int[nP];
  438. int*pny = new int[nP];
  439. memset(pnx, 0, sizeof(int)*nP);
  440. memset(pny, 0, sizeof(int)*nP);
  441. bool bRet = false;
  442. if (m_pScan->StartScanTable(a_nMatrixIndex, nP, pnx, pny))
  443. {
  444. for (int i = 0; i <(int) nP; i++)
  445. {
  446. pnxx[i] = pnx[i];
  447. pnyy[i] = pny[i];
  448. }
  449. bRet = true;
  450. }
  451. else
  452. {
  453. bRet = false;
  454. }
  455. delete[] pny;
  456. delete[] pnx;
  457. return bRet;
  458. }
  459. // set Image Size
  460. bool SetImageSize(long nWidth,long nHeight)
  461. {
  462. bool bRet = m_pScan->SetImageSize(nWidth,nHeight);
  463. return bRet;
  464. }
  465. /// set dwell time
  466. bool SetDwellTime(long nDwellTime)
  467. {
  468. bool bRet = m_pScan->SetDwellTime(nDwellTime);
  469. return bRet;
  470. }
  471. long GetDwellTimeByIndex(const long a_nIndex)
  472. {
  473. long lRet = m_pScan->GetDwellTimeByIndex(a_nIndex);
  474. return lRet;
  475. }
  476. bool SetDwellTimeByIndex(const long a_nIndex)
  477. {
  478. bool bRet = m_pScan->SetDwellTimeByIndex(a_nIndex);
  479. return bRet;
  480. }
  481. bool SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  482. {
  483. bool bRet =(bool)m_pScan->SetScanFieldSize(a_nWidth, a_nHeight);
  484. return bRet;
  485. }
  486. bool SetEMPosition(const int a_nPosX, const int a_nPosY)
  487. {
  488. bool bRet = (bool)m_pScan->SetScanFieldSize(a_nPosX, a_nPosY);
  489. return bRet;
  490. }
  491. Size GetScanRange()
  492. {
  493. CSize cs = m_pScan->GetScanRange();
  494. Size aa;
  495. aa.Height = (int)cs.cx;
  496. aa.Width = (int)cs.cy;
  497. return aa;
  498. }
  499. int GetScanStepSize()
  500. {
  501. int nRet = m_pScan->GetScanStepSize();
  502. return nRet;
  503. }
  504. int GetInterPixelDwell()
  505. {
  506. int nRet = m_pScan->GetInterPixelDwell();
  507. return nRet;
  508. }
  509. int GetNumberOfReads()
  510. {
  511. int nRet = m_pScan->GetNumberOfReads();
  512. return nRet;
  513. }
  514. double GetMagnification()
  515. {
  516. double nRet = m_pScan->GetMagnification();
  517. return nRet;
  518. }
  519. void SetScanRange(Size cs)
  520. {
  521. CSize sz;
  522. sz.cx = (LONG)cs.Height;
  523. sz.cy = (LONG)cs.Width;
  524. m_pScan->SetScanRange(sz);
  525. }
  526. void SetScanStepSize(int size)
  527. {
  528. m_pScan->SetScanStepSize(size);
  529. }
  530. void SetInterPixelDwell(int i)
  531. {
  532. m_pScan->SetInterPixelDwell(i);
  533. }
  534. void SetNumberOfReads(int i)
  535. {
  536. m_pScan->SetNumberOfReads(i);
  537. }
  538. void SetMagnification(double mag)
  539. {
  540. m_pScan->SetMagnification(mag);
  541. }
  542. bool ScanIsBruker()
  543. {
  544. bool bRet = (bool)m_pScan->IsBruker();
  545. return bRet;
  546. }
  547. bool MoveBeamTo(Point a_beamPos)
  548. {
  549. CPoint pt;
  550. pt.x = a_beamPos.X;
  551. pt.y = a_beamPos.Y;
  552. bool bRet = (bool)m_pScan->MoveBeamTo(pt);
  553. return bRet;
  554. }
  555. bool SetPointScan(int a_nMatrixIndex)
  556. {
  557. bool bRet = (bool)m_pScan->SetPointScan(a_nMatrixIndex);
  558. return bRet;
  559. }
  560. private:
  561. COTSControlFunExport()
  562. {
  563. m_pHardWareMgr = new COTSHardwareMgr();
  564. }
  565. COTSSemBase* m_pSem;
  566. COTSScanBase* m_pScan;
  567. COTSEDSBase* m_pEDS;
  568. COTSHardwareMgr* m_pHardWareMgr;
  569. static COTSControlFunExport^ theInstance=nullptr;
  570. };
  571. }