Procházet zdrojové kódy

improve the stage moving mechanism . add try enclosure and some log when catching bse image and collectting xray.

gaoshipeng před 2 roky
rodič
revize
86cdeebcfc

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

@@ -413,10 +413,10 @@
 			if (!ManagedGlobals::oxfordController->SetScanSpeed(a_nMilliseconds))
 			{
 				LogErrorTrace(__FILE__, __LINE__, _T("SetScanSpeed command failed."));
-				return (int)OxfordWrapperErrorCode::COMMAND_FAILED;
+				return false;
 			}
 
-			return (int)OxfordWrapperErrorCode::SUCCEED;
+			return true;
         }
 
         return false;
@@ -429,10 +429,10 @@
 			if (!ManagedGlobals::oxfordController->GetImageSize(a_nWidth, a_nHeight))
 			{
 				LogErrorTrace(__FILE__, __LINE__, _T("GetImageSize command failed."));
-				return (int)OxfordWrapperErrorCode::COMMAND_FAILED;
+				return false;
 			}
 
-			return (int)OxfordWrapperErrorCode::SUCCEED;
+			return true;
         }
 
         return false;
@@ -446,10 +446,10 @@
 			if (!ManagedGlobals::oxfordController->SetImageSize(a_nWidth, a_nHeight))
 			{
 				LogErrorTrace(__FILE__, __LINE__, _T("SetImageSize command failed."));
-				return (int)OxfordWrapperErrorCode::COMMAND_FAILED;
+				return false;
 			}
 
-			return (int)OxfordWrapperErrorCode::SUCCEED;
+			return true;
         }
 
         return false;
@@ -462,10 +462,10 @@
 			if (!ManagedGlobals::oxfordController->CollectImage(a_pImageBits))
 			{
 				LogErrorTrace(__FILE__, __LINE__, _T("CollectImage command failed."));
-				return (int)OxfordWrapperErrorCode::COMMAND_FAILED;
+				return false;
 			}
 
-			return (int)OxfordWrapperErrorCode::SUCCEED;
+			return true;
         }
 
         return false;
@@ -478,10 +478,10 @@
 			if (!ManagedGlobals::oxfordController->QuantifySpectrum(cResult))
 			{
 				LogErrorTrace(__FILE__, __LINE__, _T("CollectImage command failed."));
-				return (int)OxfordWrapperErrorCode::COMMAND_FAILED;
+				return false;
 			}
 
-			return (int)OxfordWrapperErrorCode::SUCCEED;
+			return true;
 		}
 
 		return false;

+ 243 - 86
OTSCPP/OTSControl/Oxford/OxfordWrapper/OxfordControllerWrapper.cpp

@@ -28,7 +28,7 @@ const long g_nMicrocopeConnectTimeOutMilliSeconds = 2000;
 const long g_nSinglePointCollectDelay = 3000;
 const long g_nSingleFeatureCollectDelay = 5000;
 const long g_nXrayControllerConnectTimeOutMilliSeconds = 10000;
-const long g_nImageTimeOutMilliSeconds = 20000;
+const long g_nImageTimeOutMilliSeconds = 40000;
 const long g_nStageTimeOutMilliSeconds = 15000;
 
 
@@ -89,6 +89,7 @@ bool OxfordControllerWrapper::Init()
 	_controllerThread = gcnew Thread(gcnew ThreadStart(this, &OxfordControllerWrapper::ControllerThreadFunction));
 	m_startControllerEvent->Reset();
 	m_endControllerEvent->Reset();
+
 	_controllerThread->Start();
 
 	return true;
@@ -1136,99 +1137,169 @@ bool OxfordControllerWrapper::StopXrayCollecting()
 
 	return !edsController->IsAcquiring;
 }
