Browse Source

optimize the oxford driver code.

gsp 3 years ago
parent
commit
9512666121

+ 2 - 2
OTSCPP/OTSControl/Bruker/OTSBrukerImpl.cpp

@@ -1813,13 +1813,13 @@ BOOL COTSBrukerImpl::CloseClient(void)
 		LogErrorTrace(__FILE__, __LINE__, "  COTSBrukerImpl::CloseClient: invalid m_pBrukerDllHandle");
 		return FALSE;
 	}
-
+	LogTrace(__FILE__, __LINE__, _T("Close Bruker client...")+ CString(std::to_string(m_nClientID).c_str()));
 	if (!m_pBrukerDllHandle->CloseClient(m_nClientID))
 	{
 		LogErrorTrace(__FILE__, __LINE__, "  COTSBrukerImpl::CloseClient   failed  ");
 		return FALSE;
 	}
-	//m_nClientID = 0;	
+	
 	
 	return TRUE;
 }

+ 1 - 0
OTSCPP/OTSControl/Bruker/OTSSEMBruker.cpp

@@ -36,6 +36,7 @@ namespace OTSController {
 		if (m_pBrukerImplPtr)
 		{
 			// initialize the bruker controller as a SEM controller
+			LogTrace(__FILE__, __LINE__, _T("Init BrukerImpl..."));
 			if (m_pBrukerImplPtr->Init(CONTROL_TYPE::BRUKER_SEM))
 			{
 				// check connection

+ 2 - 2
OTSCPP/OTSControl/OTSSemBase.cpp

@@ -114,7 +114,7 @@ namespace OTSController {
 
 
 
-				Sleep(1000);//ÑÓʱ100ºÁÃë 
+				Sleep(1000);
 			}
 
 			// tried once
@@ -129,7 +129,7 @@ namespace OTSController {
 		}
 		else
 		{
-			Sleep(1000);//still wait another 500ms to let SEM move.then  stage will be stable when we acquire BSE.
+			Sleep(1000);//still wait another 1000ms to let SEM move.then  stage will be stable when we acquire BSE.
 		}
 
 		// ok, return TRUE

+ 1 - 1
OTSCPP/OTSControl/Oxford/OTSOxfordImpl.cpp

@@ -67,7 +67,7 @@
     {
         if (m_oxfordPtr && m_bInit)
         {
-            return m_oxfordPtr->IsConnected();
+            return (bool)m_oxfordPtr->IsConnected();
         }
 
         return false;

+ 40 - 29
OTSCPP/OTSControl/Oxford/OxfordWrapper/OxfordControllerWrapper.cpp

@@ -48,9 +48,6 @@ void OxfordControllerWrapper::CloseClient(void)
 {
 	if (_controllerThread && _controllerThread->IsAlive)
 	{
-		m_startControllerEvent->Set();
-
-		m_endControllerEvent->WaitOne(g_nOxfordControllerEventWaitTimerInt);
 	}
 
 	_controllerThread->Abort();
@@ -61,8 +58,6 @@ OxfordControllerWrapper::~OxfordControllerWrapper(void)
 {	
 	if (_controllerThread && _controllerThread->IsAlive)
 	{
-	
-		m_endControllerEvent->WaitOne(g_nOxfordControllerEventWaitTimerInt);
 	}
 
 	_controllerThread->Abort();
@@ -72,12 +67,9 @@ OxfordControllerWrapper::!OxfordControllerWrapper(void)
 {
 	if (_controllerThread && _controllerThread->IsAlive)
 	{
-
-
-
-		m_endControllerEvent->WaitOne(g_nOxfordControllerEventWaitTimerInt);
+		
 	}
-
+	
 	_controllerThread->Abort();
 }
 
@@ -191,13 +183,13 @@ void OxfordControllerWrapper::ControllerThreadFunction()
 			if (edsController && _oxfordControllerData.m_pSpectrumData)
 			{
 				edsController->BeginMultipleAcquisition();
-				//OutputDebugString(_T("BeginMultipleAcquisition...(single point)"));
+				
 
 				if (m_bBeamPositionSet)
 				{
 					m_bBeamPositionSet = false;
 					bRet = true;
-					//OutputDebugString(_T("Beam position already set."));
+				
 
 					Point pos(_oxfordControllerData.m_dBeamPositionX * _oxfordControllerData.m_dPixelSize, _oxfordControllerData.m_dBeamPositionY * _oxfordControllerData.m_dPixelSize);
 					auto edsSettings = GetEdsSpectrumSettings();
@@ -206,7 +198,7 @@ void OxfordControllerWrapper::ControllerThreadFunction()
 				else
 				{
 					bRet = SetCurrentBeamPosition();
-					//OutputDebugString(_T("Set current Beam position to collect xray."));
+					
 				}
 
 				if (bRet)
@@ -359,7 +351,17 @@ void OxfordControllerWrapper::ControllerThreadFunction()
 
 bool OxfordControllerWrapper::IsConnected()
 {
-	return true;
+	if (IsMicroscopeColumnConnected()
+		&& IsMicroscopeStageConnected())
+	{
+		return true;
+	}
+	else
+	{
+		return false;
+	}
+
+	
 }
 
 bool OxfordControllerWrapper::IsMicroscopeColumnConnected()
@@ -398,7 +400,6 @@ bool OxfordControllerWrapper::GetPositionXY(double& a_dPosX, double& a_dPosY)
 {
 	_oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_POSITIONXY;
 
-	//m_startControllerEvent->Set();
 
 	double dX, dY;
 
@@ -468,7 +469,6 @@ bool OxfordControllerWrapper::SetPositionXY(const double a_dPosX, const double a
 	_oxfordControllerData.m_dPositionX = a_dPosX;
 	_oxfordControllerData.m_dPositionY = a_dPosY;
 	m_bIsStageUpdated = false;
-	//m_startControllerEvent->Set();
 
 	if (SetPositionXYToController(_oxfordControllerData.m_dPositionX, _oxfordControllerData.m_dPositionY))
 	{
@@ -478,7 +478,16 @@ bool OxfordControllerWrapper::SetPositionXY(const double a_dPosX, const double a
 	{
 		_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
 	}
-
+	double waitTime=0;
+	while (!m_bIsStageUpdated)//m_bIsStageUpdated will be set by the callback event.
+	{
+		Sleep(100);
+		waitTime += 0.1;
+		if (waitTime > 10)//prevent the m_bIsStageUpdated won't be set ,we will wait only 10s.
+		{
+			break;
+		}
+	}
 	
 
 	if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
@@ -1664,7 +1673,7 @@ bool OxfordControllerWrapper::StartImageCollecting()
 	catch (Exception^ /*ex*/)
 	{
 		CString sMessage(_T("StartImageCollecting: Start Acquisition failed"));
-		//OutputDebugString(sMessage);
+		
 		LogErrorTrace(__FILE__,__LINE__,sMessage);
 	}
 
@@ -1807,7 +1816,7 @@ bool OxfordControllerWrapper::StopImageCollecting()
 		CString sMessage = ex->Message;
 		CString sErrorMessage;
 		     sErrorMessage.Format(_T("StopImageCollecting: Stop Acquisition caught(%s)"), sMessage);
-		//OutputDebugString(sErrorMessage);
+	
 		LogErrorTrace(__FILE__, __LINE__, sErrorMessage);
 	}
 
@@ -1824,13 +1833,13 @@ IMicroscopeController^ OxfordControllerWrapper::CreateMicroscopeController()
 
 	try
 	{
+		LogTrace(__FILE__, __LINE__, _T("CreateMicroscopeControl..."));
 		_microscopeController = AcquireFactory::CreateMicroscopeControl();
 	}
 	catch(Exception^ ex)
 	{
 		CString sErrorMessage = ex->Message;
-		AfxMessageBox(_T("oxford eds cann't work,you can change work mode to offline in the sysMgrApp to run offline mode!\nerror:")+ sErrorMessage);
-		//OutputDebugString(sErrorMessage);
+		AfxMessageBox(_T("oxford eds cann't work,you can change work mode to offline in the sysMgrApp to run offline mode!\nerror:")+ sErrorMessage);	
 		LogErrorTrace(__FILE__, __LINE__, sErrorMessage);
 		exit(0);
 	}
@@ -1845,7 +1854,7 @@ IMicroscopeController^ OxfordControllerWrapper::CreateMicroscopeController()
 
 	m_bIsStageUpdated = false;
 
-	auto nStart = GetTickCount64();
+	/*auto nStart = GetTickCount64();
 	auto nEnd = nStart;
 	do
 	{
@@ -1857,15 +1866,17 @@ IMicroscopeController^ OxfordControllerWrapper::CreateMicroscopeController()
 		}
 
 		nEnd = GetTickCount64();
-	} while (nEnd >= nStart && nEnd <= (nStart + g_nMicrocopeConnectTimeOutMilliSeconds));
-
+	} while (nEnd >= nStart && nEnd <= (nStart + g_nMicrocopeConnectTimeOutMilliSeconds));*/
+	Sleep(g_nMicrocopeConnectTimeOutMilliSeconds);
 	return _microscopeController;
 }
 
 IEdSpectrumAcquisitionController^ OxfordControllerWrapper::CreateEdsSpectrumController()
 {
+	
 	if (_edSpectrumController == nullptr)
 	{
+		LogTrace(__FILE__, __LINE__, _T("CreateEdSpectrumServer..."));
 		_edSpectrumController = AcquireFactory::CreateEdSpectrumServer();
 
 		_edSpectrumController->ExperimentFinished += gcnew EventHandler<OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdSpectrum^>^>(this, &OxfordControllerWrapper::OnXrayAcquisitionFinished);
@@ -1895,8 +1906,7 @@ IEdSpectrumSettings^ OxfordControllerWrapper::GetEdsSpectrumSettings()
 
 		if (_edsSpectrumSettings == nullptr)
 		{
-			CString sMessage(_T("Create EDS Spectrum setting failed."));
-			//OutputDebugString(sMessage);
+			CString sMessage(_T("Create EDS Spectrum setting failed."));		
 			LogErrorTrace(__FILE__, __LINE__, sMessage);
 			ASSERT(FALSE);
 		}
@@ -1917,6 +1927,7 @@ IImageAcquisitionController^ OxfordControllerWrapper::CreateImageAcqusitionContr
 {
 	if (_imageAcqusitionController == nullptr)
 	{
+		LogTrace(__FILE__, __LINE__, _T("CreateImageAcqusitionController..."));
 		try
 		{
 			_imageAcqusitionController = AcquireFactory::CreateImageServer();
@@ -1940,10 +1951,9 @@ IImageAcquisitionController^ OxfordControllerWrapper::CreateImageAcqusitionContr
 		{
 			CString sMessage = ex->Message;
 			CString sErrorMessage;
-			//           sErrorMessage.Format(_T("CreateImageAcqusitionController: create controller caught(%s)"), sMessage);
-			//OutputDebugString(sErrorMessage);
+		
 			LogErrorTrace(__FILE__, __LINE__, sErrorMessage);
-			//LogMessage(sErrorMessage);
+			
 		}
 	}
 
@@ -2013,6 +2023,7 @@ IEdChordListAcquisitionController^ OxfordControllerWrapper::CreateChordlistContr
 {
 	if (_edsChordListController == nullptr)
 	{
+		LogTrace(__FILE__, __LINE__, _T("CreateEdChordListServer..."));
 		_edsChordListController = AcquireFactory::CreateEdChordListServer();
 
 		_edsChordListController->PixelProcessed += gcnew EventHandler<OINA::Extender::EventArgs<OINA::Extender::Processing::Quant::IPixelSEMQuantStatus^>^>(this, &OxfordControllerWrapper::OnController_PixelProcessed); 

+ 1 - 1
OTSCPP/OTSControl/Oxford/OxfordWrapper/OxfordControllerWrapper.h

@@ -293,7 +293,7 @@ protected:
 
 	bool m_bBeamPositionSet;
 
-	//LogFunction* m_logFuntion;
+	
 };
 
 ref class ManagedGlobals

+ 1 - 5
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -963,11 +963,7 @@ namespace OTSModelSharp
                     //save the result to project file
                     Rectangle oImageRect = (Rectangle)pBSEIamge.GetImageRect();
                     CHoleBSEImg pHoleBSEImg =new CHoleBSEImg(oImageRect,a_nHoleID, poiFieldCentre);
-                    //pHoleBSEImg.SetHoleID(a_nHoleID);
-                    //pHoleBSEImg.SetPosition(poiFieldCentre);
-                   
-                    //int nImageSize = pBSEIamge.GetHeight() * pBSEIamge.GetWidth();
-                    //pHoleBSEImg.SetImageRect(oImageRect);
+                 
                     pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
 
                     m_listHoleBSEImg.Add(pHoleBSEImg);