OTSScanOxford.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include "stdafx.h"
  2. #include "OTSScanOxford.h"
  3. #define TRACE_HERE /*NOP*/
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #endif
  7. namespace OTSController
  8. {
  9. COTSScanOxford::COTSScanOxford(void)
  10. {
  11. LogTrace(__FILE__, __LINE__, _T("%s controller created"), (LPCTSTR)GetName());
  12. }
  13. COTSScanOxford::~COTSScanOxford(void)
  14. {
  15. LogTrace(__FILE__, __LINE__, _T("%s controller finished"), (LPCTSTR)GetName());
  16. }
  17. /// <summary>
  18. /// Finished the instance.
  19. /// </summary>
  20. void COTSScanOxford::FinishedInstance()
  21. {
  22. TRACE_HERE;
  23. m_oxfordImpl.reset();
  24. }
  25. // initialisation
  26. BOOL COTSScanOxford::Init()
  27. {
  28. // get bruker initialize controller
  29. if (!m_oxfordImpl)
  30. {
  31. // get bruker controller
  32. m_oxfordImpl = OxfordImpl::GetInstance();
  33. }
  34. BOOL ifconnect = true;
  35. if (!m_oxfordImpl->IsConnected())
  36. {
  37. ifconnect = m_oxfordImpl->Connect();
  38. }
  39. return ifconnect;
  40. }
  41. CSize COTSScanOxford::GetMatrixSize(int /*a_nMatrixIndex*/)
  42. {
  43. // method return value
  44. CSize oRet = CSize(0);
  45. ASSERT(m_oxfordImpl);
  46. if (!m_oxfordImpl)
  47. {
  48. return oRet;
  49. }
  50. long nWidth = 0, nHeight = 0;
  51. if (m_oxfordImpl->GetImageSize(nWidth, nHeight))
  52. {
  53. oRet.SetSize(nWidth, nHeight);
  54. }
  55. return oRet;
  56. }
  57. BOOL COTSScanOxford::MoveBeamTo(CPoint& a_beamPos)
  58. {
  59. ASSERT(m_oxfordImpl);
  60. if (!m_oxfordImpl)
  61. {
  62. return false;
  63. }
  64. bool bRet = m_oxfordImpl->SetBeamPosition(a_beamPos.x, a_beamPos.y);
  65. return bRet;
  66. }
  67. // Start Scan Table
  68. BOOL COTSScanOxford::StartScanTable (int a_nMatrixIndex, unsigned int nP, int* px, int* py)
  69. {
  70. CSize szMatrix = GetMatrixSize(a_nMatrixIndex);
  71. double stepSize = ((double)m_szScanRange.cx) /((double) szMatrix.cx);
  72. for (unsigned int i = 0 ; i < nP ; i++)
  73. {
  74. px[i] = (int) (px[i] * stepSize) ;
  75. py[i] = m_szScanRange.cy - (int) (py[i] * stepSize) ;
  76. }
  77. return true;
  78. }
  79. /// set image size
  80. /// input long nImageSize
  81. /// return true if success
  82. BOOL COTSScanOxford::SetImageSize(long newImageSize,long nHeight)
  83. {
  84. // safety check
  85. ASSERT(m_oxfordImpl);
  86. if (!m_oxfordImpl)
  87. {
  88. return false;
  89. }
  90. if (!m_oxfordImpl->SetImageSize(newImageSize, nHeight))
  91. {
  92. ASSERT(m_oxfordImpl);
  93. if (!m_oxfordImpl)
  94. {
  95. return FALSE;
  96. }
  97. }
  98. return true;
  99. }
  100. /// set dwell time
  101. /// input long a_nDwellTime
  102. /// return true if success
  103. BOOL COTSScanOxford::SetDwellTime(long nDwellTime)
  104. {
  105. // safety check
  106. ASSERT(m_oxfordImpl);
  107. if (!m_oxfordImpl)
  108. {
  109. return false;
  110. }
  111. if (!m_oxfordImpl->SetScanSpeed(nDwellTime))
  112. {
  113. ASSERT(m_oxfordImpl);
  114. if (!m_oxfordImpl)
  115. {
  116. return FALSE;
  117. }
  118. }
  119. return true;
  120. }
  121. CBSEImgPtr COTSScanOxford::AcquireBSEImage(int /*a_nMatrixIndex*/, int /*nReads*/, int /*nDwell*/)
  122. {
  123. // safety check
  124. ASSERT(m_oxfordImpl);
  125. if (!m_oxfordImpl)
  126. {
  127. return nullptr;
  128. }
  129. long nWidth, nHeight;
  130. if (!m_oxfordImpl->GetImageSize(nWidth, nHeight))
  131. {
  132. LogErrorTrace(__FILE__, __LINE__, _T("Call GetImageSize failed."));
  133. return nullptr;
  134. }
  135. long nImageSize = nWidth * nHeight;
  136. if (nImageSize <= 0)
  137. {
  138. LogErrorTrace(__FILE__, __LINE__, _T("AcquireBSEImage failed: invalid image size (%d, %d)."), nWidth, nHeight);
  139. return nullptr;
  140. }
  141. std::vector<BYTE> vecImage(nImageSize, 0);
  142. if (!m_oxfordImpl->CollectImage(&vecImage[0]))
  143. {
  144. LogErrorTrace(__FILE__, __LINE__, _T("Call CollectImage failed."));
  145. return nullptr;
  146. }
  147. CBSEImgPtr bseImage(new CBSEImg());
  148. CRect imageRect(0, 0, nWidth, nHeight);
  149. bseImage->SetImageRect(imageRect);
  150. bseImage->InitImageData(nWidth, nHeight);
  151. BYTE* pImageData = bseImage->GetImageDataPointer();
  152. memcpy(pImageData, &vecImage[0], nWidth * nHeight);
  153. ASSERT(m_oxfordImpl);
  154. if (!m_oxfordImpl)
  155. {
  156. return bseImage;
  157. }
  158. return bseImage;
  159. }
  160. long COTSScanOxford::GetDwellTimeByIndex(const long a_nIndex)
  161. {
  162. // dwell time
  163. if(a_nIndex < DWELLTIME_OXFORD_ID_MIN || a_nIndex > DWELLTIME_OXFORD_ID_MAX)
  164. {
  165. // error, invalid scan speed value
  166. LogErrorTrace(__FILE__, __LINE__, _T("Scan speed (Dwell time) index (%d) error."), a_nIndex);
  167. ASSERT(FALSE);
  168. return -1;
  169. }
  170. // convert dwell time index to dwell time value
  171. return DWELLTIME_OXFORD_VALUES[a_nIndex];
  172. }
  173. BOOL COTSScanOxford::SetDwellTimeByIndex(const long a_nDwellTimeIndex)
  174. {
  175. // dwell time
  176. if(a_nDwellTimeIndex < DWELLTIME_OXFORD_ID_MIN || a_nDwellTimeIndex > DWELLTIME_OXFORD_ID_MAX)
  177. {
  178. // error, invalid scan speed value
  179. LogErrorTrace(__FILE__, __LINE__, _T("Scan speed index (%d) error."), a_nDwellTimeIndex);
  180. ASSERT(m_oxfordImpl);
  181. if (!m_oxfordImpl)
  182. {
  183. return FALSE;
  184. }
  185. }
  186. // convert dwell time index to dwell time value
  187. long nDwellTimeLong = DWELLTIME_OXFORD_VALUES[a_nDwellTimeIndex];
  188. if (!SetDwellTime(nDwellTimeLong))
  189. {
  190. // error, failed to set dwell time
  191. LogErrorTrace(__FILE__, __LINE__, _T("Failed to set dwell time (%d)."), a_nDwellTimeIndex);
  192. ASSERT(m_oxfordImpl);
  193. if (!m_oxfordImpl)
  194. {
  195. return FALSE;
  196. }
  197. }
  198. return true;
  199. }
  200. BOOL COTSScanOxford::SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  201. {
  202. m_nScanFieldSizeX = a_nWidth;
  203. m_nScanFieldSizeY = a_nHeight;
  204. return TRUE;
  205. }
  206. // set the SEM position
  207. BOOL COTSScanOxford::SetEMPosition(const int a_nPosX, const int a_nPosY)
  208. {
  209. m_nCurrentBSEPositionX = a_nPosX;
  210. m_nCurrentBSEPositionY = a_nPosY;
  211. return TRUE;
  212. }
  213. }