OTSScanBrucker.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. #include "stdafx.h"
  2. #include "OTSScanBrucker.h"
  3. #include "SEMCommonConst.h"
  4. namespace OTSController {
  5. // constructor
  6. COTSScanBrucker::COTSScanBrucker()
  7. : m_pBrukerImpl(nullptr)
  8. {
  9. }
  10. // destructor
  11. COTSScanBrucker::~COTSScanBrucker(void)
  12. {
  13. }
  14. /// instance termination
  15. void COTSScanBrucker::FinishedInstance()
  16. {
  17. m_pBrukerImpl.reset();
  18. }
  19. // initialization
  20. BOOL COTSScanBrucker::Init()
  21. {
  22. // is simulation
  23. /*if (IsSimulation())
  24. {
  25. return TRUE;
  26. }
  27. */
  28. // create bruker initialize controller
  29. if (!m_pBrukerImpl)
  30. {
  31. // get bruker controller
  32. m_pBrukerImpl = COTSBrukerImpl::GetInstance();
  33. }
  34. // initialize bruker scanner controller
  35. ASSERT(m_pBrukerImpl);
  36. if (!m_pBrukerImpl)
  37. {
  38. // failed to create bruker controller
  39. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to create bruker controller."));
  40. return FALSE;
  41. }
  42. // initialize bruker controller (as scanner)
  43. if (!m_pBrukerImpl->Init(CONTROL_TYPE::BRUKER_SCAN))
  44. {
  45. // failed to call bruker controller init method
  46. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to failed to call bruker controller init method."));
  47. return FALSE;
  48. }
  49. // ok, return TRUE
  50. return TRUE;
  51. }
  52. // get the size of matrix.
  53. CSize COTSScanBrucker::GetMatrixSize(int /*a_nMatrixIndex*/)
  54. {
  55. // simulation
  56. //if (IsSimulation())
  57. //{
  58. // // simulation, need to do nothing
  59. // return CSize(0);
  60. //}
  61. // check bruker controller
  62. ASSERT(m_pBrukerImpl);
  63. if (!m_pBrukerImpl)
  64. {
  65. // invalid m_pBrukerImpl
  66. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: invalid m_pBrukerImpl."));
  67. return CSize(0);
  68. }
  69. // Just return the a size based on the image size that has previously been set.
  70. // This is an artifact the interface being based on the edax model, but not catering
  71. // to bruker that keeps state internally.
  72. // Return the size based on the height that was set - we stretch the image horizontally
  73. // but by the time we return it the image is square.
  74. DWORD nWidth = 0;
  75. DWORD nHeight = 0;
  76. DWORD nAverage;
  77. BYTE bCh1;
  78. BYTE bCh2;
  79. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  80. {
  81. // failed to call ImageGetConfiguration method
  82. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: failed to call ImageGetConfiguration method"));
  83. return CSize(0);
  84. }
  85. // return
  86. return CSize(nWidth, nHeight);
  87. }
  88. // acquire BSE image
  89. CBSEImgPtr COTSScanBrucker::AcquireBSEImage(int /*a_nMatrixIndex*/, int /*nReads*/, int /*nDwell*/)
  90. {
  91. // BSE image
  92. CBSEImgPtr poBSEImgPtr = nullptr;
  93. // simulation?
  94. //if (IsSimulation())
  95. //{
  96. // // load simulation image
  97. // poBSEImgPtr = AcquireBSEImageFromBitmapFile();
  98. // // check simulation image
  99. // ASSERT(poBSEImgPtr);
  100. // if (!poBSEImgPtr)
  101. // {
  102. // // failed to load simulation image
  103. // LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: failed to load simulation image"));
  104. // }
  105. // // return simulation image, nullptr if load simulation image failed
  106. // return poBSEImgPtr;
  107. //}
  108. // check bruker controller
  109. ASSERT(m_pBrukerImpl);
  110. if (!m_pBrukerImpl)
  111. {
  112. // invalid m_pBrukerImpl
  113. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: invalid m_pBrukerImpl."));
  114. return poBSEImgPtr;
  115. }
  116. // acquire BSE image
  117. poBSEImgPtr = m_pBrukerImpl->AcquireImage();
  118. // check acquired image
  119. ASSERT(poBSEImgPtr);
  120. if (!poBSEImgPtr)
  121. {
  122. // failed to load simulation image
  123. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: failed to acquire image"));
  124. }
  125. // return acquired image, nullptr if acquire image failed
  126. return poBSEImgPtr;
  127. }
  128. // move beam to point
  129. BOOL COTSScanBrucker::MoveBeamTo(CPoint& a_beamPos)
  130. {
  131. // simulation?
  132. //if (IsSimulation())
  133. //{
  134. // // need to do nothing
  135. // return TRUE;
  136. //}
  137. // check bruker controller
  138. ASSERT(m_pBrukerImpl);
  139. if (!m_pBrukerImpl)
  140. {
  141. // invalid m_pBrukerImpl
  142. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: invalid m_pBrukerImpl."));
  143. return FALSE;
  144. }
  145. // move beam to point
  146. if (!m_pBrukerImpl->ImageSetPoint(a_beamPos))
  147. {
  148. // failed to call ImageSetPoint method
  149. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: failed to call ImageSetPoint method."));
  150. return FALSE;
  151. }
  152. // ok, return TRUE
  153. return TRUE;
  154. }
  155. // start scan table
  156. BOOL COTSScanBrucker::StartScanTable(int /*a_nMatrixIndex*/, unsigned int /*nP*/, int* /*px*/, int* /*py*/)
  157. {
  158. return TRUE;
  159. }
  160. // set image size
  161. BOOL COTSScanBrucker::SetImageSize(long a_nImageSizeX)
  162. {
  163. // simulation?
  164. //if (IsSimulation())
  165. //{
  166. // // need to do nothing
  167. // return TRUE;
  168. //}
  169. // check bruker controller
  170. ASSERT(m_pBrukerImpl);
  171. if (!m_pBrukerImpl)
  172. {
  173. // invalid m_pBrukerImpl
  174. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: invalid m_pBrukerImpl."));
  175. return FALSE;
  176. }
  177. // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels
  178. DWORD nWidth = 0;
  179. DWORD nHeight = 0;
  180. DWORD nAverage;
  181. BYTE bCh1;
  182. BYTE bCh2;
  183. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  184. {
  185. // failed to call ImageGetConfiguration method
  186. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageGetConfiguration method."));
  187. return FALSE;
  188. }
  189. // set image size
  190. nWidth = a_nImageSizeX;
  191. nHeight = (long)((double)a_nImageSizeX * OTS_RESOLUTION_RATIO + 0.5);
  192. if (!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  193. {
  194. // failed to call ImageGetConfiguration method
  195. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageSetConfiguration method."));
  196. return FALSE;
  197. }
  198. // ok, return TRUE
  199. return TRUE;
  200. }
  201. // set dwell time
  202. BOOL COTSScanBrucker::SetDwellTime(long a_nDwellTime)
  203. {
  204. // simulation?
  205. //if (IsSimulation())
  206. //{
  207. // // need to do nothing
  208. // return TRUE;
  209. //}
  210. // check bruker controller
  211. ASSERT(m_pBrukerImpl);
  212. if (!m_pBrukerImpl)
  213. {
  214. // invalid m_pBrukerImpl
  215. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: invalid m_pBrukerImpl."));
  216. return FALSE;
  217. }
  218. // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels
  219. DWORD nWidth = 0;
  220. DWORD nHeight = 0;
  221. DWORD nAverage;
  222. BYTE bCh1;
  223. BYTE bCh2;
  224. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  225. {
  226. // failed to call ImageGetConfiguration method
  227. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageGetConfiguration method."));
  228. return FALSE;
  229. }
  230. // set dwell time
  231. nAverage = (DWORD)a_nDwellTime;
  232. if(!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  233. {
  234. // failed to call ImageSetConfiguration method
  235. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageSetConfiguration method."));
  236. return FALSE;
  237. }
  238. // ok, return TRUE
  239. return TRUE;
  240. }
  241. // get field resolution by index
  242. CSize COTSScanBrucker::GetFrameResolutionByIndex(const long a_nIndex)
  243. {
  244. // check index
  245. if (a_nIndex < RESOLUTION_ID_MIN || a_nIndex > RESOLUTION_ID_MAX)
  246. {
  247. // invalid index
  248. ASSERT(FALSE);
  249. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetFrameResolutionByIndex: invalid index"));
  250. return CSize(0);
  251. }
  252. // get field resolution
  253. CSize sizeFieldResolution = RESOLUTION_VALUE[a_nIndex];
  254. return sizeFieldResolution;
  255. }
  256. // set field resolution by index
  257. BOOL COTSScanBrucker::SetFrameResolutionByIndex(const long a_nIndex)
  258. {
  259. // check index
  260. if (a_nIndex < RESOLUTION_ID_MIN || a_nIndex > RESOLUTION_ID_MAX)
  261. {
  262. // invalid index
  263. ASSERT(FALSE);
  264. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetFrameResolutionByIndex: invalid index"));
  265. return FALSE;
  266. }
  267. // get field resolution
  268. CSize sizeFieldResolution = RESOLUTION_VALUE[a_nIndex];
  269. // set image size
  270. if (!SetImageSize(sizeFieldResolution.cx))
  271. {
  272. // failed to call SetImageSize method
  273. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetFrameResolutionByIndex: failed to call SetImageSize method."));
  274. return FALSE;
  275. }
  276. // ok, return TRUE
  277. return TRUE;
  278. }
  279. // get dwell time by index
  280. long COTSScanBrucker::GetDwellTimeByIndex(const long a_nIndex)
  281. {
  282. // check index
  283. if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MAX)
  284. {
  285. // invalid index
  286. ASSERT(FALSE);
  287. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetDwellTimeByIndex: invalid index"));
  288. return -1;
  289. }
  290. // get dwell time by index
  291. long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  292. return nDwellTime;
  293. }
  294. // set dwell time by index
  295. BOOL COTSScanBrucker::SetDwellTimeByIndex(const long a_nIndex)
  296. {
  297. // check index
  298. if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MIN)
  299. {
  300. // invalid index
  301. ASSERT(FALSE);
  302. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: invalid index"));
  303. return FALSE;
  304. }
  305. // get dwell time
  306. long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  307. if (!SetDwellTime(nDwellTime))
  308. {
  309. // failed to call SetDwellTime method
  310. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: failed to call SetDwellTime method."));
  311. return FALSE;
  312. }
  313. // ok, return TRUE
  314. return TRUE;
  315. }
  316. // scan field size
  317. BOOL COTSScanBrucker::SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  318. {
  319. m_nScanFieldSizeX = a_nWidth;
  320. m_nScanFieldSizeY = a_nHeight;
  321. return TRUE;
  322. }
  323. // set the SEM position
  324. BOOL COTSScanBrucker::SetEMPosition(const int a_nPosX, const int a_nPosY)
  325. {
  326. m_nCurrentBSEPositionX = a_nPosX;
  327. m_nCurrentBSEPositionY = a_nPosY;
  328. return TRUE;
  329. }
  330. }