瀏覽代碼

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

gaoshipeng 3 年之前
父節點
當前提交
c50ef34183

+ 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;

+ 233 - 88
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();
 
-			if (result->WeightPercent != 0)
+			String^ Quant = gcnew String("");
+
+			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,13 @@ bool OxfordControllerWrapper::StartImageCollecting()
 
 	try
 	{
-		auto image = imageAcqusitionController->StartAcquisition(imageAcqusitionSettings);
+		List<IElectronImage^>^ electronImageList = gcnew List<IElectronImage^>();
+
+		auto images = imageAcqusitionController->StartAcquisition(imageAcqusitionSettings);
 
-		return image != nullptr;
+
+
+		return images != nullptr;
 	}
 	catch (Exception^ /*ex*/)
 	{
@@ -1740,25 +1869,41 @@ 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 ((bool)e->Success)
+		{
+			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;
+			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
+		{
+			CString sMessage(_T("OnImageAcquisitionFinished failed") );
+			LogErrorTrace(__FILE__, __LINE__, sMessage);
+		}
+		
 	}
-	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 +2055,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;
 
@@ -2062,8 +2208,7 @@ IImageAcquisitionSettings^ OxfordControllerWrapper::GetImageAcqusitionSettings()
 		{
 			imageSettings->EnableInputSource(OINA::Extender::Data::Image::ImageInputSources::None, true);
 		}
-		//Action<>
-		//Enumerable::ToList(imageSettings->InputSources)->ForEach(imageSettings->EnableInputSource(i.Key, false));
+
 		_imageAcqusitionSettings->ImageSettings->DwellTimeMicroSeconds = 20;
 		_imageAcqusitionSettings->ScanSettings->AcquisitionRegion->CreateFullFieldRegion(1.0 / 1024.0);
 

+ 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();

+ 5 - 5
OTSCPP/OTSLog/COTSUtilityDllFunExport.cpp

@@ -212,12 +212,12 @@ bool SendLogMessageToNlog(LPCTSTR Msg, int postLogLevel)
 	{
 		HWND hd = GetDesktopWindow();        //得到桌面窗口
 		     hd = GetWindow(hd, GW_CHILD);        //得到屏幕上第一个子窗口
-		     char s[200] = { 0 };
+		     char s[1000] = { 0 };
 		     int num = 1;
 		     while (hd != NULL)                    //循环得到所有的子窗口
 		     {
-		       memset(s, 0, 200);
-		       GetWindowText(hd, s, 200);
+		       memset(s, 0, 1000);
+		       GetWindowText(hd, s, 1000);
 			   CString winTxt(s);
 			   if (winTxt.Find(_T("OTSMeasureApp"))>-1)//find the measure app mainform
 			   {
@@ -246,9 +246,9 @@ bool SendLogMessageToNlog(LPCTSTR Msg, int postLogLevel)
 	postlog.logLevel = postLogLevel;
 	int l = msg.GetLength();
 
-	if (l > 200)
+	if (l > 1000)
 	{
-		l = 200;
+		l = 1000;
 	}
 	for (int i = 0; i < l; i++)
 	{

+ 1 - 1
OTSCPP/OTSLog/COTSUtilityDllFunExport.h

@@ -3,7 +3,7 @@
  struct PostLogMsg
 {
 	int logLevel;
-	char logMsg[200];
+	char logMsg[1000];
 
 
 };

+ 1 - 1
OTSIncAMeasureApp/OTSMeasureOutputNlog.cs

@@ -14,7 +14,7 @@ namespace OTSMeasureApp
     public struct PostLogMsg
     {
         public int logLevel;//1 trace 2 debug 3info 4 warn 5 error 6 fatal
-        [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)200)]
+        [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)1000)]
         public char[] logMessage;
     };