OTSControlFunExport.h 14 KB

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