OTSEDSBrucker.cpp 9.1 KB

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