-
-void OxfordControllerWrapper::OnXrayAcquisitionFinished(Object^ sender, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdSpectrum^>^ e)
+void  OxfordControllerWrapper::XraySpectrumProcess(OINA::Extender::Data::Ed::IEdSpectrum^ spectrum)
 {
-	//Quantify processing
-	IEdSpectrumProcessing^ EdSpectrumProcessing = ProcessingFactory::CreateSpectrumProcessing();
+	try
+	{
 
-	// Use the autoIdSettings to define elements that are known or elements that you want to exclude. They also list elements that cannot be identified
-	IAutoIdSettings^ autoIdSettings = ProcessingFactory::CreateAutoIdSettings();
-	EdSpectrumProcessing->IdentifyElements(e->Value, autoIdSettings);
+		//Quantify processing
+		IEdSpectrumProcessing^ EdSpectrumProcessing = ProcessingFactory::CreateSpectrumProcessing();
 
-	ISEMQuantSettings^ settings = ProcessingFactory::CreateSEMQuantSettings();
+		// Use the autoIdSettings to define elements that are known or elements that you want to exclude. They also list elements that cannot be identified
+		IAutoIdSettings^ autoIdSettings = ProcessingFactory::CreateAutoIdSettings();
+		EdSpectrumProcessing->IdentifyElements(spectrum, autoIdSettings);
 
-	// While it is possible to choose other elements, Oxygen is the only supported element by stoichiometry.
-	settings->CombinedElement = 8;
-	settings->Normalised = true;
+		ISEMQuantSettings^ settings = ProcessingFactory::CreateSEMQuantSettings();
 
-	ISEMQuantStatus^ quantStatus = EdSpectrumProcessing->SEMQuantifySpectrum(e->Value, settings);//(a_nChannelData, OIHelper::SEMQuantSettings);
+		// While it is possible to choose other elements, Oxygen is the only supported element by stoichiometry.
+		settings->CombinedElement = 8;
+		settings->Normalised = true;
 
-	IEnumerable<ISEMQuantResult^>^ Results = quantStatus->Results;
+		ISEMQuantStatus^ quantStatus = EdSpectrumProcessing->SEMQuantifySpectrum(spectrum, settings);//(a_nChannelData, OIHelper::SEMQuantSettings);
 
-	if (_oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_XRAYPOINT 
-		|| _oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_CURRENTXRAYPOINT)
-	{
-		//Get element result for single point
-		auto ie = Results->GetEnumerator();
-		
-		String^ Quant = gcnew String("");
+		IEnumerable<ISEMQuantResult^>^ Results = quantStatus->Results;
 
-		while (ie->MoveNext())
+		if (_oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_XRAYPOINT
+			|| _oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_CURRENTXRAYPOINT)
 		{
-			ISEMQuantResult^ result = ie->Current;
+			//Get element result for single point
+			auto ie = Results->GetEnumerator();
+
+			String^ Quant = gcnew String("");
 
-			if (result->WeightPercent != 0)
+			while (ie->MoveNext())
 			{
-				Quant += "Quant=";
-				Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
-				Quant += ",";
-				Quant += result->LineType.ToString();
-				Quant += ",";
-				Quant += result->WeightPercent.ToString();				
+				ISEMQuantResult^ result = ie->Current;
+
+				if (result->WeightPercent != 0)
+				{
+					Quant += "Quant=";
+					Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
+					Quant += ",";
+					Quant += result->LineType.ToString();
+					Quant += ",";
+					Quant += result->WeightPercent.ToString();
+				}
 			}
-		}
 
-		_oxfordControllerData.m_sElementResult = Quant;
-		ConvertSpectrumData(e->Value, _oxfordControllerData.m_pSpectrumData, _oxfordControllerData.m_nBufferSize);
+			_oxfordControllerData.m_sElementResult = Quant;
+			ConvertSpectrumData(spectrum, _oxfordControllerData.m_pSpectrumData, _oxfordControllerData.m_nBufferSize);
 
-		_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+			_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+
+			auto edsController = CreateEdsSpectrumController();
+			if (edsController)
+			{
+				edsController->EndMultipleAcquisition();
+				m_endControllerEvent->Set();
 
-		auto edsController = CreateEdsSpectrumController();
-		if (edsController)
+			}
+		}
+		else
 		{
-			edsController->EndMultipleAcquisition();
-			m_endControllerEvent->Set();
-			
+
+			//Get element result for single point
+			auto ie = Results->GetEnumerator();
+
+			String^ Quant = gcnew String("");
+			while (ie->MoveNext())
+			{
+				ISEMQuantResult^ result = ie->Current;
+
+				if (result->WeightPercent != 0)
+				{
+					Quant += "Quant=";
+					Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
+					Quant += ",";
+					Quant += result->LineType.ToString();
+					Quant += ",";
+					Quant += result->WeightPercent.ToString();
+					Quant += "\n";
+				}
+			}
+
+			CString msg = Quant;
+			unsigned char* dst = _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_strElementResult;
+			for (int i = 0; i < msg.GetLength(); i++)
+			{
+				dst[i] = (unsigned char)msg.GetAt(i);
+			}
+
+			ConvertSpectrumData(spectrum, _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_pXrayData, _oxfordControllerData.m_nBufferSize);
+
+
+
+			_oxfordControllerData.m_nCollectedXrayCounts++;
+			if (_oxfordControllerData.m_nCollectedXrayCounts == _oxfordControllerData.m_nXrayDataCount)
+			{
+				_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+
+				auto edsController = CreateEdsSpectrumController();
+				if (edsController)
+				{
+					edsController->EndMultipleAcquisition();
+					m_endControllerEvent->Set();
+
+				}
+			}
 		}
 	}
-	else
+	catch (Exception^ ex)
 	{
+		CString sMessage(_T("OnXrayAcquisitionFinished failed") + ex->ToString());
 
-		//Get element result for single point
-		auto ie = Results->GetEnumerator();
+		LogErrorTrace(__FILE__, __LINE__, sMessage);
+	}
 
-		String^ Quant = gcnew String("");
-		while (ie->MoveNext())
-		{
-			ISEMQuantResult^ result = ie->Current;			
-
-			if (result->WeightPercent != 0)
-			{		
-				Quant += "Quant=";
-				Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
-				Quant += ",";
-				Quant += result->LineType.ToString();
-				Quant += ",";
-				Quant += result->WeightPercent.ToString();
-				Quant += "\n";					
-			}
-		}
+}
+void OxfordControllerWrapper::OnXrayAcquisitionFinished(Object^ sender, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdSpectrum^>^ e)
+{
+	try
+	{
 
-		CString msg = Quant;
-		unsigned char* dst = _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_strElementResult;
-		for (int i = 0; i < msg.GetLength(); i++)
-		{
-			dst[i] = (unsigned char) msg.GetAt(i);
-		}
+		//Quantify processing
+		IEdSpectrumProcessing^ EdSpectrumProcessing = ProcessingFactory::CreateSpectrumProcessing();
 
-		ConvertSpectrumData(e->Value, _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_pXrayData, _oxfordControllerData.m_nBufferSize);
+		// Use the autoIdSettings to define elements that are known or elements that you want to exclude. They also list elements that cannot be identified
+		IAutoIdSettings^ autoIdSettings = ProcessingFactory::CreateAutoIdSettings();
+		EdSpectrumProcessing->IdentifyElements(e->Value, autoIdSettings);
 
+		ISEMQuantSettings^ settings = ProcessingFactory::CreateSEMQuantSettings();
 
+		// While it is possible to choose other elements, Oxygen is the only supported element by stoichiometry.
+		settings->CombinedElement = 8;
+		settings->Normalised = true;
 
-		_oxfordControllerData.m_nCollectedXrayCounts++;
-		if (_oxfordControllerData.m_nCollectedXrayCounts == _oxfordControllerData.m_nXrayDataCount)
+		ISEMQuantStatus^ quantStatus = EdSpectrumProcessing->SEMQuantifySpectrum(e->Value, settings);//(a_nChannelData, OIHelper::SEMQuantSettings);
+
+		IEnumerable<ISEMQuantResult^>^ Results = quantStatus->Results;
+
+		if (_oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_XRAYPOINT
+			|| _oxfordControllerData.m_nCommand == OxfordControllerCommand::COLLECT_CURRENTXRAYPOINT)
 		{
+			//Get element result for single point
+			auto ie = Results->GetEnumerator();
+
+			String^ Quant = gcnew String("");
+
+			while (ie->MoveNext())
+			{
+				ISEMQuantResult^ result = ie->Current;
+
+				if (result->WeightPercent != 0)
+				{
+					Quant += "Quant=";
+					Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
+					Quant += ",";
+					Quant += result->LineType.ToString();
+					Quant += ",";
+					Quant += result->WeightPercent.ToString();
+				}
+			}
+
+			_oxfordControllerData.m_sElementResult = Quant;
+			ConvertSpectrumData(e->Value, _oxfordControllerData.m_pSpectrumData, _oxfordControllerData.m_nBufferSize);
+
 			_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
 
 			auto edsController = CreateEdsSpectrumController();
@@ -1236,10 +1307,64 @@ void OxfordControllerWrapper::OnXrayAcquisitionFinished(Object^ sender, OINA::Ex
 			{
 				edsController->EndMultipleAcquisition();
 				m_endControllerEvent->Set();
-				
+
+			}
+		}
+		else
+		{
+
+			//Get element result for single point
+			auto ie = Results->GetEnumerator();
+
+			String^ Quant = gcnew String("");
+			while (ie->MoveNext())
+			{
+				ISEMQuantResult^ result = ie->Current;
+
+				if (result->WeightPercent != 0)
+				{
+					Quant += "Quant=";
+					Quant += ElementProperties::GetElementSymbol(result->AtomicNumber);
+					Quant += ",";
+					Quant += result->LineType.ToString();
+					Quant += ",";
+					Quant += result->WeightPercent.ToString();
+					Quant += "\n";
+				}
+			}
+
+			CString msg = Quant;
+			unsigned char* dst = _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_strElementResult;
+			for (int i = 0; i < msg.GetLength(); i++)
+			{
+				dst[i] = (unsigned char)msg.GetAt(i);
+			}
+
+			ConvertSpectrumData(e->Value, _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_pXrayData, _oxfordControllerData.m_nBufferSize);
+
+
+
+			_oxfordControllerData.m_nCollectedXrayCounts++;
+			if (_oxfordControllerData.m_nCollectedXrayCounts == _oxfordControllerData.m_nXrayDataCount)
+			{
+				_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+
+				auto edsController = CreateEdsSpectrumController();
+				if (edsController)
+				{
+					edsController->EndMultipleAcquisition();
+					m_endControllerEvent->Set();
+
+				}
 			}
 		}
-	}	
+	}
+	catch (Exception^ ex)
+	{
+		CString sMessage(_T("OnXrayAcquisitionFinished failed") + ex->ToString());
+
+		LogErrorTrace(__FILE__, __LINE__, sMessage);
+	}
 }
 
 void OxfordControllerWrapper::OnXrayChordlistFinished(Object^, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdMap^>^ e)
