OTSEDSBrucker.cpp 8.0 KB

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