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