OTSControlFunExport.h 14 KB

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