OTSControlFunExport.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. //EDS Interface
  291. //获取EDS名称
  292. //函数名称:GetEDSName()
  293. //输入参数:无
  294. //输出参数:类型:int,设备ID标识
  295. String^ GetEDSName()
  296. {
  297. CString a_str = (m_pEDS->GetName());
  298. String^ strOut = gcnew String(a_str);
  299. return strOut;
  300. }
  301. //获取EDS类型,Bruker是3.
  302. //函数名称:int EDSGetType()
  303. //输入参数:无
  304. //输出参数:类型:int,设备ID标识
  305. int EDSGetType()
  306. {
  307. int a_type = (int)EDSController::EDS_ID::BRUKER;
  308. return a_type;
  309. }
  310. //EDS初始化
  311. //函数名称:bool EDSInit()
  312. //输入参数:无
  313. //输出参数:类型:bool,true,设备申请成功
  314. // false,设备申请失败
  315. bool EDSInit()
  316. {
  317. bool bRet = m_pEDS->Init();
  318. return bRet;
  319. }
  320. //是否支持Xray采集
  321. //函数名称:bool IsSupportSetCollection()
  322. //输入参数:无
  323. //输出参数:类型:bool,true,支持采集
  324. // false,不支持采集
  325. bool IsSupportSetCollection()
  326. {
  327. bool bRet = m_pEDS->IsSupportSetCollection();
  328. return bRet;
  329. }
  330. bool CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, array<unsigned long>^% a_XrayData);
  331. bool CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize);
  332. bool CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData);
  333. bool GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant);
  334. bool GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<COTSParticleClr^>^ parts, bool bQuant);
  335. bool GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  336. bool GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSFeatureClr^>^ feas,array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant);
  337. bool GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSParticleClr^>^ parts, bool bQuant);
  338. bool GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant);
  339. // analysis elements
  340. bool GetXRayElements(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  341. // analysis elements
  342. bool GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult);
  343. /// Set Amp Time Index for all detectors
  344. bool SetAmpTimeIndex(long a_lvalue)
  345. {
  346. bool bRet = m_pEDS->SetAmpTimeIndex(a_lvalue);
  347. return bRet;
  348. }
  349. /// get live time
  350. float GetLiveTime(void)
  351. {
  352. float fRet = m_pEDS->GetLiveTime();
  353. return fRet;
  354. }
  355. /// get x-ray point collection limit
  356. long GetMaxPointLimit(void)
  357. {
  358. long lRet = m_pEDS->GetMaxPointLimit();
  359. return lRet;
  360. }
  361. DWORD GetNumberOfChannels(void)
  362. {
  363. DWORD nRet = m_pEDS->GetNumberOfChannels();
  364. return nRet;
  365. }
  366. //获取图像数据14741238434
  367. int AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array<System::Byte>^% a_ImgData);
  368. //获取图像数据14741238434
  369. bool AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, CBSEImgClr^% a_ImgData)
  370. {
  371. /*int bRet = 0;
  372. CSize sz;*/
  373. //int height, width;
  374. CBSEImgPtr pbseImg = nullptr;
  375. pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell);
  376. a_ImgData = gcnew CBSEImgClr(pbseImg);
  377. return true;
  378. }
  379. // 初始化
  380. bool ScanInit()
  381. {
  382. bool bRet = m_pScan->Init();
  383. return bRet;
  384. }
  385. int GetScanType()
  386. {
  387. int nRet = (int)ScanController::SCANNER_ID::BRUKER;
  388. return nRet;
  389. }
  390. Size GetMatrixSize(int a_nMatrixIndex)
  391. {
  392. CSize cs;
  393. cs = m_pScan->GetMatrixSize(a_nMatrixIndex);
  394. Size aa;
  395. aa.Height = (int)cs.cy;
  396. aa.Width = (int)cs.cx;
  397. return aa;
  398. }
  399. // Start Scan Table
  400. bool StartScanTable(int a_nMatrixIndex, unsigned int nP, array<System::Int16>^ pnxx, array<System::Int16>^ pnyy)
  401. {
  402. int*pnx = new int[nP];
  403. int*pny = new int[nP];
  404. memset(pnx, 0, sizeof(int)*nP);
  405. memset(pny, 0, sizeof(int)*nP);
  406. bool bRet = false;
  407. if (m_pScan->StartScanTable(a_nMatrixIndex, nP, pnx, pny))
  408. {
  409. for (int i = 0; i <(int) nP; i++)
  410. {
  411. pnxx[i] = pnx[i];
  412. pnyy[i] = pny[i];
  413. }
  414. bRet = true;
  415. }
  416. else
  417. {
  418. bRet = false;
  419. }
  420. delete[] pny;
  421. delete[] pnx;
  422. return bRet;
  423. }
  424. // set Image Size
  425. bool SetImageSize(long nWidth,long nHeight)
  426. {
  427. bool bRet = m_pScan->SetImageSize(nWidth,nHeight);
  428. return bRet;
  429. }
  430. /// set dwell time
  431. bool SetDwellTime(long nDwellTime)
  432. {
  433. bool bRet = m_pScan->SetDwellTime(nDwellTime);
  434. return bRet;
  435. }
  436. long GetDwellTimeByIndex(const long a_nIndex)
  437. {
  438. long lRet = m_pScan->GetDwellTimeByIndex(a_nIndex);
  439. return lRet;
  440. }
  441. bool SetDwellTimeByIndex(const long a_nIndex)
  442. {
  443. bool bRet = m_pScan->SetDwellTimeByIndex(a_nIndex);
  444. return bRet;
  445. }
  446. bool SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  447. {
  448. bool bRet =(bool)m_pScan->SetScanFieldSize(a_nWidth, a_nHeight);
  449. return bRet;
  450. }
  451. bool SetEMPosition(const int a_nPosX, const int a_nPosY)
  452. {
  453. bool bRet = (bool)m_pScan->SetScanFieldSize(a_nPosX, a_nPosY);
  454. return bRet;
  455. }
  456. Size GetScanRange()
  457. {
  458. CSize cs = m_pScan->GetScanRange();
  459. Size aa;
  460. aa.Height = (int)cs.cx;
  461. aa.Width = (int)cs.cy;
  462. return aa;
  463. }
  464. int GetScanStepSize()
  465. {
  466. int nRet = m_pScan->GetScanStepSize();
  467. return nRet;
  468. }
  469. int GetInterPixelDwell()
  470. {
  471. int nRet = m_pScan->GetInterPixelDwell();
  472. return nRet;
  473. }
  474. int GetNumberOfReads()
  475. {
  476. int nRet = m_pScan->GetNumberOfReads();
  477. return nRet;
  478. }
  479. double GetMagnification()
  480. {
  481. double nRet = m_pScan->GetMagnification();
  482. return nRet;
  483. }
  484. void SetScanRange(Size cs)
  485. {
  486. CSize sz;
  487. sz.cx = (LONG)cs.Height;
  488. sz.cy = (LONG)cs.Width;
  489. m_pScan->SetScanRange(sz);
  490. }
  491. void SetScanStepSize(int size)
  492. {
  493. m_pScan->SetScanStepSize(size);
  494. }
  495. void SetInterPixelDwell(int i)
  496. {
  497. m_pScan->SetInterPixelDwell(i);
  498. }
  499. void SetNumberOfReads(int i)
  500. {
  501. m_pScan->SetNumberOfReads(i);
  502. }
  503. void SetMagnification(double mag)
  504. {
  505. m_pScan->SetMagnification(mag);
  506. }
  507. bool ScanIsBruker()
  508. {
  509. bool bRet = (bool)m_pScan->IsBruker();
  510. return bRet;
  511. }
  512. bool MoveBeamTo(Point a_beamPos)
  513. {
  514. CPoint pt;
  515. pt.x = a_beamPos.X;
  516. pt.y = a_beamPos.Y;
  517. bool bRet = (bool)m_pScan->MoveBeamTo(pt);
  518. return bRet;
  519. }
  520. bool SetPointScan(int a_nMatrixIndex)
  521. {
  522. bool bRet = (bool)m_pScan->SetPointScan(a_nMatrixIndex);
  523. return bRet;
  524. }
  525. private:
  526. COTSControlFunExport()
  527. {
  528. m_pHardWareMgr = new COTSHardwareMgr();
  529. m_pSem = (m_pHardWareMgr->GetSemControllerMgrPtr()).get();
  530. m_pScan = (m_pHardWareMgr->GetScanControllerPtr()).get();
  531. m_pEDS = (m_pHardWareMgr->GetEDSControllerPtr()).get();
  532. }
  533. COTSSemBase* m_pSem;
  534. COTSScanBase* m_pScan;
  535. COTSEDSBase* m_pEDS;
  536. COTSHardwareMgr* m_pHardWareMgr;
  537. static COTSControlFunExport^ theInstance=nullptr;
  538. };
  539. }