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