OTSEDSBrucker.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. for (int i = 0; i < (int)a_vXRayPoints.size(); i++)
  180. {
  181. listXRayPointsTemp.push_back( a_vXRayPoints[i]);
  182. if (!m_pBrukerImpl->GetXRayByPoints(listXRayPointsTemp, a_nXRayAQTime))// one point per time,or we cann't get the full element data. gsp 2020-11-30
  183. {
  184. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByPoints: failed to get element."));
  185. }
  186. listXRayPointsTemp.clear();
  187. }
  188. return TRUE;
  189. }
  190. BOOL COTSEDSBrucker::GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  191. std::vector<BrukerFeature>& a_listFeatures,
  192. const DWORD a_nXRayAQTime)
  193. {
  194. // check bruker controller
  195. ASSERT(m_pBrukerImpl);
  196. if (!m_pBrukerImpl)
  197. {
  198. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByFeatures: invalid m_pBrukerImpl."));
  199. return FALSE;
  200. }
  201. // collect x-Ray points (area scan)
  202. if (!m_pBrukerImpl->GetXRayByFeatures(a_listXRayPoints, a_listFeatures, a_nXRayAQTime))
  203. {
  204. // failed to call bruker controller CollectXRayPointsByFeatures method.
  205. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectXRayPointsByFeatures: failed to call bruker controller CollectXRayPointsByFeatures method."));
  206. return FALSE;
  207. }
  208. // ok, return TRUE
  209. return TRUE;
  210. }
  211. // Quatification
  212. void COTSEDSBrucker::SetQuantification(BOOL a_bQuantification)
  213. {
  214. // check bruker controller
  215. ASSERT(m_pBrukerImpl);
  216. if (!m_pBrukerImpl)
  217. {
  218. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::SetQuantification: invalid m_pBrukerImpl."));
  219. return;
  220. }
  221. // collect x-Ray points (area scan)
  222. m_pBrukerImpl->SetQuantificationFlag(a_bQuantification);
  223. }
  224. BOOL COTSEDSBrucker::GetQuantification()
  225. {
  226. // check bruker controller
  227. ASSERT(m_pBrukerImpl);
  228. if (!m_pBrukerImpl)
  229. {
  230. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantification: invalid m_pBrukerImpl."));
  231. return FALSE;
  232. }
  233. // collect x-Ray points (area scan)
  234. return m_pBrukerImpl->GetQuantificationFlag();
  235. }
  236. // Get number of channels
  237. DWORD COTSEDSBrucker::GetNumberOfChannels(void)
  238. {
  239. return (DWORD)2000;
  240. }
  241. // Get the x-Ray data
  242. DWORD* COTSEDSBrucker::GetXRayData()
  243. {
  244. return m_nRayData;
  245. }
  246. }