#include "stdafx.h" #include "OTSScanBrucker.h" #include "SEMCommonConst.h" namespace OTSController { // constructor COTSScanBrucker::COTSScanBrucker() : m_pBrukerImpl(nullptr) { } // destructor COTSScanBrucker::~COTSScanBrucker(void) { } /// instance termination void COTSScanBrucker::FinishedInstance() { m_pBrukerImpl.reset(); } // initialization BOOL COTSScanBrucker::Init() { // is simulation /*if (IsSimulation()) { return TRUE; } */ // create bruker initialize controller if (!m_pBrukerImpl) { // get bruker controller m_pBrukerImpl = COTSBrukerImpl::GetInstance(); } // initialize bruker scanner controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // failed to create bruker controller LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to create bruker controller.")); return FALSE; } // initialize bruker controller (as scanner) if (!m_pBrukerImpl->Init(CONTROL_TYPE::BRUKER_SCAN)) { // failed to call bruker controller init method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::Init: failed to failed to call bruker controller init method.")); return FALSE; } // ok, return TRUE return TRUE; } // get the size of matrix. CSize COTSScanBrucker::GetMatrixSize(int /*a_nMatrixIndex*/) { // simulation //if (IsSimulation()) //{ // // simulation, need to do nothing // return CSize(0); //} // check bruker controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // invalid m_pBrukerImpl LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: invalid m_pBrukerImpl.")); return CSize(0); } // Just return the a size based on the image size that has previously been set. // This is an artifact the interface being based on the edax model, but not catering // to bruker that keeps state internally. // Return the size based on the height that was set - we stretch the image horizontally // but by the time we return it the image is square. DWORD nWidth = 0; DWORD nHeight = 0; DWORD nAverage; BYTE bCh1; BYTE bCh2; if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2)) { // failed to call ImageGetConfiguration method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetMatrixSize: failed to call ImageGetConfiguration method")); return CSize(0); } // return return CSize(nWidth, nHeight); } // acquire BSE image CBSEImgPtr COTSScanBrucker::AcquireBSEImage(int /*a_nMatrixIndex*/, int /*nReads*/, int /*nDwell*/) { // BSE image CBSEImgPtr poBSEImgPtr = nullptr; // simulation? //if (IsSimulation()) //{ // // load simulation image // poBSEImgPtr = AcquireBSEImageFromBitmapFile(); // // check simulation image // ASSERT(poBSEImgPtr); // if (!poBSEImgPtr) // { // // failed to load simulation image // LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: failed to load simulation image")); // } // // return simulation image, nullptr if load simulation image failed // return poBSEImgPtr; //} // check bruker controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // invalid m_pBrukerImpl LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: invalid m_pBrukerImpl.")); return poBSEImgPtr; } // acquire BSE image poBSEImgPtr = m_pBrukerImpl->AcquireImage(); // check acquired image ASSERT(poBSEImgPtr); if (!poBSEImgPtr) { // failed to load simulation image LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::AcquireBSEImage: failed to acquire image")); } // return acquired image, nullptr if acquire image failed return poBSEImgPtr; } // move beam to point BOOL COTSScanBrucker::MoveBeamTo(CPoint& a_beamPos) { // simulation? //if (IsSimulation()) //{ // // need to do nothing // return TRUE; //} // check bruker controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // invalid m_pBrukerImpl LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: invalid m_pBrukerImpl.")); return FALSE; } // move beam to point if (!m_pBrukerImpl->ImageSetPoint(a_beamPos)) { // failed to call ImageSetPoint method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::MoveBeamTo: failed to call ImageSetPoint method.")); return FALSE; } // ok, return TRUE return TRUE; } // start scan table BOOL COTSScanBrucker::StartScanTable(int /*a_nMatrixIndex*/, unsigned int /*nP*/, int* /*px*/, int* /*py*/) { return TRUE; } // set image size BOOL COTSScanBrucker::SetImageSize(long a_nImageSizeX) { // simulation? //if (IsSimulation()) //{ // // need to do nothing // return TRUE; //} // check bruker controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // invalid m_pBrukerImpl LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: invalid m_pBrukerImpl.")); return FALSE; } // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels DWORD nWidth = 0; DWORD nHeight = 0; DWORD nAverage; BYTE bCh1; BYTE bCh2; if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2)) { // failed to call ImageGetConfiguration method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageGetConfiguration method.")); return FALSE; } // set image size nWidth = a_nImageSizeX; nHeight = (long)((double)a_nImageSizeX * OTS_RESOLUTION_RATIO + 0.5); if (!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2)) { // failed to call ImageGetConfiguration method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetImageSize: failed to call ImageSetConfiguration method.")); return FALSE; } // ok, return TRUE return TRUE; } // set dwell time BOOL COTSScanBrucker::SetDwellTime(long a_nDwellTime) { // simulation? //if (IsSimulation()) //{ // // need to do nothing // return TRUE; //} // check bruker controller ASSERT(m_pBrukerImpl); if (!m_pBrukerImpl) { // invalid m_pBrukerImpl LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: invalid m_pBrukerImpl.")); return FALSE; } // call ImageGetConfiguration to get the existing dimensions, dwell time and enabled channels DWORD nWidth = 0; DWORD nHeight = 0; DWORD nAverage; BYTE bCh1; BYTE bCh2; if (!m_pBrukerImpl->ImageGetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2)) { // failed to call ImageGetConfiguration method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageGetConfiguration method.")); return FALSE; } // set dwell time nAverage = (DWORD)a_nDwellTime; if(!m_pBrukerImpl->ImageSetConfiguration(nWidth, nHeight, nAverage, bCh1, bCh2)) { // failed to call ImageSetConfiguration method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTime: failed to call ImageSetConfiguration method.")); return FALSE; } // ok, return TRUE return TRUE; } // get field resolution by index CSize COTSScanBrucker::GetFrameResolutionByIndex(const long a_nIndex) { // check index if (a_nIndex < RESOLUTION_ID_MIN || a_nIndex > RESOLUTION_ID_MAX) { // invalid index ASSERT(FALSE); LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetFrameResolutionByIndex: invalid index")); return CSize(0); } // get field resolution CSize sizeFieldResolution = RESOLUTION_VALUE[a_nIndex]; return sizeFieldResolution; } // set field resolution by index BOOL COTSScanBrucker::SetFrameResolutionByIndex(const long a_nIndex) { // check index if (a_nIndex < RESOLUTION_ID_MIN || a_nIndex > RESOLUTION_ID_MAX) { // invalid index ASSERT(FALSE); LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetFrameResolutionByIndex: invalid index")); return FALSE; } // get field resolution CSize sizeFieldResolution = RESOLUTION_VALUE[a_nIndex]; // set image size if (!SetImageSize(sizeFieldResolution.cx)) { // failed to call SetImageSize method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetFrameResolutionByIndex: failed to call SetImageSize method.")); return FALSE; } // ok, return TRUE return TRUE; } // get dwell time by index long COTSScanBrucker::GetDwellTimeByIndex(const long a_nIndex) { // check index if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MAX) { // invalid index ASSERT(FALSE); LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::GetDwellTimeByIndex: invalid index")); return -1; } // get dwell time by index long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex]; return nDwellTime; } // set dwell time by index BOOL COTSScanBrucker::SetDwellTimeByIndex(const long a_nIndex) { // check index if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MIN) { // invalid index ASSERT(FALSE); LogInfoTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: invalid index")); return FALSE; } // get dwell time long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex]; if (!SetDwellTime(nDwellTime)) { // failed to call SetDwellTime method LogErrorTrace(__FILE__, __LINE__, _T("COTSScanBrucker::SetDwellTimeByIndex: failed to call SetDwellTime method.")); return FALSE; } // ok, return TRUE return TRUE; } // scan field size BOOL COTSScanBrucker::SetScanFieldSize(const int a_nWidth, const int a_nHeight) { m_nScanFieldSizeX = a_nWidth; m_nScanFieldSizeY = a_nHeight; return TRUE; } // set the SEM position BOOL COTSScanBrucker::SetEMPosition(const int a_nPosX, const int a_nPosY) { m_nCurrentBSEPositionX = a_nPosX; m_nCurrentBSEPositionY = a_nPosY; return TRUE; } }