OTSEDSBrucker.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. BOOL COTSEDSBrucker::StopXrayAcquistion()
  107. {
  108. ASSERT(m_pBrukerImpl);
  109. if (!m_pBrukerImpl)
  110. {
  111. LogErrorTrace(__FILE__, __LINE__, _T(" invalid m_pBrukerImpl."));
  112. return FALSE;
  113. }
  114. return m_pBrukerImpl->StopSpectrumMeasure();
  115. }
  116. // get live time
  117. float COTSEDSBrucker::GetLiveTime()
  118. {
  119. // check bruker controller
  120. ASSERT(m_pBrukerImpl);
  121. if (!m_pBrukerImpl)
  122. {
  123. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  124. return 0.0;
  125. }
  126. // get time value from the controller
  127. float fRet;
  128. fRet = m_pBrukerImpl->GetLiveTime();
  129. return fRet;
  130. }
  131. BOOL COTSEDSBrucker::IsSupportQuantification()
  132. {
  133. return TRUE;
  134. }
  135. BOOL COTSEDSBrucker::GetQuantificationMethods(std::vector<CString>& a_vMethods)
  136. {
  137. // check bruker controller
  138. ASSERT(m_pBrukerImpl);
  139. if (!m_pBrukerImpl)
  140. {
  141. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantificationMethods: invalid m_pBrukerImpl."));
  142. return FALSE;
  143. }
  144. return m_pBrukerImpl->GetQuantificationMethods(a_vMethods);
  145. }
  146. BOOL COTSEDSBrucker::QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName)
  147. {
  148. // check bruker controller
  149. ASSERT(m_pBrukerImpl);
  150. if (!m_pBrukerImpl)
  151. {
  152. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifyXrayPoint: invalid m_pBrukerImpl."));
  153. return FALSE;
  154. }
  155. return m_pBrukerImpl->QuantifyXrayPoint(a_pXRayPoint, a_sMethodName);
  156. }
  157. BOOL COTSEDSBrucker::QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry)
  158. {
  159. // check bruker controller
  160. ASSERT(m_pBrukerImpl);
  161. if (!m_pBrukerImpl)
  162. {
  163. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumFile: invalid m_pBrukerImpl."));
  164. return FALSE;
  165. }
  166. return m_pBrukerImpl->QuantifySpectrumFile(a_sFilePathName, a_sMethodName, a_listElementChemistry);
  167. }
  168. BOOL COTSEDSBrucker::QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry)
  169. {
  170. // check bruker controller
  171. ASSERT(m_pBrukerImpl);
  172. if (!m_pBrukerImpl)
  173. {
  174. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumOut: invalid m_pBrukerImpl."));
  175. return FALSE;
  176. }
  177. return m_pBrukerImpl->QuantifySpectrumOut(a_nMilliseconds, a_pCounts, a_nBufferSize, a_listElementChemistry);
  178. }
  179. BOOL COTSEDSBrucker::GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime)
  180. {
  181. // check Bruker controller
  182. ASSERT(m_pBrukerImpl);
  183. if (!m_pBrukerImpl)
  184. {
  185. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByPoints: invalid m_pBrukerImpl."));
  186. return FALSE;
  187. }
  188. // turn SEM to external
  189. if (!m_pBrukerImpl->SetSEMExternalOn())
  190. {
  191. // failed to call SetSEMExternalOn method
  192. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  193. return FALSE;
  194. }
  195. std::vector<CPosXrayPtr> listXRayPointsTemp;
  196. for (int i = 0; i < (int)a_vXRayPoints.size(); i++)
  197. {
  198. listXRayPointsTemp.push_back( a_vXRayPoints[i]);
  199. if (!m_pBrukerImpl->GetXRayByPoints(listXRayPointsTemp, a_nXRayAQTime))// one point per time,or we cann't get the full element data. gsp 2020-11-30
  200. {
  201. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByPoints: failed to get element."));
  202. }
  203. listXRayPointsTemp.clear();
  204. }
  205. if (!m_pBrukerImpl->SetSEMExternalOff())
  206. {
  207. // failed to call SetSEMExternalOn method
  208. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  209. }
  210. return TRUE;
  211. }
  212. BOOL COTSEDSBrucker::GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  213. std::vector<BrukerFeature>& a_listFeatures,
  214. const DWORD a_nXRayAQTime)
  215. {
  216. // check bruker controller
  217. ASSERT(m_pBrukerImpl);
  218. if (!m_pBrukerImpl)
  219. {
  220. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByFeatures: invalid m_pBrukerImpl."));
  221. return FALSE;
  222. }
  223. // turn SEM to external
  224. if (!m_pBrukerImpl->SetSEMExternalOn())
  225. {
  226. // failed to call SetSEMExternalOn method
  227. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  228. return FALSE;
  229. }
  230. std::vector<CPosXrayPtr> listXRayPointsTemp;
  231. std::vector<BrukerFeature> listFeatureTemp;
  232. for (int i = 0; i < (int)a_listXRayPoints.size(); i++)
  233. {
  234. listXRayPointsTemp.push_back(a_listXRayPoints[i]);
  235. listFeatureTemp.push_back(a_listFeatures[i]);
  236. // collect x-Ray points (area scan)
  237. if (!m_pBrukerImpl->GetXRayByFeatures(listXRayPointsTemp, listFeatureTemp, a_nXRayAQTime))
  238. {
  239. // failed to call bruker controller CollectXRayPointsByFeatures method.
  240. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectXRayPointsByFeatures: failed to call bruker controller CollectXRayPointsByFeatures method."));
  241. }
  242. listXRayPointsTemp.clear();
  243. listFeatureTemp.clear();
  244. }
  245. if (!m_pBrukerImpl->SetSEMExternalOff())
  246. {
  247. // failed to call SetSEMExternalOn method
  248. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  249. }
  250. // ok, return TRUE
  251. return TRUE;
  252. }
  253. // Quatification
  254. void COTSEDSBrucker::SetQuantification(BOOL a_bQuantification)
  255. {
  256. // check bruker controller
  257. ASSERT(m_pBrukerImpl);
  258. if (!m_pBrukerImpl)
  259. {
  260. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::SetQuantification: invalid m_pBrukerImpl."));
  261. return;
  262. }
  263. // collect x-Ray points (area scan)
  264. m_pBrukerImpl->SetQuantificationFlag(a_bQuantification);
  265. }
  266. BOOL COTSEDSBrucker::GetQuantification()
  267. {
  268. // check bruker controller
  269. ASSERT(m_pBrukerImpl);
  270. if (!m_pBrukerImpl)
  271. {
  272. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantification: invalid m_pBrukerImpl."));
  273. return FALSE;
  274. }
  275. // collect x-Ray points (area scan)
  276. return m_pBrukerImpl->GetQuantificationFlag();
  277. }
  278. // Get number of channels
  279. DWORD COTSEDSBrucker::GetNumberOfChannels(void)
  280. {
  281. return (DWORD)2000;
  282. }
  283. // Get the x-Ray data
  284. DWORD* COTSEDSBrucker::GetXRayData()
  285. {
  286. return m_nRayData;
  287. }
  288. }