OTSBrukerImpl.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #pragma once
  2. #include "OTSSingleton.h"
  3. // Load ClientDll
  4. #include "OTSBrukerImpl_const.h"
  5. #include "OTSBrukerClientDll.h"
  6. #include "otsdataconst.h"
  7. #include "Element.h"
  8. #include "BSEImg.h"
  9. #include "PosXray.h"
  10. #include "OTSFeature.h"
  11. using namespace OTSDATA;
  12. namespace OTSController {
  13. typedef enum class __declspec(dllexport) CONTROL_TYPE
  14. {
  15. BRUKER_SEM = 0, //든쓸�구
  16. BRUKER_SCAN = 1, //暠獗�췄친욥
  17. BRUKER_XRAY = 2 //X-RAY친욥
  18. } CONTROL_TYPE;
  19. typedef enum class __declspec(dllexport) BRUKER_PARAM
  20. {
  21. BUF_LENGTH = 1024,
  22. MAX_SEGMENTS = 8192,
  23. MAX_PIXEL_MICROSECONDS = 32000,
  24. RT_SPECTRUM_BUFFER_SIZE = 64000, // SpectrumBufferSize
  25. RT_SPECTRUM_CHANNELS = 2000, // XANA_CHANNELS = 2000,
  26. RT_SPECTRUM_CHANNELS_LONG = 3000 // RT_SPECTRUM_CHANNELS_LONG = 3000,
  27. } BRUKER_PARAM;
  28. class COTSBrukerImpl : public Singleton<COTSBrukerImpl>, public boost::noncopyable
  29. {
  30. public:
  31. // constructor
  32. COTSBrukerImpl();
  33. // destructor
  34. ~COTSBrukerImpl();
  35. // initialization
  36. BOOL Init(CONTROL_TYPE a_nControlType, BOOL a_b32Bite = TRUE);
  37. BOOL DisConnect();
  38. // check connection
  39. BOOL CheckConnection(BOOL& a_bConnected);
  40. // SEM functions
  41. // SEM Data (mag, KV and working distance)
  42. BOOL GetSEMData(double& a_dMagnification, double& a_dHighVoltage, double& a_dWorkingDistance);
  43. BOOL SetSEMData(double a_dMagnification, double a_dHighVoltage, double a_dWorkingDistance);
  44. // SEM BC Data (brightness and contrast)
  45. BOOL GetSEMBCData(double& a_dBrightness, double& a_dContrast);
  46. BOOL SetSEMBCData(double a_dBrightness, double a_dContrast);
  47. // Probe Current
  48. BOOL GetProbeCurrent(double&);
  49. BOOL SetProbeCurrent(double);
  50. // spot size
  51. BOOL GetSEMSpotSize(double& a_dSpotSize);
  52. BOOL SetSEMSpotSize(double a_dSpotSize);
  53. // stage data
  54. BOOL GetSEMStageData(double& a_nPositionX, double& a_nPositionY, double& a_nPositionZ, double& a_dTilt, double& a_dRotation);
  55. BOOL SetSEMStageData(double a_nPositionX, double a_nPositionY, double a_nPositionZ, double a_dTilt, double a_dRotation);
  56. // external on/off
  57. BOOL SetSEMExternalOn(void);
  58. BOOL SetSEMExternalOff(void);
  59. // get scan Mode
  60. BOOL GetScanMode(long& a_nScanMode);
  61. // set scan mode
  62. BOOL SetScanMode(long a_nScanMode);
  63. // Switch SEM Off
  64. BOOL SwitchSEMOff(BOOL a_bHTValue, BOOL a_bBeamCurrent, BOOL a_bBeamBlank);
  65. // imaging functions
  66. // Get and set image config - dimensions, dwell time and enabled channels
  67. BOOL ImageGetConfiguration(DWORD& a_nWidth, DWORD& a_nHeight, DWORD& a_nAverage, BYTE& a_bCh1, BYTE& a_bCh2);
  68. BOOL ImageSetConfiguration(DWORD a_nWidth, DWORD a_nHeight, DWORD a_nAverage, BYTE a_bCh1, BYTE a_bCh2);
  69. // image collection, using the size and dwell time that was last set
  70. CBSEImgPtr AcquireImage();
  71. // set point
  72. BOOL ImageSetPoint(const CPoint& a_oPoint);
  73. // x-ray functions
  74. // live time
  75. float GetLiveTime(void);
  76. BOOL GetLiveRealTime(float& a_dLiveTime, float& a_dRealTime);
  77. // collect spectrum data by timeB
  78. BOOL CollectSpectrum(DWORD a_nMilliSeconds, long* a_pCounts, DWORD a_nBufferSize);
  79. // collect spectrum data by timeB and quantify
  80. BOOL QuantifySpectrumOut(DWORD a_nMilliSeconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistries);
  81. // quantify spectrum
  82. BOOL QuantifySpectrum(char* a_pcMethod, char* a_pcParams, char* a_pcResultBuffer, long a_nBufferSize);
  83. // collect x-ray
  84. BOOL CollectXRayPoints(std::vector<CPosXray*>& a_vXPoints, DWORD a_nACTimeMS);
  85. BOOL CollectXRayPoints(CPosXraysList& a_listXrayPois, DWORD a_nACTimeMS);
  86. BOOL CollectXRayPointsByFeatures(std::vector<CPosXray*>& a_vXPoints, std::vector<std::vector<BrukerSegment>>& a_vFeatures, DWORD a_nACTimeMS);
  87. BOOL ReadXRayPoints(std::vector<CPosXray*>& a_vXPoints, const DWORD a_nACTimeMS);
  88. BOOL ReadXRayPoints(CPosXraysList& a_listXrayPois, const DWORD a_nACTimeMS);
  89. BOOL ReadXRayPointsByFeature(std::vector<CPosXray*>& a_vXPoints, const DWORD a_nACTimeMS);
  90. BOOL ReadXRayPointsByFeature(CPosXraysList& a_vXPoints, const DWORD a_nACTimeMS);
  91. BOOL CollectOneXRayPoint(const CPoint& a_oPoi, DWORD a_nLifeTimeMilliSeconds, long* a_pnCounts, DWORD a_nBufferSize, bool a_bSetHeadStruc = FALSE);
  92. // spectrum measurement
  93. BOOL StartSpectrumMeasurement();
  94. BOOL IsSpectrumMeterRunning(BOOL& a_bRunning);
  95. BOOL StopSpectrumMeasure(void);
  96. BOOL ReadSpectrum(long* a_pnCounts, DWORD a_nBufferSize);
  97. // get quantification method name
  98. BOOL GetQuantificationMethods(std::vector<CString>& a_vMethods);
  99. BOOL QuantifyXrayPoint(CPosXray* a_pXRayPoint, CString a_strMethodName);
  100. BOOL QuantifySpectrumFile(LPCTSTR a_sFilePathName, CString a_strMethodName, CElementChemistriesList& a_vElementChemistry);
  101. RTSpectrumHeaderRec* GetSectrumHeader();
  102. // if do x-ray quantification
  103. BOOL GetQuantificationFlag() { return m_bDoQuantification; }
  104. void SetQuantificationFlag(BOOL a_bDoQuantification) { m_bDoQuantification = a_bDoQuantification; }
  105. // m_bDoQuantification should be set first.
  106. BOOL GetXRayByPoints(CPosXraysList& a_listXrayPois, DWORD a_nACTimeMS);
  107. BOOL SetXRayPoints(CPosXraysList& a_listXrayPois, const DWORD a_nACTimeMS);
  108. BOOL GetXRayByFeatures(CPosXraysList& a_vXPoints, std::vector<BrukerFeature> a_vFeatures, DWORD a_nACTimeMS);
  109. BOOL SetXRayPointsByFeature(CPosXraysList& a_vXPoints, const DWORD a_nACTimeMS);
  110. protected:
  111. // close client
  112. BOOL CloseClient(void);//there's no need to call from out ,the single instance destruction method will call it automatically.
  113. BOOL GetSpectrum(long a_nBufferIndex, RTSpectrumHeaderRec* a_poSpcHR, long a_nBufferSize);
  114. BOOL LoadSpectrum(char* a_sFilePathName);
  115. BOOL ReadSpectrum(void);
  116. BOOL PutSpectrum(char* m_pBuffer, long a_nBufferSize);
  117. BOOL CreateSpectrum(char* m_pParamBuffer, RTSpectrumHeaderRec* a_poSpcHR, char* m_pResultBuffer, long& a_nBufferSize);
  118. BOOL ShowSpectrum(long a_nBufferIndex, char* a_pSpectumName);
  119. BOOL GetSpectrometerParams(long a_nBufferIndex, char* a_pcBuffer, long& a_nBufferSize);
  120. BOOL GetElementChemistryData(CElementChemistry& a_oElementChemistryData, CString a_strElementChemistry);
  121. BOOL CopySpectrum(long* a_pnCounts, DWORD a_nBufferSize);
  122. BOOL StartSpectrumLifeTimeMeasurement(DWORD a_nLifeTime);
  123. BOOL SpectrumLifeTimeMeasurement(DWORD a_nLifeTime);
  124. BOOL StartSpectrumRealTimeMeasurement(DWORD a_nRealTime);
  125. BOOL SpectrumRealTimeMeasurement(DWORD a_nRealTime);
  126. BOOL SpectrumCountsMeasurement(DWORD a_nCounts, int a_nTimeLimit = -1);
  127. BOOL ConvertSpectrum(RTSpectrumHeaderRec* a_poSpcHR, long* a_pnCounts, DWORD a_nBufferSize);
  128. BOOL GetPointListSpectrum(long a_nIndex, long* a_pnSpec);
  129. BOOL GetFeatureListSpectrum(long a_nIndex, long* a_pnSpec);
  130. BOOL StartPointListMeasurement(DWORD a_nSegmentCount, BrukerSegment* a_poSegment, DWORD m_nMilliseconds);
  131. BOOL StartFeatureListMeasurement(DWORD a_nFeatureCount, BrukerFeature* a_poFeature, WORD* a_pwdPixelTimes);
  132. BOOL CheckDetectorState(long a_nDetectorId, BOOL& a_bState, long& a_nMaxEnergy);
  133. /// set SPU (used for send command to multi-detector system) value
  134. BOOL SetSPU(void);
  135. // open client
  136. BOOL OpenClient(void);
  137. BOOL OpenClient(char*, char*, char*, BYTE, BYTE, DWORD*);
  138. // query server
  139. BOOL QueryServers(void);
  140. //// instance termination
  141. //void FinishedInstance(void); // this is to delete it
  142. CString GetQuantificationSpectrumPathName();
  143. //Get Load Dll Name
  144. BOOL GetLoadDllName(CString& csDllName);
  145. // spectrum header
  146. RTSpectrumHeaderRec* m_pSpectrumHead;
  147. //
  148. std::shared_ptr<OTSBrukerClientDll> m_pBrukerDllHandle;
  149. std::shared_ptr<char> m_psServerName; // server name
  150. BOOL m_bInit; // initialize flag
  151. BOOL m_bSEMInst; // SEM instance
  152. BOOL m_bScannerInst; // scanner instance
  153. BOOL m_bXRAyControllerInst; // x ray instance
  154. std::shared_ptr<char> m_psRTSpectrumBuffer; // this is used to get spectrum from detector
  155. DWORD m_nClientID;
  156. BOOL m_bSEMExternal;
  157. int m_nSPU;
  158. BOOL m_bConnected;
  159. BOOL m_bDoQuantification; // if do x-ray quantification
  160. BOOL m_bShowQuantificationSpectrum;
  161. };
  162. }