OTSEDSBrucker.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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::GetQuantificationMethods(std::vector<CString>& a_vMethods)
  132. {
  133. // check bruker controller
  134. ASSERT(m_pBrukerImpl);
  135. if (!m_pBrukerImpl)
  136. {
  137. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantificationMethods: invalid m_pBrukerImpl."));
  138. return FALSE;
  139. }
  140. return m_pBrukerImpl->GetQuantificationMethods(a_vMethods);
  141. }
  142. BOOL COTSEDSBrucker::QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName)
  143. {
  144. // check bruker controller
  145. ASSERT(m_pBrukerImpl);
  146. if (!m_pBrukerImpl)
  147. {
  148. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifyXrayPoint: invalid m_pBrukerImpl."));
  149. return FALSE;
  150. }
  151. return m_pBrukerImpl->QuantifyXrayPoint(a_pXRayPoint, a_sMethodName);
  152. }
  153. BOOL COTSEDSBrucker::QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry)
  154. {
  155. // check bruker controller
  156. ASSERT(m_pBrukerImpl);
  157. if (!m_pBrukerImpl)
  158. {
  159. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumFile: invalid m_pBrukerImpl."));
  160. return FALSE;
  161. }
  162. return m_pBrukerImpl->QuantifySpectrumFile(a_sFilePathName, a_sMethodName, a_listElementChemistry);
  163. }
  164. BOOL COTSEDSBrucker::QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry)
  165. {
  166. // check bruker controller
  167. ASSERT(m_pBrukerImpl);
  168. if (!m_pBrukerImpl)
  169. {
  170. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumOut: invalid m_pBrukerImpl."));
  171. return FALSE;
  172. }
  173. return m_pBrukerImpl->QuantifySpectrumOut(a_nMilliseconds, a_pCounts, a_nBufferSize, a_listElementChemistry);
  174. }
  175. BOOL COTSEDSBrucker::GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime)
  176. {
  177. // check Bruker controller
  178. ASSERT(m_pBrukerImpl);
  179. if (!m_pBrukerImpl)
  180. {
  181. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByPoints: invalid m_pBrukerImpl."));
  182. return FALSE;
  183. }
  184. std::vector<CPosXrayPtr> listXRayPointsTemp;
  185. if (!m_pBrukerImpl->GetXRayByPoints(a_vXRayPoints, a_nXRayAQTime))// one point per time,or we cann't get the full element data. gsp 2020-11-30
  186. {
  187. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByPoints: failed to get element."));
  188. }
  189. return TRUE;
  190. }
  191. BOOL COTSEDSBrucker::QuantifyXrays(std::vector<CPosXrayPtr>& a_vXRayParts)
  192. {
  193. m_pBrukerImpl->QuantifyPosXrayPointsOnLine(a_vXRayParts);
  194. return true;
  195. }
  196. BOOL COTSEDSBrucker::QuantifyXray(CPosXrayPtr& a_vXRayPart)
  197. {
  198. m_pBrukerImpl->QuantifyPosXrayPointOnLine(a_vXRayPart);
  199. return true;
  200. }
  201. BOOL COTSEDSBrucker::GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  202. std::vector<BrukerFeature>& a_listFeatures,
  203. const DWORD a_nXRayAQTime)
  204. {
  205. // check bruker controller
  206. ASSERT(m_pBrukerImpl);
  207. if (!m_pBrukerImpl)
  208. {
  209. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByFeatures: invalid m_pBrukerImpl."));
  210. return FALSE;
  211. }
  212. // turn SEM to external
  213. if (!m_pBrukerImpl->SetSEMExternalOn())
  214. {
  215. // failed to call SetSEMExternalOn method
  216. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  217. return FALSE;
  218. }
  219. if (!m_pBrukerImpl->GetXRayByFeatures(a_listXRayPoints, a_listFeatures, a_nXRayAQTime))
  220. {
  221. // failed to call bruker controller CollectXRayPointsByFeatures method.
  222. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectXRayPointsByFeatures: failed to call bruker controller CollectXRayPointsByFeatures method."));
  223. }
  224. if (!m_pBrukerImpl->SetSEMExternalOff())
  225. {
  226. // failed to call SetSEMExternalOn method
  227. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  228. }
  229. // ok, return TRUE
  230. return TRUE;
  231. }
  232. // Quatification
  233. void COTSEDSBrucker::SetQuantification(BOOL a_bQuantification)
  234. {
  235. // check bruker controller
  236. ASSERT(m_pBrukerImpl);
  237. if (!m_pBrukerImpl)
  238. {
  239. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::SetQuantification: invalid m_pBrukerImpl."));
  240. return;
  241. }
  242. // collect x-Ray points (area scan)
  243. m_pBrukerImpl->SetQuantificationFlag(a_bQuantification);
  244. }
  245. BOOL COTSEDSBrucker::GetQuantification()
  246. {
  247. // check bruker controller
  248. ASSERT(m_pBrukerImpl);
  249. if (!m_pBrukerImpl)
  250. {
  251. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantification: invalid m_pBrukerImpl."));
  252. return FALSE;
  253. }
  254. // collect x-Ray points (area scan)
  255. return m_pBrukerImpl->GetQuantificationFlag();
  256. }
  257. // Get number of channels
  258. DWORD COTSEDSBrucker::GetNumberOfChannels(void)
  259. {
  260. return (DWORD)2000;
  261. }
  262. // Get the x-Ray data
  263. DWORD* COTSEDSBrucker::GetXRayData()
  264. {
  265. return m_nRayData;
  266. }
  267. void COTSEDSBrucker::SetExpectCount(int expectcount)
  268. {
  269. m_pBrukerImpl->SetExpectCount(expectcount);
  270. }
  271. int COTSEDSBrucker::GetExpectCount()
  272. {
  273. return m_pBrukerImpl->GetExpectCount();
  274. }
  275. }