OTSControlFunExport.h 13 KB

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