OTSEDSBrucker.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. if (!m_pBrukerImpl->SetSPU())
  23. {
  24. return FALSE;
  25. }
  26. // ok, return TRUE
  27. return TRUE;
  28. }
  29. // collect spectrum at the given position (to controller buffer)
  30. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds, const CPoint& a_oPoint)
  31. {
  32. // check bruker controller
  33. ASSERT(m_pBrukerImpl);
  34. if (!m_pBrukerImpl)
  35. {
  36. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  37. return FALSE;
  38. }
  39. // collect spectrum data
  40. if (!m_pBrukerImpl->CollectOneXRayPoint(a_oPoint, a_nMilliseconds, (long*)m_nRayData, (DWORD)EDSConst::XANA_CHANNELS))
  41. {
  42. // failed to call bruker controller CollectOneXRayPoint method
  43. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectOneXRayPoint method."));
  44. return FALSE;
  45. }
  46. // ok, return TRUE
  47. return TRUE;
  48. }
  49. // collects spectrum (to controller buffer)
  50. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds)
  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->CollectSpectrum(a_nMilliseconds, (long*)m_nRayData, (DWORD)EDSConst::XANA_CHANNELS))
  61. {
  62. // failed to call bruker controller CollectSpectrum method
  63. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectSpectrum method."));
  64. return FALSE;
  65. }
  66. // ok, return TRUE
  67. return TRUE;
  68. }
  69. // collects spectrum (to given buffer)
  70. BOOL COTSEDSBrucker::CollectSpectrum(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize)
  71. {
  72. // input check
  73. ASSERT(a_pCounts);
  74. if (!a_pCounts)
  75. {
  76. // invalid input data buffer
  77. LogTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid input data buffer."));
  78. return FALSE;
  79. }
  80. // check bruker controller
  81. ASSERT(m_pBrukerImpl);
  82. if (!m_pBrukerImpl)
  83. {
  84. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  85. return FALSE;
  86. }
  87. // collect spectrum data
  88. if (!m_pBrukerImpl->CollectSpectrum(a_nMilliseconds, a_pCounts, a_nBufferSize))
  89. {
  90. // failed to call bruker controller CollectSpectrum method
  91. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: failed to call bruker controller CollectSpectrum method."));
  92. return FALSE;
  93. }
  94. // ok, return TRUE
  95. return TRUE;
  96. }
  97. BOOL COTSEDSBrucker::StopXrayAcquistion()
  98. {
  99. ASSERT(m_pBrukerImpl);
  100. if (!m_pBrukerImpl)
  101. {
  102. LogErrorTrace(__FILE__, __LINE__, _T(" invalid m_pBrukerImpl."));
  103. return FALSE;
  104. }
  105. return m_pBrukerImpl->StopSpectrumMeasure();
  106. }
  107. // get live time
  108. float COTSEDSBrucker::GetLiveTime()
  109. {
  110. // check bruker controller
  111. ASSERT(m_pBrukerImpl);
  112. if (!m_pBrukerImpl)
  113. {
  114. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectSpectrum: invalid m_pBrukerImpl."));
  115. return 0.0;
  116. }
  117. // get time value from the controller
  118. float fRet;
  119. fRet = m_pBrukerImpl->GetLiveTime();
  120. return fRet;
  121. }
  122. BOOL COTSEDSBrucker::GetQuantificationMethods(std::vector<CString>& a_vMethods)
  123. {
  124. // check bruker controller
  125. ASSERT(m_pBrukerImpl);
  126. if (!m_pBrukerImpl)
  127. {
  128. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantificationMethods: invalid m_pBrukerImpl."));
  129. return FALSE;
  130. }
  131. return m_pBrukerImpl->GetQuantificationMethods(a_vMethods);
  132. }
  133. BOOL COTSEDSBrucker::QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName)
  134. {
  135. // check bruker controller
  136. ASSERT(m_pBrukerImpl);
  137. if (!m_pBrukerImpl)
  138. {
  139. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifyXrayPoint: invalid m_pBrukerImpl."));
  140. return FALSE;
  141. }
  142. return m_pBrukerImpl->QuantifyXrayPoint(a_pXRayPoint, a_sMethodName);
  143. }
  144. BOOL COTSEDSBrucker::QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry)
  145. {
  146. // check bruker controller
  147. ASSERT(m_pBrukerImpl);
  148. if (!m_pBrukerImpl)
  149. {
  150. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumFile: invalid m_pBrukerImpl."));
  151. return FALSE;
  152. }
  153. return m_pBrukerImpl->QuantifySpectrumFile(a_sFilePathName, a_sMethodName, a_listElementChemistry);
  154. }
  155. BOOL COTSEDSBrucker::QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry)
  156. {
  157. // check bruker controller
  158. ASSERT(m_pBrukerImpl);
  159. if (!m_pBrukerImpl)
  160. {
  161. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::QuantifySpectrumOut: invalid m_pBrukerImpl."));
  162. return FALSE;
  163. }
  164. return m_pBrukerImpl->QuantifySpectrumOut(a_nMilliseconds, a_pCounts, a_nBufferSize, a_listElementChemistry);
  165. }
  166. BOOL COTSEDSBrucker::GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime)
  167. {
  168. // check Bruker controller
  169. ASSERT(m_pBrukerImpl);
  170. if (!m_pBrukerImpl)
  171. {
  172. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByPoints: invalid m_pBrukerImpl."));
  173. return FALSE;
  174. }
  175. std::vector<CPosXrayPtr> listXRayPointsTemp;
  176. if (!m_pBrukerImpl->GetXRayByPoints(a_vXRayPoints, a_nXRayAQTime))
  177. {
  178. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByPoints: failed to get element."));
  179. }
  180. return TRUE;
  181. }
  182. BOOL COTSEDSBrucker::QuantifyXrays(std::vector<CPosXrayPtr>& a_vXRayParts)
  183. {
  184. m_pBrukerImpl->QuantifyPosXrayPointsOnLine(a_vXRayParts);
  185. return true;
  186. }
  187. BOOL COTSEDSBrucker::QuantifyXray(CPosXrayPtr& a_vXRayPart)
  188. {
  189. m_pBrukerImpl->QuantifyPosXrayPointOnLine(a_vXRayPart);
  190. return true;
  191. }
  192. BOOL COTSEDSBrucker::GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  193. std::vector<BrukerFeature>& a_listFeatures,
  194. const DWORD a_nXRayAQTime)
  195. {
  196. // check bruker controller
  197. ASSERT(m_pBrukerImpl);
  198. if (!m_pBrukerImpl)
  199. {
  200. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetXRayByFeatures: invalid m_pBrukerImpl."));
  201. return FALSE;
  202. }
  203. // turn SEM to external
  204. if (!m_pBrukerImpl->SetSEMExternalOn())
  205. {
  206. // failed to call SetSEMExternalOn method
  207. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOn method."));
  208. return FALSE;
  209. }
  210. if (!m_pBrukerImpl->GetXRayByFeatures(a_listXRayPoints, a_listFeatures, a_nXRayAQTime))
  211. {
  212. // failed to call bruker controller CollectXRayPointsByFeatures method.
  213. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::CollectXRayPointsByFeatures: failed to call bruker controller CollectXRayPointsByFeatures method."));
  214. }
  215. if (!m_pBrukerImpl->SetSEMExternalOff())
  216. {
  217. // failed to call SetSEMExternalOn method
  218. LogTrace(__FILE__, __LINE__, _T("COTSBrukerImpl::GetXRayByPoints: failed to call SetSEMExternalOff method."));
  219. }
  220. // ok, return TRUE
  221. return TRUE;
  222. }
  223. // Quatification
  224. void COTSEDSBrucker::SetQuantification(BOOL a_bQuantification)
  225. {
  226. // check bruker controller
  227. ASSERT(m_pBrukerImpl);
  228. if (!m_pBrukerImpl)
  229. {
  230. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::SetQuantification: invalid m_pBrukerImpl."));
  231. return;
  232. }
  233. // collect x-Ray points (area scan)
  234. m_pBrukerImpl->SetQuantificationFlag(a_bQuantification);
  235. }
  236. BOOL COTSEDSBrucker::GetQuantification()
  237. {
  238. // check bruker controller
  239. ASSERT(m_pBrukerImpl);
  240. if (!m_pBrukerImpl)
  241. {
  242. LogErrorTrace(__FILE__, __LINE__, _T("COTSEDSBrucker::GetQuantification: invalid m_pBrukerImpl."));
  243. return FALSE;
  244. }
  245. // collect x-Ray points (area scan)
  246. return m_pBrukerImpl->GetQuantificationFlag();
  247. }
  248. // Get number of channels
  249. DWORD COTSEDSBrucker::GetNumberOfChannels(void)
  250. {
  251. return (DWORD)2000;
  252. }
  253. // Get the x-Ray data
  254. DWORD* COTSEDSBrucker::GetXRayData()
  255. {
  256. return m_nRayData;
  257. }
  258. void COTSEDSBrucker::SetExpectCount(int expectcount)
  259. {
  260. m_pBrukerImpl->SetExpectCount(expectcount);
  261. }
  262. int COTSEDSBrucker::GetExpectCount()
  263. {
  264. return m_pBrukerImpl->GetExpectCount();
  265. }
  266. void COTSEDSBrucker::SetQuantificationParam(bool ifauto, CString knownelements)
  267. {
  268. m_pBrukerImpl->SetQuantificationParam(ifauto, knownelements);
  269. }
  270. }