OTSControlFunExport.h 14 KB

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