@@ -1723,9 +1848,32 @@ bool OxfordControllerWrapper::StartImageCollecting()
 
 	try
 	{
-		auto image = imageAcqusitionController->StartAcquisition(imageAcqusitionSettings);
+		List<IElectronImage^>^ electronImageList = gcnew List<IElectronImage^>();
 
-		return image != nullptr;
+		auto images = imageAcqusitionController->StartAcquisition(imageAcqusitionSettings);
+
+		/*for each (auto eleImage in images)
+		{
+			electronImageList->Add(eleImage);
+		}
+
+		if (electronImageList->Count == 0)
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
+		}
+		else if (!ReadImageData(electronImageList[0], _oxfordControllerData.m_pImageBits))
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
+		}
+		else
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+		}
+
+		m_endControllerEvent->Set();*/
+
+
+		return images != nullptr;
 	}
 	catch (Exception^ /*ex*/)
 	{
@@ -1740,25 +1888,33 @@ bool OxfordControllerWrapper::StartImageCollecting()
 void OxfordControllerWrapper::OnImageAcquisitionFinished(Object^ /*sender*/, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<array<OINA::Extender::Data::Image::IElectronImage^ >^ >^ e)
 {
 	List<IElectronImage^>^ electronImageList = gcnew List<IElectronImage^>();
-
-	for each (auto eleImage in e->Value)
+	try
 	{
-		electronImageList->Add(eleImage);
-	}
 
-	if (electronImageList->Count == 0)
-	{
-		_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
-	}
-	else if (!ReadImageData(electronImageList[0], _oxfordControllerData.m_pImageBits))
-	{
-		_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
+		for each (auto eleImage in e->Value)
+		{
+			electronImageList->Add(eleImage);
+		}
+
+		if (electronImageList->Count == 0)
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
+		}
+		else if (!ReadImageData(electronImageList[0], _oxfordControllerData.m_pImageBits))
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::FAILED;
+		}
+		else
+		{
+			_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
+		}
 	}
