OTSEDSBrucker.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. #include "stdafx.h"
  2. #include "OTSEDSBrucker.h"
  3. namespace OTSController {
  4. // constructor
  5. COTSEDSBrucker::COTSEDSBrucker(void)
  6. {
  7. }
  8. // destructor
  9. COTSEDSBrucker::~COTSEDSBrucker(void)
  10. {
  11. }
  12. // initialization
  13. BOOL COTSEDSBrucker::Init()
  14. {
  15. // create bruker controller if necessary
  16. if (!m_pBrukerImpl)
  17. {
  18. // create bruker controller
  19. m_pBrukerImpl = COTSBrukerImpl::GetInstance();
  20. }
  21. // check if bruker controller is alright
  22. ASSERT(m_pBrukerImpl);
  23. if (!m_pBrukerImpl)
  24. {
  25. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::Init: failed to create bruker controller."));
  26. return FALSE;
  27. }
  28. // initialize bruker controller (as xray controller)
  29. if (!m_pBrukerImpl->Init(CONTROL_TYPE::BRUKER_XRAY))
  30. {
  31. // failed to initialize bruker controller
  32. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::Init: failed to initialize bruker controller."));
  33. return FALSE;
  34. }
  35. // ok, return TRUE
  36. return TRUE;
  37. }
  38. // collect spectrum at the given position (to controller buffer)
  39. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds, const CPoint& a_oPoint)
  40. {
  41. // check bruker controller
  42. ASSERT(m_pBrukerImpl);
  43. if (!m_pBrukerImpl)
  44. {
  45. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  46. return FALSE;
  47. }
  48. // collect spectrum data
  49. if (!m_pBrukerImpl->CollectOneXRayPoint(a_oPoint, a_nMilliseconds, (long*)m_nRayData, (DWORD)EDSConst::XANA_CHANNELS))
  50. {
  51. // failed to call bruker controller CollectOneXRayPoint method
  52. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectOneXRayPoint method."));
  53. return FALSE;
  54. }
  55. // ok, return TRUE
  56. return TRUE;
  57. }
  58. // collects spectrum (to controller buffer)
  59. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds)
  60. {
  61. // check bruker controller
  62. ASSERT(m_pBrukerImpl);
  63. if (!m_pBrukerImpl)
  64. {
  65. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  66. return FALSE;
  67. }
  68. // collect spectrum data
  69. if (!m_pBrukerImpl->CollectSpectrum(a_nMilliseconds, (long*)m_nRayData, (DWORD)EDSConst::XANA_CHANNELS))
  70. {
  71. // failed to call bruker controller CollectSpectrum method
  72. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectSpectrum method."));
  73. return FALSE;
  74. }
  75. // ok, return TRUE
  76. return TRUE;
  77. }
  78. // collects spectrum (to given buffer)
  79. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize)
  80. {
  81. // input check
  82. ASSERT(a_pCounts);
  83. if (!a_pCounts)
  84. {
  85. // invalid input data buffer
  86. LogTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid input data buffer."));
  87. return FALSE;
  88. }
  89. // check bruker controller
  90. ASSERT(m_pBrukerImpl);
  91. if (!m_pBrukerImpl)
  92. {
  93. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  94. return FALSE;
  95. }
  96. // collect spectrum data
  97. if (!m_pBrukerImpl->CollectSpectrum(a_nMilliseconds, a_pCounts, a_nBufferSize))
  98. {
  99. // failed to call bruker controller CollectSpectrum method
  100. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectSpectrum method."));
  101. return FALSE;
  102. }
  103. // ok, return TRUE
  104. return TRUE;
  105. }
  106. // get live time
  107. float COTSEDSBrucker::GetLiveTime()
  108. {
  109. // check bruker controller
  110. ASSERT(m_pBrukerImpl);
  111. if (!m_pBrukerImpl)
  112. {
  113. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  114. return 0.0;
  115. }
  116. // get time value from the controller
  117. float fRet;
  118. fRet = m_pBrukerImpl->GetLiveTime();
  119. return fRet;
  120. }
  121. BOOL COTSEDSBrucker::IsSupportQuantification()
  122. {
  123. return TRUE;
  124. }
  125. BOOL COTSEDSBrucker::GetQuantificationMethods(std::vector<CString>& a_vMethods)
  126. {
  127. // check bruker controller
  128. ASSERT(m_pBrukerImpl);
  129. if (!m_pBrukerImpl)
  130. {
  131. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantificationMethods: invalid m_pBrukerImpl."));
  132. return FALSE;
  133. }
  134. return m_pBrukerImpl->GetQuantificationMethods(a_vMethods);
  135. }
  136. BOOL COTSEDSBrucker::QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName)
  137. {
  138. // check bruker controller
  139. ASSERT(m_pBrukerImpl);
  140. if (!m_pBrukerImpl)
  141. {
  142. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifyXrayPoint: invalid m_pBrukerImpl."));
  143. return FALSE;
  144. }
  145. return m_pBrukerImpl->QuantifyXrayPoint(a_pXRayPoint, a_sMethodName);
  146. }
  147. BOOL COTSEDSBrucker::QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry)
  148. {
  149. // check bruker controller
  150. ASSERT(m_pBrukerImpl);
  151. if (!m_pBrukerImpl)
  152. {
  153. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumFile: invalid m_pBrukerImpl."));
  154. return FALSE;
  155. }
  156. return m_pBrukerImpl->QuantifySpectrumFile(a_sFilePathName, a_sMethodName, a_listElementChemistry);
  157. }
  158. BOOL COTSEDSBrucker::QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry)
  159. {
  160. // check bruker controller
  161. ASSERT(m_pBrukerImpl);
  162. if (!m_pBrukerImpl)
  163. {
  164. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumOut: invalid m_pBrukerImpl."));
  165. return FALSE;
  166. }
  167. return m_pBrukerImpl->QuantifySpectrumOut(a_nMilliseconds, a_pCounts, a_nBufferSize, a_listElementChemistry);
  168. }
  169. BOOL COTSEDSBrucker::GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime)
  170. {
  171. // check Bruker controller
  172. ASSERT(m_pBrukerImpl);
  173. if (!m_pBrukerImpl)
  174. {
  175. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByPoints: invalid m_pBrukerImpl."));
  176. return FALSE;
  177. }
  178. std::vector<CPosXrayPtr> listXRayPointsTemp;
  179. // turn SEM to external
  180. if (!m_pBrukerImpl->SetSEMExternalOn())
  181. {
  182. // failed to call SetSEMExternalOn method
  183. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  184. return FALSE;
  185. }
  186. for (int i = 0; i < (int)a_vXRayPoints.size(); i++)
  187. {
  188. listXRayPointsTemp.push_back( a_vXRayPoints[i]);
  189. }
  190. if (!m_pBrukerImpl->GetXRayByPoints(listXRayPointsTemp, a_nXRayAQTime))// one point per time,or we cann't get the full element data. gsp 2020-11-30
  191. {
  192. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByPoints: failed to get element."));
  193. }
  194. listXRayPointsTemp.clear();
  195. if (!m_pBrukerImpl->SetSEMExternalOff())
  196. {
  197. // failed to call SetSEMExternalOn method
  198. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  199. }
  200. return TRUE;
  201. }
  202. BOOL COTSEDSBrucker::GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  203. std::vector<BrukerFeature>& a_listFeatures,
  204. const DWORD a_nXRayAQTime)
  205. {
  206. // check bruker controller
  207. ASSERT(m_pBrukerImpl);
  208. if (!m_pBrukerImpl)
  209. {
  210. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByFeatures: invalid m_pBrukerImpl."));
  211. return FALSE;
  212. }
  213. // turn SEM to external
  214. if (!m_pBrukerImpl->SetSEMExternalOn())
  215. {
  216. // failed to call SetSEMExternalOn method
  217. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  218. return FALSE;
  219. }
  220. // collect x-Ray points (area scan)
  221. if (!m_pBrukerImpl->GetXRayByFeatures(a_listXRayPoints, a_listFeatures, a_nXRayAQTime))
  222. {
  223. // failed to call bruker controller CollectXRayPointsByFeatures method.
  224. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectXRayPointsByFeatures: failed to call bruker controller CollectXRayPointsByFeatures method."));
  225. return FALSE;
  226. }
  227. if (!m_pBrukerImpl->SetSEMExternalOff())
  228. {
  229. // failed to call SetSEMExternalOn method
  230. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  231. }
  232. // ok, return TRUE
  233. return TRUE;
  234. }
  235. // Quatification
  236. void COTSEDSBrucker::SetQuantification(BOOL a_bQuantification)
  237. {
  238. // check bruker controller
  239. ASSERT(m_pBrukerImpl);
  240. if (!m_pBrukerImpl)
  241. {
  242. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::SetQuantification: invalid m_pBrukerImpl."));
  243. return;
  244. }
  245. // collect x-Ray points (area scan)
  246. m_pBrukerImpl->SetQuantificationFlag(a_bQuantification);
  247. }
  248. BOOL COTSEDSBrucker::GetQuantification()
  249. {
  250. // check bruker controller
  251. ASSERT(m_pBrukerImpl);
  252. if (!m_pBrukerImpl)
  253. {
  254. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantification: invalid m_pBrukerImpl."));
  255. return FALSE;
  256. }
  257. // collect x-Ray points (area scan)
  258. return m_pBrukerImpl->GetQuantificationFlag();
  259. }
  260. // Get number of channels
  261. DWORD COTSEDSBrucker::GetNumberOfChannels(void)
  262. {
  263. return (DWORD)2000;
  264. }
  265. // Get the x-Ray data
  266. DWORD* COTSEDSBrucker::GetXRayData()
  267. {
  268. return m_nRayData;
  269. }
  270. }