CBrukerImpl.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using Bruker.API;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OTSMeasureApp.ServiceCenter.BrukerCSharp
  8. {
  9. public class COTSBrukerImpl
  10. {
  11. // constructor
  12. COTSBrukerImpl()
  13. { }
  14. // destructor
  15. ~COTSBrukerImpl()
  16. { }
  17. // initialization
  18. bool Init( bool a_b32Bite = true)
  19. {
  20. }
  21. bool DisConnect()
  22. { }
  23. // check connection
  24. bool CheckConnection(bool a_bConnected);
  25. void SetExpectCount(int expectCount)
  26. int GetExpectCount();
  27. // SEM functions
  28. // SEM Data (mag, KV and working distance)
  29. BOOL GetSEMData(double& a_dMagnification, double& a_dHighVoltage, double& a_dWorkingDistance);
  30. BOOL SetSEMData(double a_dMagnification, double a_dHighVoltage, double a_dWorkingDistance);
  31. // SEM BC Data (brightness and contrast)
  32. BOOL GetSEMBCData(double& a_dBrightness, double& a_dContrast);
  33. BOOL SetSEMBCData(double a_dBrightness, double a_dContrast);
  34. // Probe Current
  35. BOOL GetProbeCurrent(double&);
  36. BOOL SetProbeCurrent(double);
  37. // spot size
  38. BOOL GetSEMSpotSize(double& a_dSpotSize);
  39. BOOL SetSEMSpotSize(double a_dSpotSize);
  40. // stage data
  41. BOOL GetSEMStageData(double& a_nPositionX, double& a_nPositionY, double& a_nPositionZ, double& a_dTilt, double& a_dRotation);
  42. BOOL SetSEMStageData(double a_nPositionX, double a_nPositionY, double a_nPositionZ, double a_dTilt, double a_dRotation);
  43. // external on/off
  44. BOOL SetSEMExternalOn(void);
  45. BOOL SetSEMExternalOff(void);
  46. // get scan Mode
  47. BOOL GetScanMode(long& a_nScanMode);
  48. // set scan mode
  49. BOOL SetScanMode(long a_nScanMode);
  50. // Switch SEM Off
  51. BOOL SwitchSEMOff(BOOL a_bHTValue, BOOL a_bBeamCurrent, BOOL a_bBeamBlank);
  52. // imaging functions
  53. // Get and set image config - dimensions, dwell time and enabled channels
  54. BOOL ImageGetConfiguration(DWORD& a_nWidth, DWORD& a_nHeight, DWORD& a_nAverage, BYTE& a_bCh1, BYTE& a_bCh2);
  55. BOOL ImageSetConfiguration(DWORD a_nWidth, DWORD a_nHeight, DWORD a_nAverage, BYTE a_bCh1, BYTE a_bCh2);
  56. // image collection, using the size and dwell time that was last set
  57. CBSEImgPtr AcquireImage();
  58. // set point
  59. BOOL ImageSetPoint(const CPoint& a_oPoint);
  60. // x-ray functions
  61. // live time
  62. float GetLiveTime(void);
  63. BOOL GetLiveRealTime(float& a_dLiveTime, float& a_dRealTime);
  64. // collect spectrum data by timeB
  65. BOOL CollectSpectrum(DWORD a_nMilliSeconds, long* a_pCounts, DWORD a_nBufferSize);
  66. // collect spectrum data by timeB and quantify
  67. BOOL QuantifySpectrumOut(DWORD a_nMilliSeconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistries);
  68. // quantify spectrum
  69. BOOL QuantifySpectrum(char* a_pcMethod, char* a_pcParams, char* a_pcResultBuffer, long a_nBufferSize);
  70. // collect x-ray
  71. BOOL CollectXRayPoints(std::vector<CPosXray*>& a_vXPoints, DWORD a_nACTimeMS);
  72. BOOL CollectXRayPoints(CPosXrayList& a_listXrayPois, DWORD a_nACTimeMS);
  73. BOOL CollectXRayPointsByFeatures(std::vector<CPosXray*>& a_vXPoints, std::vector<BrukerFeature>& a_vFeatures, DWORD a_nACTimeMS);
  74. BOOL ReadXRayPoints(std::vector<CPosXray*>& a_vXPoints, const DWORD a_nACTimeMS);
  75. BOOL ReadXRayPoints(CPosXrayList& a_listXrayPois, const DWORD a_nACTimeMS);
  76. BOOL ReadXRayPointsByFeature(std::vector<CPosXray*>& a_vXPoints, const DWORD a_nACTimeMS);
  77. BOOL ReadXRayPointsByFeature(CPosXrayList& a_vXPoints, const DWORD a_nACTimeMS);
  78. BOOL CollectOneXRayPoint(const CPoint& a_oPoi, DWORD a_nLifeTimeMilliSeconds, long* a_pnCounts, DWORD a_nBufferSize, bool a_bSetHeadStruc = FALSE);
  79. // spectrum measurement
  80. BOOL StartSpectrumMeasurement();
  81. BOOL IsSpectrumMeterRunning(BOOL& a_bRunning);
  82. BOOL StopSpectrumMeasure(void);
  83. BOOL ReadSpectrum(long* a_pnCounts, DWORD a_nBufferSize);
  84. // get quantification method name
  85. BOOL GetQuantificationMethods(std::vector<CString>& a_vMethods);
  86. BOOL QuantifyXrayPoint(CPosXray* a_pXRayPoint, CString a_strMethodName);
  87. BOOL QuantifySpectrumFile(LPCTSTR a_sFilePathName, CString a_strMethodName, CElementChemistriesList& a_vElementChemistry);
  88. BOOL QuantifyPosXrayPointsOnLine(std::vector<CPosXrayPtr>& a_vXRayParts);//delay quantifying so the next field's stage moving and BSE aquisition can be executed in the same time.
  89. BOOL QuantifyPosXrayPointOnLine(CPosXrayPtr a_vXRayPart);//delay quantifying
  90. RTSpectrumHeaderRec* GetSectrumHeader();
  91. // if do x-ray quantification
  92. BOOL GetQuantificationFlag() { return m_bDoQuantification; }
  93. void SetQuantificationFlag(BOOL a_bDoQuantification) { m_bDoQuantification = a_bDoQuantification; }
  94. // m_bDoQuantification should be set first.
  95. BOOL GetXRayByPoints(CPosXrayList& a_listXrayPois, DWORD a_nACTimeMS);
  96. BOOL SetXRayPoints(CPosXrayList& a_listXrayPois/*, const DWORD a_nACTimeMS*/);
  97. BOOL GetXRayByFeatures(CPosXrayList& a_vXPoints, std::vector<BrukerFeature> a_vFeatures, SHORT a_nACTimeMS);
  98. BOOL SetXRayPointsByFeature(CPosXrayList& a_vXPoints, const DWORD a_nACTimeMS);
  99. protected:
  100. // close client
  101. BOOL CloseClient(void);//there's no need to call from out ,the single instance destruction method will call it automatically.
  102. BOOL GetSpectrum(long a_nBufferIndex, BrukerDll::PRTSpectrumHeaderRec a_poSpcHR, long a_nBufferSize);
  103. BOOL LoadSpectrum(char* a_sFilePathName);
  104. BOOL ReadSpectrum(void);
  105. BOOL PutSpectrum(char* m_pBuffer, long a_nBufferSize);
  106. BOOL CreateSpectrum(char* m_pParamBuffer, BrukerDll::PRTSpectrumHeaderRec a_poSpcHR, char* m_pResultBuffer, int32_t& a_nBufferSize);
  107. BOOL ShowSpectrum(long a_nBufferIndex, char* a_pSpectumName);
  108. BOOL GetSpectrometerParams(long a_nBufferIndex, char* a_pcBuffer, int32_t& a_nBufferSize);
  109. BOOL GetElementChemistryData(CElementChemistry& a_oElementChemistryData, CString a_strElementChemistry);
  110. BOOL CopySpectrum(long* a_pnCounts, DWORD a_nBufferSize);
  111. BOOL StartSpectrumLifeTimeMeasurement(DWORD a_nLifeTime);
  112. BOOL SpectrumLifeTimeMeasurement(DWORD a_nLifeTime);
  113. BOOL StartSpectrumRealTimeMeasurement(DWORD a_nRealTime);
  114. BOOL SpectrumRealTimeMeasurement(DWORD a_nRealTime);
  115. BOOL SpectrumCountsMeasurement(DWORD a_nCounts, int a_nTimeLimit = -1);
  116. BOOL ConvertSpectrum(RTSpectrumHeaderRec* a_poSpcHR, long* a_pnCounts, DWORD a_nBufferSize);
  117. BOOL GetPointListSpectrum(long a_nIndex, long* a_pnSpec);
  118. BOOL GetFeatureListSpectrum(long a_nIndex, long* a_pnSpec);
  119. BOOL StartPointListMeasurement(DWORD a_nSegmentCount, BrukerDll::PSegmentList a_poSegment, DWORD m_nMilliseconds);
  120. BOOL StartFeatureListMeasurement(DWORD a_nFeatureCount, BrukerDll::PFeatureDataList a_poFeature, SHORT** a_pwdPixelTimes);
  121. BOOL CheckDetectorState(long a_nDetectorId, BOOL& a_bState, uint32_t& a_nMaxEnergy);
  122. /// set SPU (used for send command to multi-detector system) value
  123. BOOL SetSPU(void);
  124. // open client
  125. BOOL OpenClient(void);
  126. BOOL OpenClient(char*, char*, char*, BYTE, BYTE, uint32_t&);
  127. // query server
  128. BOOL QueryBrukerServers(void);
  129. //// instance termination
  130. //void FinishedInstance(void); // this is to delete it
  131. CString GetQuantificationSpectrumPathName();
  132. //Get Load Dll Name
  133. BOOL GetLoadDllName(CString& csDllName);
  134. // spectrum header
  135. TRTSpectrumHeaderRec m_pSpectrumHead;
  136. //
  137. //std::shared_ptr<OTSBrukerClientDll> m_pBrukerDllHandle;
  138. std::shared_ptr<char> m_psServerName; // server name
  139. BOOL m_bInit; // initialize flag
  140. BOOL m_bSEMInst; // SEM instance
  141. BOOL m_bScannerInst; // scanner instance
  142. BOOL m_bXRAyControllerInst; // x ray instance
  143. std::shared_ptr<char> m_psRTSpectrumBuffer; // this is used to get spectrum from detector
  144. uint32_t m_nClientID;
  145. BOOL m_bSEMExternal;
  146. int m_nSPU;
  147. BOOL m_bConnected;
  148. BOOL m_bDoQuantification; // if do x-ray quantification
  149. BOOL m_bShowQuantificationSpectrum;
  150. int m_expectCount;
  151. }
  152. }