-	else
+	catch (Exception^ ex)
 	{
-		_oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
-	}
+		CString sMessage(_T("OnImageAcquisitionFinished failed")+ex->ToString());
 
+		LogErrorTrace(__FILE__, __LINE__, sMessage);
+	}
 	m_endControllerEvent->Set();
 }
 
@@ -1910,7 +2066,8 @@ IMicroscopeController^ OxfordControllerWrapper::CreateMicroscopeController()
 	}
 
 	_microscopeController->ColumnChange += gcnew EventHandler<OINA::Extender::MicroscopeControl::ColumnEventArgs^>(this, &OxfordControllerWrapper::OnMicroscopeColumnUpdated);
-	_microscopeController->StageChange += gcnew EventHandler<OINA::Extender::MicroscopeControl::StageEventArgs^>(this, &OxfordControllerWrapper::OnMicroscopeStageUpdated);
+	//_microscopeController->StageChange += gcnew EventHandler<OINA::Extender::MicroscopeControl::StageEventArgs^>(this, &OxfordControllerWrapper::OnMicroscopeStageUpdated);
+	_microscopeController->ChangeCompleted += gcnew EventHandler<OINA::Extender::MicroscopeControl::CompletedEventArgs^>(this, &OxfordControllerWrapper::OnMicroscopeCompleted);
 
 	m_bIsStageUpdated = false;
 

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

