OTSScanBrucker.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. // create bruker initialize controller
  23. if (!m_pBrukerImpl)
  24. {
  25. // get bruker controller
  26. m_pBrukerImpl = COTSBrukerImpl::GetInstance();
  27. }
  28. // initialize bruker scanner controller
  29. ASSERT(m_pBrukerImpl);
  30. if (!m_pBrukerImpl)
  31. {
  32. // failed to create bruker controller
  33. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to create bruker controller."));
  34. return FALSE;
  35. }
  36. // initialize bruker controller (as scanner)
  37. if (!m_pBrukerImpl->Init(CONTROL_TYPE::BRUKER_SCAN))
  38. {
  39. // failed to call bruker controller init method
  40. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to failed to call bruker controller init method."));
  41. return FALSE;
  42. }
  43. // ok, return TRUE
  44. return TRUE;
  45. }
  46. // get the size of matrix.
  47. CSize COTSScanBrucker::GetMatrixSize(int /*a_nMatrixIndex*/)
  48. {
  49. // check bruker controller
  50. ASSERT(m_pBrukerImpl);
  51. if (!m_pBrukerImpl)
  52. {
  53. // invalid m_pBrukerImpl
  54. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: invalid m_pBrukerImpl."));
  55. return CSize(0);
  56. }
  57. // Just return the a size based on the image size that has previously been set.
  58. // This is an artifact the interface being based on the edax model, but not catering
  59. // to bruker that keeps state internally.
  60. // Return the size based on the height that was set - we stretch the image horizontally
  61. // but by the time we return it the image is square.
  62. DWORD nWidth = 0;
  63. DWORD nHeight = 0;
  64. DWORD nAverage;
  65. BYTE bCh1;
  66. BYTE bCh2;
  67. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  68. {
  69. // failed to call ImageGetConfiguration method
  70. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: failed to call ImageGetConfiguration method"));
  71. return CSize(0);
  72. }
  73. // return
  74. return CSize(nWidth, nHeight);
  75. }
  76. // acquire BSE image
  77. CBSEImgPtr COTSScanBrucker::AcquireBSEImage(int /*a_nMatrixIndex*/, int /*nReads*/, int /*nDwell*/)
  78. {
  79. // BSE image
  80. CBSEImgPtr poBSEImgPtr = nullptr;
  81. // check bruker controller
  82. ASSERT(m_pBrukerImpl);
  83. if (!m_pBrukerImpl)
  84. {
  85. // invalid m_pBrukerImpl
  86. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: invalid m_pBrukerImpl."));
  87. return poBSEImgPtr;
  88. }
  89. // acquire BSE image
  90. poBSEImgPtr = m_pBrukerImpl->AcquireImage();
  91. // check acquired image
  92. ASSERT(poBSEImgPtr);
  93. if (!poBSEImgPtr)
  94. {
  95. // failed to load simulation image
  96. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: failed to acquire image"));
  97. }
  98. // return acquired image, nullptr if acquire image failed
  99. return poBSEImgPtr;
  100. }
  101. // move beam to point
  102. BOOL COTSScanBrucker::MoveBeamTo(CPoint& a_beamPos)
  103. {
  104. // check bruker controller
  105. ASSERT(m_pBrukerImpl);
  106. if (!m_pBrukerImpl)
  107. {
  108. // invalid m_pBrukerImpl
  109. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: invalid m_pBrukerImpl."));
  110. return FALSE;
  111. }
  112. // move beam to point
  113. if (!m_pBrukerImpl->ImageSetPoint(a_beamPos))
  114. {
  115. // failed to call ImageSetPoint method
  116. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: failed to call ImageSetPoint method."));
  117. return FALSE;
  118. }
  119. // ok, return TRUE
  120. return TRUE;
  121. }
  122. // start scan table
  123. BOOL COTSScanBrucker::StartScanTable(int /*a_nMatrixIndex*/, unsigned int /*nP*/, int* /*px*/, int* /*py*/)
  124. {
  125. return TRUE;
  126. }
  127. // set image size
  128. BOOL COTSScanBrucker::SetImageSize(long a_nImageSizeX,long a_Height)
  129. {
  130. // check bruker controller
  131. ASSERT(m_pBrukerImpl);
  132. if (!m_pBrukerImpl)
  133. {
  134. // invalid m_pBrukerImpl
  135. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: invalid m_pBrukerImpl."));
  136. return FALSE;
  137. }
  138. // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels
  139. DWORD nWidth = 0;
  140. DWORD nHeight = 0;
  141. DWORD nAverage;
  142. BYTE bCh1;
  143. BYTE bCh2;
  144. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  145. {
  146. // failed to call ImageGetConfiguration method
  147. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageGetConfiguration method."));
  148. return FALSE;
  149. }
  150. // set image size
  151. nWidth = a_nImageSizeX;
  152. nHeight = a_Height;
  153. if (!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  154. {
  155. // failed to call ImageGetConfiguration method
  156. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageSetConfiguration method."));
  157. return FALSE;
  158. }
  159. // ok, return TRUE
  160. return TRUE;
  161. }
  162. // set dwell time
  163. BOOL COTSScanBrucker::SetDwellTime(long a_nDwellTime)
  164. {
  165. // check bruker controller
  166. ASSERT(m_pBrukerImpl);
  167. if (!m_pBrukerImpl)
  168. {
  169. // invalid m_pBrukerImpl
  170. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: invalid m_pBrukerImpl."));
  171. return FALSE;
  172. }
  173. // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels
  174. DWORD nWidth = 0;
  175. DWORD nHeight = 0;
  176. DWORD nAverage;
  177. BYTE bCh1;
  178. BYTE bCh2;
  179. if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  180. {
  181. // failed to call ImageGetConfiguration method
  182. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageGetConfiguration method."));
  183. return FALSE;
  184. }
  185. // set dwell time
  186. nAverage = (DWORD)a_nDwellTime;
  187. if(!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2))
  188. {
  189. // failed to call ImageSetConfiguration method
  190. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageSetConfiguration method."));
  191. return FALSE;
  192. }
  193. // ok, return TRUE
  194. return TRUE;
  195. }
  196. // get dwell time by index
  197. long COTSScanBrucker::GetDwellTimeByIndex(const long a_nIndex)
  198. {
  199. // check index
  200. if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MAX)
  201. {
  202. // invalid index
  203. ASSERT(FALSE);
  204. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetDwellTimeByIndex: invalid index"));
  205. return -1;
  206. }
  207. // get dwell time by index
  208. long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  209. return nDwellTime;
  210. }
  211. // set dwell time by index
  212. BOOL COTSScanBrucker::SetDwellTimeByIndex(const long a_nIndex)
  213. {
  214. // check index
  215. if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MIN)
  216. {
  217. // invalid index
  218. ASSERT(FALSE);
  219. LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: invalid index"));
  220. return FALSE;
  221. }
  222. // get dwell time
  223. long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  224. if (!SetDwellTime(nDwellTime))
  225. {
  226. // failed to call SetDwellTime method
  227. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: failed to call SetDwellTime method."));
  228. return FALSE;
  229. }
  230. // ok, return TRUE
  231. return TRUE;
  232. }
  233. // scan field size
  234. BOOL COTSScanBrucker::SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  235. {
  236. m_nScanFieldSizeX = a_nWidth;
  237. m_nScanFieldSizeY = a_nHeight;
  238. return TRUE;
  239. }
  240. // set the SEM position
  241. BOOL COTSScanBrucker::SetEMPosition(const int a_nPosX, const int a_nPosY)
  242. {
  243. m_nCurrentBSEPositionX = a_nPosX;
  244. m_nCurrentBSEPositionY = a_nPosY;
  245. return TRUE;
  246. }
  247. }