OTSScanBrucker.cpp 7.3 KB

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