@@ -187,6 +187,7 @@ public:
 		return m_bIsStageUpdated;
 	}
 	bool StopXrayCollecting();
+
 protected:
 
 	bool GetPositionXYFromController(double& a_dPosX, double& a_dPosY);
@@ -228,6 +229,21 @@ protected:
 		
 		m_bIsStageUpdated = true;
 		//LogTrace(__FILE__, __LINE__, _T("StageUpdated!"));
+	}
+	void OnMicroscopeCompleted(Object^ sender, OINA::Extender::MicroscopeControl::CompletedEventArgs^ e)
+	{
+		if ((int)e->Control == (int)MicroscopeControl::MicroscopeControlType::Stage)
+		{
+			if (e->Success)
+			{
+				LogTrace(__FILE__, __LINE__, _T("StageUpdated!"));
+				m_bIsStageUpdated = true;
+
+			}
+			
+		}
+	
+		
 	}
 	bool m_bIsStageUpdated;
 	bool m_bIsColumnUpdated;
@@ -246,7 +262,7 @@ protected:
 	void OnController_PixelProcessed(Object^ /*sender*/, OINA::Extender::EventArgs<OINA::Extender::Processing::Quant::IPixelSEMQuantStatus^ >^ e);
 	void OnController_ExperimentFinished(Object^ /*sender*/, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs^ e);
 	bool ReadImageData(IElectronImage^ a_electronImage, BYTE* a_pImageBits);
-
+	void XraySpectrumProcess(OINA::Extender::Data::Ed::IEdSpectrum^ spectrum);
 	void LogMessage(CString a_sMessage);
 
 	IMicroscopeController^ CreateMicroscopeController();

+ 7 - 7
OTSIncAMeasureApp/Program.cs

@@ -13,13 +13,13 @@ namespace OTSMeasureApp
         static void Main()
         {
             //判断是否有授权
-            //var reg = new CRegistration();
-            //if (!reg.RegistrationVerification())
-            //{
-            //    MessageBox.Show("Error: missing authorization");
-            //    System.Environment.Exit(0);
-            //    return;
-            //}
+            var reg = new CRegistration();
+            if (!reg.RegistrationVerification())
+            {
+                MessageBox.Show("Error: missing authorization");
+                System.Environment.Exit(0);
+                return;
+            }
             //--------------------------只运行一个测量程序--------------------------------
 
             bool flag = false;