OTSControlFunExport.h 14 KB

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