OTSControlFunExport.h 14 KB

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