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