123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367 |
- #include "stdafx.h"
- #include "OxfordControllerWrapper.h"
- #include "tinyxml2.h"
- #include "XMLSerialization.h"
- #include "COTSUtilityDllFunExport.h"
- using namespace System;
- using namespace System::Windows;
- using namespace System::Collections::Generic;
- using namespace System::Collections::ObjectModel;
- using namespace System::Collections::Specialized;
- using namespace System::ComponentModel;
- using namespace System::Windows::Forms;
- using namespace System::Threading;
- /// <summary>
- /// The oxford controller channels.
- /// Always collect xray by this channels.
- /// </summary>
- const int g_nOxfordControllerChannels = 4096; // use 2k to collect xray spectrum
- const int g_nOxfordControllerProcessTime = 4;
- const int g_nOxfordControllerEnergyRange = 20;
- const int g_nOxfordControllerEventWaitTimerInt = 100;
- const int g_nOxfordControllerEventSleepTimerInt = 100;
- const long g_nMicrocopeConnectTimeOutMilliSeconds = 2000;
- // Oxford single point delay time(ms)
- const long g_nSinglePointCollectDelay = 3000;
- const long g_nSingleFeatureCollectDelay = 5000;
- const long g_nXrayControllerConnectTimeOutMilliSeconds =20000;
- const long g_nImageTimeOutMilliSeconds = 40000;
- const long g_nStageTimeOutMilliSeconds = 40000;
- OxfordControllerWrapper::OxfordControllerWrapper(void)
- : m_bIsStageUpdated(false)
- , m_bBeamPositionSet(false)
- {
- //_dataType = ImageDataType::DataByte;
- m_startControllerEvent = gcnew AutoResetEvent(false);
- m_endControllerEvent = gcnew AutoResetEvent(false);
- }
- void OxfordControllerWrapper::CloseClient(void)
- {
- if (_controllerThread && _controllerThread->IsAlive)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::EXIT;
- //_controllerThread->Abort();
- }
-
- //_controllerThread = nullptr;
- _microscopeController = nullptr;
- _edSpectrumController = nullptr;
- _imageAcqusitionController = nullptr;
- _edsChordListController = nullptr;
- _SEMQuantController = nullptr;
-
-
- }
- OxfordControllerWrapper::~OxfordControllerWrapper(void)
- {
-
- CloseClient();
- }
- OxfordControllerWrapper::!OxfordControllerWrapper(void)
- {
-
-
- CloseClient();
- }
- bool OxfordControllerWrapper::Init()
- {
- if (_controllerThread != nullptr && _controllerThread->IsAlive)
- {
- return true;
- }
- _controllerThread = gcnew Thread(gcnew ThreadStart(this, &OxfordControllerWrapper::ControllerThreadFunction));
- m_startControllerEvent->Reset();
- m_endControllerEvent->Reset();
- if (_microscopeController == nullptr)
- {
- auto ctrl = CreateMicroscopeController();
- if (ctrl == nullptr) return false;
- }
- if (_edSpectrumController == nullptr)
- {
- auto ctrl1=CreateEdsSpectrumController();
- if (ctrl1 == nullptr) return false;
- }
- if (_imageAcqusitionController == nullptr)
- {
- auto ctrl2=CreateImageAcqusitionController();
- if (ctrl2 == nullptr) return false;
- }
- if (_edsChordListController == nullptr)
- {
- auto ctrl3=CreateChordlistController();
- if (ctrl3 == nullptr) return false;
- }
- _controllerThread->Start();
- return true;
- }
- void OxfordControllerWrapper::ControllerThreadFunction()
- {
-
- while (true)
- {
- while (true)
- {
- if (_oxfordControllerData.m_nCommand == OxfordControllerCommand::EXIT) break;
-
- if (m_startControllerEvent->WaitOne(0, true))
- {
- m_startControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
- }
- if (_oxfordControllerData.m_nCommand == OxfordControllerCommand::EXIT) break;
- switch (_oxfordControllerData.m_nCommand)
- {
- case OxfordControllerCommand::COLLECT_IMAGE:
- {
- if (!StartImageCollecting())
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- }
- }
-
- break;
- case OxfordControllerCommand::COLLECT_XRAYPOINT:
- {
- auto edsController = CreateEdsSpectrumController();
-
- bool bRet = false;
- if (edsController && _oxfordControllerData.m_pSpectrumData)
- {
- edsController->BeginMultipleAcquisition();
- LogTrace(__FILE__,__LINE__,_T("BeginMultipleAcquisition...(single point)"));
- if (SetBeamPosition(_oxfordControllerData.m_dBeamPositionX, _oxfordControllerData.m_dBeamPositionY))
- {
- bRet = StartXrayCollecting(_oxfordControllerData.m_nAcTime);
- }
- }
- if (!bRet)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- }
- }
- break;
- case OxfordControllerCommand::COLLECT_CURRENTXRAYPOINT:
- {
- auto edsController = CreateEdsSpectrumController();
-
- bool bRet = false;
- if (edsController && _oxfordControllerData.m_pSpectrumData)
- {
- edsController->BeginMultipleAcquisition();
-
- if (m_bBeamPositionSet)
- {
- m_bBeamPositionSet = false;
- bRet = true;
-
- Point pos(_oxfordControllerData.m_dBeamPositionX * _oxfordControllerData.m_dPixelSize, _oxfordControllerData.m_dBeamPositionY * _oxfordControllerData.m_dPixelSize);
- auto edsSettings = GetEdsSpectrumSettings();
- edsSettings->ScanSettings->AcquisitionRegion->CreatePointRegion(pos);
- }
- else
- {
- bRet = SetCurrentBeamPosition();
-
- }
- if (bRet)
- {
- bRet = StartXrayCollecting(_oxfordControllerData.m_nAcTime);
- }
- }
- if (!bRet)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- }
- }
- break;
- case OxfordControllerCommand::COLLECT_XRAYPOINTS:
- {
- auto edsController = CreateEdsSpectrumController();
-
- if (!edsController || !_oxfordControllerData.m_pXrayDataList || _oxfordControllerData.m_nXrayDataCount <= 0)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- auto edsSettings = GetEdsSpectrumSettings();
- _oxfordControllerData.m_nCollectedXrayCounts = 0;
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- edsController->BeginMultipleAcquisition();
-
- for (int i = 0; i < _oxfordControllerData.m_nXrayDataCount; ++i)
- {
- OxfordXrayData* pXrayData = &_oxfordControllerData.m_pXrayDataList[i];
- // <note>Accept pixel position to convert to oxford normalized beam position</note>
- Point pos(pXrayData->m_nPosX * _oxfordControllerData.m_dPixelSize, pXrayData->m_nPosY * _oxfordControllerData.m_dPixelSize);
- edsSettings->EdSettings->AcquisitionMode = (EdAcquireMode)2;
- edsSettings->EdSettings->AcquisitionTime = TimeSpan::FromMilliseconds(_oxfordControllerData.m_nAcTime);
- edsSettings->EdSettings->ProcessTime = 5;
- /*edsSettings->EdSettings->EnergyRange = 100;
- edsSettings->EdSettings->NumberOfChannels = 1;*/
- edsSettings->ScanSettings->AcquisitionRegion->CreatePointRegion(pos);
- edsController->StartAcquisition(edsSettings);
-
- }
- }
- }
- break;
- case OxfordControllerCommand::COLLECT_XRAYCHOILDLIST:
- {
- auto edsController = CreateEdsSpectrumController();
-
- if (!edsController || !_oxfordControllerData.m_pXrayDataList || _oxfordControllerData.m_nXrayDataCount <= 0)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- auto edsSettings = GetEdsSpectrumSettings();
- _oxfordControllerData.m_nCollectedXrayCounts = 0;
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- edsController->BeginMultipleAcquisition();
- _oxfordControllerData.m_nCollectedXrayCounts = 0;
-
- for (int i = 0; i < _oxfordControllerData.m_nXrayDataCount; i++)
- {
- List< OINA::Extender::Data::Chord^>^ chords = gcnew List<OINA::Extender::Data::Chord^>();
- for (int j = 0; j < _oxfordControllerData.m_pXrayDataList[i].m_nChordNum; j++)
- {
- int X = _oxfordControllerData.m_pXrayDataList[i].m_ChordList[j].m_nX;
- int Y = _oxfordControllerData.m_pXrayDataList[i].m_ChordList[j].m_nY;
- int XLength = _oxfordControllerData.m_pXrayDataList[i].m_ChordList[j].m_nLength;
- OINA::Extender::Data::Chord^ chord = gcnew OINA::Extender::Data::Chord(X, Y, XLength);
- chords->Add(chord);
- }
- OINA::Extender::Data::ChordList^ chordsList = gcnew OINA::Extender::Data::ChordList(chords, _oxfordControllerData.m_dPixelSize);//1/1024.0
- edsSettings->ScanSettings->AcquisitionRegion->CreateChordListRegion(chordsList);
- edsSettings->EdSettings->AcquisitionTime = TimeSpan::FromMilliseconds(_oxfordControllerData.m_nAcTime);
- edsController->StartAcquisition(edsSettings);
-
- }
- }
- }
- break;
- case OxfordControllerCommand::COLLECT_QUANTIFYSPECTRUM:
- if (!StartImageCollecting())
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::WORKING;
- }
- break;
- case OxfordControllerCommand::SET_POSITIONXY:
- {
- if (SetPositionXYToController(_oxfordControllerData.m_dPositionX, _oxfordControllerData.m_dPositionY))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
-
- long nCollectedTime = 0;
- while (!m_bIsStageUpdated)
- {
- Application::DoEvents();
-
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
-
- nCollectedTime += g_nOxfordControllerEventSleepTimerInt;
- if (nCollectedTime > g_nStageTimeOutMilliSeconds)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
-
- break;
- }
- }
- Thread::Sleep(500);
- m_endControllerEvent->Set();
- }
- break;
- case OxfordControllerCommand::STOP_ACQUISITION:
- {
- auto edsController = CreateEdsSpectrumController();
- while (edsController->IsAcquiring)
- {
- edsController->StopAcquisition();
- }
- }
- break;
- case OxfordControllerCommand::END_MULTIPLEACQUISITION:
- {
- auto edsController = CreateEdsSpectrumController();
- while (edsController->IsAcquiring)
- {
- edsController->StopAcquisition();
- }
- edsController->EndMultipleAcquisition();
- }
- break;
-
- }
- }
- }
- bool OxfordControllerWrapper::IsConnected()
- {
- if (IsMicroscopeColumnConnected()
- && IsMicroscopeStageConnected())
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- bool OxfordControllerWrapper::IsMicroscopeColumnConnected()
- {
- //auto microscopeController = this->CreateMicroscopeController();
- if (_microscopeController != nullptr)
- {
- return _microscopeController->ColumnConnectionStatus->IsConnected;
- }
- return false;
- }
- bool OxfordControllerWrapper::IsMicroscopeStageConnected()
- {
- //auto microscopeController = this->CreateMicroscopeController();
- if (_microscopeController != nullptr)
- {
- return _microscopeController->StageConnectionStatus->IsConnected;
- }
- return false;
- }
- IStageConditions^ OxfordControllerWrapper::GetStageConditions()
- {
- if (!IsMicroscopeStageConnected())
- {
- return nullptr;
- }
- return _microscopeController->StageConditions;
- }
- bool OxfordControllerWrapper::GetPositionXY(double& a_dPosX, double& a_dPosY)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_POSITIONXY;
- double dX, dY;
- if (GetPositionXYFromController(dX, dY))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- _oxfordControllerData.m_dPositionX = dX;
- _oxfordControllerData.m_dPositionY = dY;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_dPosX = _oxfordControllerData.m_dPositionX;
- a_dPosY = _oxfordControllerData.m_dPositionY;
- return true;
- }
- return false;
- }
- /// <summary>
- /// Get position xy from controller
- /// </summary>
- /// <param name="a_dPosX">The double of position x.</param>
- /// <param name="a_dPosY">The double of position y.</param>
- /// <returns>
- /// Return the position xy from controller
- /// </returns>
- bool OxfordControllerWrapper::GetPositionXYFromController(double& a_dPosX, double& a_dPosY)
- {
- if (!IsMicroscopeStageConnected())
- {
- return false;
- }
- while(!_microscopeController->StageCapabilities->StageX->CanRead)
- {
- Sleep(100);
- }
- a_dPosX = _microscopeController->StageConditions->StageX * 1000.0;
- while(!_microscopeController->StageCapabilities->StageY->CanRead)
- {
- Sleep(100);
- }
- a_dPosY = _microscopeController->StageConditions->StageY * 1000.0;
- return true;
- }
- /// <summary>
- /// Set the position xy
- /// </summary>
- /// <param name="a_dPosX">The double of position x.</param>
- /// <param name="a_dPosY">The double of position y.</param>
- /// <returns>TRUE if success, otherwise FALSE</returns>
- bool OxfordControllerWrapper::SetPositionXY(const double a_dPosX, const double a_dPosY)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_POSITIONXY;
- _oxfordControllerData.m_dPositionX = a_dPosX;
- _oxfordControllerData.m_dPositionY = a_dPosY;
- m_bIsStageUpdated = false;
- m_startControllerEvent->Set();
- long nCollectedTime = 0;
- while (true)
- {
-
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
-
- Application::DoEvents();
-
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- else
- {
- return false;
- }
-
-
- }
- bool OxfordControllerWrapper::SetPositionXYToController(const double a_dPosX, const double a_dPosY)
- {
- if (!IsMicroscopeStageConnected())
- {
- return false;
- }
- Dictionary<Stage, double>^ stageDictionary = gcnew Dictionary<Stage, double>;
- stageDictionary->Add(Stage::StageX, a_dPosX / 1000.0);
- stageDictionary->Add(Stage::StageY, a_dPosY / 1000.0);
- _microscopeController->SetStageConditions(stageDictionary);
- return true;
- }
- bool OxfordControllerWrapper::GetWorkingDistance(double& a_dWorkingDistance)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_WORKINGDISTANCE;
- double dWD = 0;
- if (GetWorkingDistanceFromController(dWD))
- {
- _oxfordControllerData.m_dWorkingDistance = dWD;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_dWorkingDistance = _oxfordControllerData.m_dWorkingDistance;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetWorkingDistanceFromController(double& a_dWorkingDistance)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- a_dWorkingDistance = _microscopeController->ColumnConditions->WorkingDistance;
- return true;
- }
- bool OxfordControllerWrapper::SetWorkingDistance(double a_dWorkingDistance)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_WORKINGDISTANCE;
- _oxfordControllerData.m_dWorkingDistance = a_dWorkingDistance;
- if (SetWorkingDistanceToController(_oxfordControllerData.m_dWorkingDistance))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetWorkingDistanceToController(double a_dWorkingDistance)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- Dictionary<Column, double>^ columnDictionary = gcnew Dictionary<Column, double>;
- columnDictionary->Add(Column::WorkingDistance, a_dWorkingDistance);
- _microscopeController->SetColumnConditions(columnDictionary);
- return true;
- }
- bool OxfordControllerWrapper::GetMagnification(double& a_dMagnification)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_MAGNIFICATION;
- double dMag = 0;
- if (GetMagnificationFromController(dMag))
- {
- _oxfordControllerData.m_dMagnification = dMag;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_dMagnification = _oxfordControllerData.m_dMagnification;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetMagnificationFromController(double& a_dMagnification)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- a_dMagnification = _microscopeController->ColumnConditions->Magnification;
- return true;
- }
- bool OxfordControllerWrapper::SetMagnification(double a_dMagnification)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_MAGNIFICATION;
- _oxfordControllerData.m_dMagnification = a_dMagnification;
- if (SetMagnificationToController(_oxfordControllerData.m_dMagnification))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetMagnificationToController(double a_dMagnification)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- Dictionary<Column, double>^ columnDictionary = gcnew Dictionary<Column, double>;
- columnDictionary->Add(Column::Magnification, a_dMagnification);
- _microscopeController->SetColumnConditions(columnDictionary);
- return true;
- }
- bool OxfordControllerWrapper::GetHighVoltage(double& a_dHighVoltage)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_HIGHVOTAGE;
- double dValue = 0;
- if (GetHighVoltageFromController(dValue))
- {
- _oxfordControllerData.m_dHighVotage = dValue;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_dHighVoltage = _oxfordControllerData.m_dHighVotage;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetHighVoltageFromController(double& a_dHighVoltage)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- a_dHighVoltage = _microscopeController->ColumnConditions->HighVoltage;
- return true;
- }
- bool OxfordControllerWrapper::SetHighVoltage(double a_dHighVoltage)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_HIGHVOTAGE;
- _oxfordControllerData.m_dHighVotage = a_dHighVoltage;
- if (SetHighVoltageToController(_oxfordControllerData.m_dHighVotage))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetHighVoltageToController(double a_dHighVoltage)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- Dictionary<Column, double>^ columnDictionary = gcnew Dictionary<Column, double>;
- columnDictionary->Add(Column::HighVoltage, a_dHighVoltage);
- _microscopeController->SetColumnConditions(columnDictionary);
- return true;
- }
- bool OxfordControllerWrapper::GetBeamOn(bool& a_bBeamOn)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_BEAMON;
- //m_startControllerEvent->Set();
- bool bValue;
- if (GetBeamOnFromController(bValue))
- {
- _oxfordControllerData.m_bBeamOn = bValue;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_bBeamOn = _oxfordControllerData.m_bBeamOn;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetBeamOnFromController(bool& a_bBeamOn)
- {
- if (!IsMicroscopeColumnConnected())
- {
- return false;
- }
- double dValue = _microscopeController->ColumnConditions->BeamOn;
- // notice: false: 0.0 and true: 1.0
- a_bBeamOn = dValue > 0.1;
- return true;
- }
- bool OxfordControllerWrapper::SetBeamOn(bool a_bBeamOn)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_BEAMON;
- _oxfordControllerData.m_bBeamOn = a_bBeamOn;
- if (SetBeamOnToController(_oxfordControllerData.m_bBeamOn))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetBeamOnToController(bool a_bBeamOn)
- {
- if (!IsConnected())
- {
- return false;
- }
- (void)a_bBeamOn;
- return true;
- }
- bool OxfordControllerWrapper::GetBeamBlank(bool& a_bBeamBlank)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_BEAMBLANK;
- bool bValue;
- if (GetBeamBlankFromController(bValue))
- {
- _oxfordControllerData.m_bBeamBlank = bValue;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_bBeamBlank = _oxfordControllerData.m_bBeamBlank;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetBeamBlankFromController(bool& a_bBeamBlank)
- {
- if (!IsConnected())
- {
- return false;
- }
- // todo: get beam blank
- a_bBeamBlank = true;
- return true;
- }
- bool OxfordControllerWrapper::SetBeamBlank(bool a_bBeamBlank)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_BEAMBLANK;
- _oxfordControllerData.m_bBeamBlank = a_bBeamBlank;
- if (SetBeamBlankToController(_oxfordControllerData.m_bBeamBlank))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetBeamBlankToController(bool a_bBeamBlank)
- {
- if (!IsConnected())
- {
- return false;
- }
- // todo: set beam blank
- (void)a_bBeamBlank;
- //try
- //{
- //_microscopeController->ColumnConditions->BeamOn = a_bBeamBlank;
- //}
- //catch(...)
- //{
- //}
- return true;
- }
- bool OxfordControllerWrapper::GetExternalScan(bool& a_bExternal)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::GET_EXTERNAL;
- bool bValue;
- if (GetExternalScanFromController(bValue))
- {
- _oxfordControllerData.m_bExternal = bValue;
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- a_bExternal = _oxfordControllerData.m_bExternal;
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::GetExternalScanFromController(bool& a_bExternal)
- {
- if (!IsConnected())
- {
- return false;
- }
- a_bExternal = _microscopeController->IsInExternalScan;
- return true;
- }
- bool OxfordControllerWrapper::SetExternalScan(bool a_bExternal)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::SET_EXTERNAL;
- _oxfordControllerData.m_bExternal = a_bExternal;
-
- if (SetExternalScanToController(_oxfordControllerData.m_bExternal))
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- }
-
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetExternalScanToController(bool a_bExternal)
- {
- if (!IsConnected())
- {
- return false;
- }
- _microscopeController->SetExternalScan(a_bExternal);
- return true;
- }
- /// <summary>
- /// Set the beam position
- /// </summary>
- /// <param name="a_dPosX">The double of position x.</param>
- /// <param name="a_dPosY">The double of position y.</param>
- /// <note>Accept pixel position to convert to oxford normalized beam position</note>
- /// <returns>TRUE if success, otherwise FALSE</returns>
- bool OxfordControllerWrapper::SetBeamPosition(const double a_dPosX, const double a_dPosY)
- {
- auto edsSettings = GetEdsSpectrumSettings();
- if (!edsSettings)
- {
- return false;
- }
- m_bBeamPositionSet = true;
- _oxfordControllerData.m_dBeamPositionX = a_dPosX;
- _oxfordControllerData.m_dBeamPositionY = a_dPosY;
- return true;
- }
- bool OxfordControllerWrapper::SetCurrentBeamPosition()
- {
- auto edsSettings = GetEdsSpectrumSettings();
- if (!edsSettings)
- {
- return false;
- }
- auto ret = edsSettings->ScanSettings->AcquisitionRegion->CreateMicroscopeRegion();
- return ret != nullptr;
- }
- bool OxfordControllerWrapper::StartXrayCollecting(const long a_nAcTimeMilliseconds)
- {
- auto edsController = CreateEdsSpectrumController();
- if (!edsController)
- {
- return false;
- }
- auto edsSettings = GetEdsSpectrumSettings();
- /*edsSettings->EdSettings->AcquisitionTime = TimeSpan::FromMilliseconds(a_nAcTimeMilliseconds);
- edsSettings->EdSettings->ProcessTime = 4;*/
- edsSettings->EdSettings->AcquisitionMode = (EdAcquireMode)2;
- edsSettings->EdSettings->AcquisitionTime = TimeSpan::FromMilliseconds(_oxfordControllerData.m_nAcTime);
- edsSettings->EdSettings->ProcessTime = 5;
- auto spectrum = edsController->StartAcquisition(edsSettings);
- return spectrum != nullptr;
- }
- bool OxfordControllerWrapper::StopXrayCollecting()
- {
- auto edsController = CreateEdsSpectrumController();
- if (!edsController)
- {
- return false;
- }
- if (edsController->IsAcquiring)
- {
- edsController->StopAcquisition();
- }
- return !edsController->IsAcquiring;
- }
- void OxfordControllerWrapper::XraySpectrumProcess(OINA::Extender::Data::Ed::IEdSpectrum^ spectrum)
- {
- try
- {
- //Quantify processing
- IEdSpectrumProcessing^ EdSpectrumProcessing = ProcessingFactory::CreateSpectrumProcessing();
- // 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);
- 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;
- ISEMQuantStatus^ quantStatus = EdSpectrumProcessing->SEMQuantifySpectrum(spectrum, 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(spectrum, _oxfordControllerData.m_pSpectrumData, _oxfordControllerData.m_nBufferSize);
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- auto edsController = CreateEdsSpectrumController();
- if (edsController)
- {
- 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(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();
- }
- }
- }
- }
- catch (Exception^ ex)
- {
- CString sMessage(_T("OnXrayAcquisitionFinished failed") + ex->ToString());
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- }
- }
- void OxfordControllerWrapper::OnXrayAcquisitionFinished(Object^ sender, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdSpectrum^>^ e)
- {
- try
- {
- //Quantify processing
- IEdSpectrumProcessing^ EdSpectrumProcessing = ProcessingFactory::CreateSpectrumProcessing();
- // 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;
- 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();
- if (edsController)
- {
- 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;
- if (_oxfordControllerData.m_pXrayDataList == NULL)
- {
- return;
- }
- 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);
- auto edsController = CreateEdsSpectrumController();
- if (edsController)
- {
- edsController->EndMultipleAcquisition();
- m_endControllerEvent->Set();
- }
- }
- }
- void OxfordControllerWrapper::OnXrayChordlistFinished(Object^, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdMap^>^ e)
- {
- }
- bool OxfordControllerWrapper::CollectXrayPoint(const double a_dPosX, const double a_dPosY, const long a_nAcTimeMilliseconds, long* a_pSpectrumData, DWORD a_nBufferSize)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::COLLECT_XRAYPOINT;
- _oxfordControllerData.m_dBeamPositionX = a_dPosX;
- _oxfordControllerData.m_dBeamPositionY = a_dPosY;
- _oxfordControllerData.m_nAcTime = a_nAcTimeMilliseconds;
- _oxfordControllerData.m_pSpectrumData = a_pSpectrumData;
- _oxfordControllerData.m_nBufferSize = a_nBufferSize;
- m_startControllerEvent->Set();
- Thread::Sleep(a_nAcTimeMilliseconds);
- long nCollectedTime = a_nAcTimeMilliseconds;
- long nCollectedTimeLimit = nCollectedTime + g_nSinglePointCollectDelay + g_nXrayControllerConnectTimeOutMilliSeconds;
- while (true)
- {
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
- nCollectedTime += g_nOxfordControllerEventSleepTimerInt;
- if (nCollectedTime > nCollectedTimeLimit)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::END_MULTIPLEACQUISITION;
- m_startControllerEvent->Set();
-
- m_endControllerEvent->Reset();
- break;
- }
- }
- _oxfordControllerData.m_pSpectrumData = nullptr;
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::CollectXrayPoint(const long a_nAcTimeMilliseconds, long* a_pSpectrumData, DWORD a_nBufferSize)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::COLLECT_CURRENTXRAYPOINT;
- _oxfordControllerData.m_nAcTime = a_nAcTimeMilliseconds;
- _oxfordControllerData.m_pSpectrumData = a_pSpectrumData;
- _oxfordControllerData.m_nBufferSize = a_nBufferSize;
- m_startControllerEvent->Set();
- Thread::Sleep(a_nAcTimeMilliseconds);
- long nCollectedTime = a_nAcTimeMilliseconds;
- long nCollectedTimeLimit = nCollectedTime + g_nSinglePointCollectDelay + g_nXrayControllerConnectTimeOutMilliSeconds;
- while (true)
- {
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
- nCollectedTime += g_nOxfordControllerEventSleepTimerInt;
- if (nCollectedTime > nCollectedTimeLimit)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::END_MULTIPLEACQUISITION;
- m_startControllerEvent->Set();
- m_endControllerEvent->Reset();
- break;
- }
- }
- _oxfordControllerData.m_pSpectrumData = nullptr;
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::CollectXrayPoints(const long a_nAcTimeMilliseconds, OxfordXrayData* a_pXrayDataList, const long a_nXrayDataCount, DWORD a_nBufferSize)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::COLLECT_XRAYPOINTS;
- _oxfordControllerData.m_nAcTime = a_nAcTimeMilliseconds;
- _oxfordControllerData.m_pXrayDataList = a_pXrayDataList;
- _oxfordControllerData.m_nXrayDataCount = a_nXrayDataCount;
- _oxfordControllerData.m_nBufferSize = a_nBufferSize;
-
- Thread::Sleep(300);
- m_startControllerEvent->Set();
- long nCollectedTime = 1000;
- long nCollectedTimeLimit = nCollectedTime + a_nXrayDataCount * g_nSinglePointCollectDelay + g_nXrayControllerConnectTimeOutMilliSeconds;
- while (true)
- {
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
- nCollectedTime += g_nOxfordControllerEventSleepTimerInt;
- if (nCollectedTime > nCollectedTimeLimit)
- {
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::END_MULTIPLEACQUISITION;
- m_startControllerEvent->Set();
- m_endControllerEvent->Reset();
- break;
- }
- }
- _oxfordControllerData.m_pXrayDataList = nullptr;
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::CollectXrayFeatures(const long a_nAcTimeMilliseconds, OxfordXrayData* a_pXrayDataList, const long a_nXrayDataCount, DWORD a_nBufferSize)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::COLLECT_XRAYCHOILDLIST;
- _oxfordControllerData.m_nAcTime = a_nAcTimeMilliseconds;
- _oxfordControllerData.m_pXrayDataList = a_pXrayDataList;
- _oxfordControllerData.m_nXrayDataCount = a_nXrayDataCount;//要采集的feature个数
- _oxfordControllerData.m_nCollectedXrayCounts = 0;
- _oxfordControllerData.m_nChordsNum = a_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_nChordNum;
- _oxfordControllerData.m_nCollectedChordsCount = 0;
- _oxfordControllerData.m_nBufferSize = a_nBufferSize;
-
- //当前采集的feature包含的像素的个数
- _oxfordControllerData.m_nPixelNum = a_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_nPixelNum;
- _oxfordControllerData.m_nCollectedPixelCounts = 0;
- Thread::Sleep(300);
- m_startControllerEvent->Set();
- //Thread::Sleep(a_nAcTimeMilliseconds * a_nXrayDataCount);
- long nCollectedTime =1000;
- long nCollectedTimeLimit = nCollectedTime + a_nXrayDataCount * g_nSingleFeatureCollectDelay + g_nXrayControllerConnectTimeOutMilliSeconds;
- while (true)
- {
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventSleepTimerInt);
- nCollectedTime += g_nOxfordControllerEventSleepTimerInt;
- if (nCollectedTime > nCollectedTimeLimit)
- {
- CString sMessage;
- sMessage.Format(_T("Error: Total collected time(%d) over limit(%d)"), nCollectedTime, nCollectedTimeLimit);
-
- LogErrorTrace(__FILE__,__LINE__,sMessage);
- sMessage.Format(_T("1Total collected xray %d / %d"), _oxfordControllerData.m_nCollectedXrayCounts, _oxfordControllerData.m_nXrayDataCount);
-
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Reset();
- break;
- }
- }
- _oxfordControllerData.m_pXrayDataList = nullptr;
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- CString sMessage;
- sMessage.Format(_T("CollectXrayArea failed."));
- LogErrorTrace(__FILE__, __LINE__, sMessage);
-
- return false;
- }
- bool OxfordControllerWrapper::ConvertSpectrumData(IEdSpectrum^ a_spectrum, long* a_pSpectrumData, int a_nBufferSize)
- {
- if (!a_spectrum || !a_pSpectrumData)
- {
- return false;
- }
- memset(a_pSpectrumData, 0, sizeof(long) * a_nBufferSize);
- array<int>^ xrayData = gcnew array<int>(a_spectrum->NumberOfChannels);
- a_spectrum->GetChannelData(xrayData);
- double dZeroChannelValue = a_spectrum->ZeroChannelValue;
- int nChannelStart = 0;
- if (dZeroChannelValue < 0) // zero channel value should less than zero
- {
- nChannelStart = (int)(-dZeroChannelValue / a_spectrum->ChannelWidth + 0.5);
- }
- int nDataLength = (int)(a_spectrum->EnergyRange * 1000 / a_spectrum->ChannelWidth + 0.5);
- double dStep1 = 1.0 / nDataLength;
- double dStep2 = 1.0 / a_nBufferSize;
- for (int i = 0; i < nDataLength; ++i)
- {
- int nValue = xrayData[i + nChannelStart] > 0 ? xrayData[i + nChannelStart] : 0;
- double dBinPos = i * dStep1;
- long nLeftBin = (long)(dBinPos / dStep2);
- // calculate % into left bin
- double dLeft_Percent = double(nLeftBin + 1) - dBinPos / dStep2; // ((nLeftBin + 1)*dStep2 - dBinPos)/dStep2
- // calculate data into the left bin
- long nValueToLeftBin = (long)((double)nValue * dLeft_Percent + 0.5);
- // put data into bins
- a_pSpectrumData[nLeftBin] += nValueToLeftBin;
- if ((nLeftBin + 1) < (long)a_nBufferSize)
- {
- a_pSpectrumData[nLeftBin + 1] += (nValue - nValueToLeftBin);
- }
- }
- return true;
- }
- bool OxfordControllerWrapper::IsXrayCollecting()
- {
- if (_edSpectrumController)
- {
- return _edSpectrumController->IsAcquiring;
- }
- return false;
- }
- bool OxfordControllerWrapper::IsImageCollecting()
- {
- if (_imageAcqusitionController)
- {
- return _imageAcqusitionController->IsAcquiring;
- }
- return false;
- }
- bool OxfordControllerWrapper::IsQuantifySpectrumCollecting()
- {
- if (_edSpectrumController)
- {
- return _edSpectrumController->IsAcquiring;
- }
- return false;
- }
- bool OxfordControllerWrapper::SetScanSpeed(const long a_nMilliseconds)
- {
- auto imageAcqusitionSettings = GetImageAcqusitionSettings();
- imageAcqusitionSettings->ImageSettings->DwellTimeMicroSeconds = a_nMilliseconds;
- return true;
- }
- bool OxfordControllerWrapper::GetImageSize(long& a_nWidth, long& a_nHeight)
- {
- a_nWidth = _oxfordControllerData.m_nImageWidth;
- a_nHeight = _oxfordControllerData.m_nImageHeight;
- return true;
- }
- bool OxfordControllerWrapper::SetImageSize(const long a_nWidth, const long a_nHeight)
- {
-
- _oxfordControllerData.m_nImageWidth = a_nWidth;
- _oxfordControllerData.m_nImageHeight = a_nHeight;
- auto imageAcqusitionSettings = GetImageAcqusitionSettings();
- imageAcqusitionSettings->ScanSettings->AcquisitionRegion->CreateFullFieldRegion(1.0 / a_nWidth);
- return true;
- }
- bool OxfordControllerWrapper::CollectImage(int a)
- {
- return true;
- }
- bool OxfordControllerWrapper::QuantifySpectrum(unsigned char* cResult)
- {
- CString result = _oxfordControllerData.m_sElementResult;
- cResult = (unsigned char*)result.GetBuffer();
- return true;
- }
- bool OxfordControllerWrapper::CollectImage(BYTE* a_pImageBits)
- {
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::COLLECT_IMAGE;
- _oxfordControllerData.m_pImageBits = a_pImageBits;
- m_startControllerEvent->Set();
- long nCollectedTime = 0;
- long nCollectedTimeLimit = g_nImageTimeOutMilliSeconds;
-
- while (true)
- {
- if (m_endControllerEvent->WaitOne(0, true))
- {
- m_endControllerEvent->Reset();
- break;
- }
- Application::DoEvents();
- Thread::Sleep(g_nOxfordControllerEventWaitTimerInt);
-
-
- nCollectedTime += g_nOxfordControllerEventWaitTimerInt;
- if (nCollectedTime > nCollectedTimeLimit)
- {
- //this->CreateImageAcqusitionController();
-
- _oxfordControllerData.m_nCommand = OxfordControllerCommand::STOP_ACQUISITION;
- m_startControllerEvent->Set();
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
-
- m_endControllerEvent->Reset();
- break;
- }
- }
- _oxfordControllerData.m_pImageBits = nullptr;
- if (_oxfordControllerData.m_nState == OxfordControllerState::SUCCEEDED)
- {
- return true;
- }
- return false;
- }
- bool OxfordControllerWrapper::ReadImageData(IElectronImage^ a_electronImage, BYTE* a_pImageBits)
- {
- if (a_electronImage == nullptr)
- {
- return false;
- }
- if (a_pImageBits == NULL)
- {
- return false;
- }
- _oxfordControllerData.m_nImageWidth = a_electronImage->Width;
- _oxfordControllerData.m_nImageHeight = a_electronImage->Height;
- _oxfordControllerData.m_dPixelSize = a_electronImage->PixelSize;
- int nBytesPerPixel = a_electronImage->BytesPerPixel;
- int nImageSize = _oxfordControllerData.m_nImageWidth * _oxfordControllerData.m_nImageHeight;
- int nBufferSize = _oxfordControllerData.m_nImageWidth * _oxfordControllerData.m_nImageHeight * nBytesPerPixel;
- array<byte>^ imageData = gcnew array<byte>(nBufferSize);
- a_electronImage->GetData(imageData);
- // default, oxford will return short image, we need to convert to byte
- if (nBytesPerPixel == 2)
- {
- int nBSEValue = 0;
- for (int i = 0; i < nImageSize; ++i)
- {
- nBSEValue = imageData[0 + i * nBytesPerPixel] + imageData[1 + i * nBytesPerPixel] * 255;
- a_pImageBits[i] = (BYTE)(nBSEValue / 128.0 + 0.5);
- }
- }
- else
- {
- int nOffset = nBytesPerPixel - 1;
- for (int i = 0; i < nImageSize; ++i)
- {
- #ifdef _DEBUG
- byte nValue = imageData[nBytesPerPixel - 1 + i * nBytesPerPixel];
- a_pImageBits[i] = nValue;
- #else
- a_pImageBits[i] = imageData[nOffset + i * nBytesPerPixel];
- #endif
- }
- }
- return true;
- }
- bool OxfordControllerWrapper::StartImageCollecting()
- {
- auto imageAcqusitionController = CreateImageAcqusitionController();
- auto imageAcqusitionSettings = GetImageAcqusitionSettings();
- if (imageAcqusitionController == nullptr)
- {
- return false;
- }
- if (imageAcqusitionSettings == nullptr)
- {
- return false;
- }
- try
- {
- List<IElectronImage^>^ electronImageList = gcnew List<IElectronImage^>();
- auto images = imageAcqusitionController->StartAcquisition(imageAcqusitionSettings);
- return images != nullptr;
- }
- catch (Exception^ /*ex*/)
- {
- CString sMessage(_T("StartImageCollecting: Start Acquisition failed"));
-
- LogErrorTrace(__FILE__,__LINE__,sMessage);
- }
- return false;
- }
- void OxfordControllerWrapper::OnImageAcquisitionFinished(Object^ /*sender*/, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<array<OINA::Extender::Data::Image::IElectronImage^ >^ >^ e)
- {
- List<IElectronImage^>^ electronImageList = gcnew List<IElectronImage^>();
- try
- {
- 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;
- }
- else
- {
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- }
- }
- else
- {
- CString sMessage(_T("OnImageAcquisitionFinished failed") );
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- }
-
- }
- catch (Exception^ ex)
- {
- CString sMessage(_T("OnImageAcquisitionFinished failed")+ex->ToString());
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- }
- m_endControllerEvent->Set();
- }
- void OxfordControllerWrapper::OnController_PixelProcessed(Object^ /*sender*/, OINA::Extender::EventArgs<OINA::Extender::Processing::Quant::IPixelSEMQuantStatus^ >^ e)
- {
- _oxfordControllerData.m_nCollectedPixelCounts++;
- //更新当前feature的元素成分
- //Get element result for single point
- auto ie = e->Value->QuantStatus->Results->GetEnumerator();
-
- while (ie->MoveNext())
- {
- ISEMQuantResult^ result = ie->Current;
- if (result->WeightPercent != 0)
- {
- Element^ Quant = gcnew Element();
- Quant->m_nAotomaticNo = result->AtomicNumber;
- Quant->m_dWeight = result->WeightPercent;
- if (_oxfordControllerData.m_listElementResult == nullptr)
- {
- _oxfordControllerData.m_listElementResult = gcnew List<Element^ >();
- _oxfordControllerData.m_listElementResult->Add(Quant);
- }
- else
- {
- bool bFind = false;
- for (int i = 0; i < _oxfordControllerData.m_listElementResult->Count; i++)
- {
- Element^ result = _oxfordControllerData.m_listElementResult[i];
- if (Quant->m_nAotomaticNo == result->m_nAotomaticNo)
- {
- result->m_dWeight += Quant->m_dWeight;
- bFind = true;
- }
- }
- if (!bFind)
- {
- _oxfordControllerData.m_listElementResult->Add(Quant);
- }
- }
- }
- }
- //当前的chord数据中pixel没有采集完整
- if (_oxfordControllerData.m_nCollectedPixelCounts == _oxfordControllerData.m_nPixelNum)
- {
- //形成quant数据
- CString Quant = _T("");
- for (int i = 0; i < _oxfordControllerData.m_listElementResult->Count; i++)
- {
- Element^ result = _oxfordControllerData.m_listElementResult[i];
- Quant += "Quant=";
- CString strAoto(ElementProperties::GetElementSymbol(result->m_nAotomaticNo));
- Quant += strAoto;
- Quant += ",";
- Quant += _T("K-serials");
- Quant += ",";
- CString strWeight = (result->m_dWeight / (double)_oxfordControllerData.m_nPixelNum).ToString();
- Quant += strWeight ;
- 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);
- }
- _oxfordControllerData.m_nCollectedXrayCounts++;
- if (_oxfordControllerData.m_nCollectedXrayCounts < _oxfordControllerData.m_nXrayDataCount)
- {
- _oxfordControllerData.m_nPixelNum = _oxfordControllerData.m_pXrayDataList[_oxfordControllerData.m_nCollectedXrayCounts].m_nPixelNum;
- _oxfordControllerData.m_nCollectedPixelCounts = 0;
- _oxfordControllerData.m_listElementResult->Clear();
- }
-
- }
- }
- void OxfordControllerWrapper::OnController_ExperimentFinished(Object^ /*sender*/, OINA::Extender::Acquisition::AcquisitionFinishedEventArgs^ e)
- {
- if (_oxfordControllerData.m_nCollectedXrayCounts == _oxfordControllerData.m_nXrayDataCount)
- _oxfordControllerData.m_nState = OxfordControllerState::SUCCEEDED;
- else
- _oxfordControllerData.m_nState = OxfordControllerState::FAILED;
- m_endControllerEvent->Set();
- }
- bool OxfordControllerWrapper::StopImageCollecting()
- {
- auto imageAcqusitionController = CreateImageAcqusitionController();;
- try
- {
- if (imageAcqusitionController->IsAcquiring)
- {
- imageAcqusitionController->StopAcquisition();
- }
- }
- catch (Exception^ ex)
- {
- CString sMessage = ex->Message;
- CString sErrorMessage;
- sErrorMessage.Format(_T("StopImageCollecting: Stop Acquisition caught(%s)"), sMessage);
-
- LogErrorTrace(__FILE__, __LINE__, sErrorMessage);
- }
- return !imageAcqusitionController->IsAcquiring;
- }
- IMicroscopeController^ OxfordControllerWrapper::CreateMicroscopeController()
- {
- if (_microscopeController != nullptr)
- {
- return _microscopeController;
- }
- 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);
- LogErrorTrace(__FILE__, __LINE__, sErrorMessage);
- return nullptr;
- }
- if (_microscopeController == nullptr)
- {
- CString 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);
- return nullptr;
- }
- _microscopeController->ColumnChange += gcnew EventHandler<OINA::Extender::MicroscopeControl::ColumnEventArgs^>(this, &OxfordControllerWrapper::OnMicroscopeColumnUpdated);
- //_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;
- auto nStart = GetTickCount64();
- auto nEnd = nStart;
- do
- {
- if (IsMicroscopeColumnConnected()
- && IsMicroscopeStageConnected())
- {
- break;
- }
- nEnd = GetTickCount64();
- } while (nEnd >= nStart && nEnd <= (nStart + g_nMicrocopeConnectTimeOutMilliSeconds));
- return _microscopeController;
- }
- IEdSpectrumAcquisitionController^ OxfordControllerWrapper::CreateEdsSpectrumController()
- {
-
- if (_edSpectrumController == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("CreateEdSpectrumServer..."));
- try
- {
- _edSpectrumController = AcquireFactory::CreateEdSpectrumServer();
- _edSpectrumController->ExperimentFinished += gcnew EventHandler<OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<OINA::Extender::Data::Ed::IEdSpectrum^>^>(this, &OxfordControllerWrapper::OnXrayAcquisitionFinished);
- auto edsSpectrumSettings = GetEdsSpectrumSettings();
- while (true)
- {
- /*if (_edSpectrumController->IsEdHardwareReady(edsSpectrumSettings))
- {*/
- if (edsSpectrumSettings->EdCapabilities->HasHardwareConnection)
- {
- break;
- }
- //}
- }
- }
- catch (const std::exception& e)
- {
- CString msg(e.what());
- LogTrace(__FILE__, __LINE__,msg);
- return nullptr;
- }
-
- }
- return _edSpectrumController;
- }
- IEdSpectrumSettings^ OxfordControllerWrapper::GetEdsSpectrumSettings()
- {
- if (_edsSpectrumSettings == nullptr)
- {
- _edsSpectrumSettings = AcquireFactory::CreateEdSpectrumSettings();
- if (_edsSpectrumSettings == nullptr)
- {
- CString sMessage(_T("Create EDS Spectrum setting failed."));
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- ASSERT(FALSE);
- }
- else
- {
- _edsSpectrumSettings->EdSettings->AcquisitionMode = EdAcquireMode::LiveTime;
- //_edsSpectrumSettings->EdSettings->AcquisitionTime = TimeSpan::FromSeconds(1);
- _edsSpectrumSettings->EdSettings->NumberOfChannels = g_nOxfordControllerChannels;
- _edsSpectrumSettings->EdSettings->ProcessTime = g_nOxfordControllerProcessTime;
- _edsSpectrumSettings->EdSettings->EnergyRange = g_nOxfordControllerEnergyRange;
- }
- }
- return _edsSpectrumSettings;
- }
- IImageAcquisitionController^ OxfordControllerWrapper::CreateImageAcqusitionController()
- {
- if (_imageAcqusitionController == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("CreateImageAcqusitionController..."));
- try
- {
- _imageAcqusitionController = AcquireFactory::CreateImageServer();
-
- //_imageAcqusitionController->ExperimentStarted += gcnew EventHandler<OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<array<OINA::Extender::Data::Image::IElectronImage^ >^ >^>(this, &OxfordControllerWrapper::OnImageAcquisitioStarted);
- _imageAcqusitionController->ExperimentFinished += gcnew EventHandler<OINA::Extender::Acquisition::AcquisitionFinishedEventArgs<array<OINA::Extender::Data::Image::IElectronImage^ >^ >^>(this, &OxfordControllerWrapper::OnImageAcquisitionFinished);
- auto imageAcqusitionSettings = GetImageAcqusitionSettings();
- while (true)
- {
- /*if (_imageAcqusitionController->IsImageHardwareReady(imageAcqusitionSettings))
- {*/
- if (imageAcqusitionSettings->ImageCapabilities->HasHardwareConnection)
- {
- break;
- }
- //}
- }
- }
- catch (Exception^ ex)
- {
- CString sMessage = ex->Message;
-
-
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- return nullptr;
- }
- }
- return _imageAcqusitionController;
- }
- IImageAcquisitionSettings^ OxfordControllerWrapper::GetImageAcqusitionSettings()
- {
- if (_imageAcqusitionSettings == nullptr)
- {
- _imageAcqusitionSettings = AcquireFactory::CreateImageSettings();
- _imageAcqusitionSettings->ScanSettings->FrameCount = 1;
- IImageSettings^ imageSettings = _imageAcqusitionSettings->ImageSettings;
- for each (KeyValuePair<OINA::Extender::Data::Image::ImageInputSources, bool>^ imputSource in imageSettings->InputSources)
- {
- imageSettings->EnableInputSource(imputSource->Key, false);
- }
- CString szXMLFileName = "./Config/ProData/HardwareConfig.xml";
- tinyxml2::XMLDocument doc;
- doc.LoadFile(szXMLFileName);//载入xml文件
- xmls::Slo subClass;
- xmls::xString sImageInputSources;
- subClass.Register("ImageInputSources", &sImageInputSources);
- subClass.Register("SemControllerName", &subClass);
- tinyxml2::XMLElement* rootNode;
- rootNode = doc.FirstChildElement(RootClassName);
- subClass.Serialize(false, &doc, rootNode);
- CString cImageInputSources = sImageInputSources.value().c_str();
- if (cImageInputSources == "BSE")
- {
- imageSettings->EnableInputSource(OINA::Extender::Data::Image::ImageInputSources::Bse, true);
- }
- else if (cImageInputSources == "SE")
- {
- imageSettings->EnableInputSource(OINA::Extender::Data::Image::ImageInputSources::SE, true);
- }
- else
- {
- imageSettings->EnableInputSource(OINA::Extender::Data::Image::ImageInputSources::None, true);
- }
- _imageAcqusitionSettings->ImageSettings->DwellTimeMicroSeconds = 20;
- _imageAcqusitionSettings->ScanSettings->AcquisitionRegion->CreateFullFieldRegion(1.0 / 1024.0);
- }
- return _imageAcqusitionSettings;
- }
- IEdChordListAcquisitionController^ OxfordControllerWrapper::CreateChordlistController()
- {
- if (_edsChordListController == nullptr)
- {
- try
- {
- LogTrace(__FILE__, __LINE__, _T("CreateEdChordListServer..."));
- _edsChordListController = AcquireFactory::CreateEdChordListServer();
- _edsChordListController->PixelProcessed += gcnew EventHandler<OINA::Extender::EventArgs<OINA::Extender::Processing::Quant::IPixelSEMQuantStatus^>^>(this, &OxfordControllerWrapper::OnController_PixelProcessed);
- _edsChordListController->ExperimentFinished += gcnew EventHandler<OINA::Extender::Acquisition::AcquisitionFinishedEventArgs^>(this, &OxfordControllerWrapper::OnController_ExperimentFinished);
- auto edsChordListSettings = GetChordlistSettings();
- while (true)
- {
- /*if (_edsChordListController->IsEdHardwareReady(edsChordListSettings))
- {*/
- if (edsChordListSettings->EdCapabilities->HasHardwareConnection)
- {
- break;
- }
- //}
- }
- }catch(Exception^ ex)
- {
- CString sMessage = ex->Message;
- LogErrorTrace(__FILE__, __LINE__, sMessage);
- return nullptr;
- }
-
- }
- return _edsChordListController;
- }
- /// <summary>
- /// Get some chordlists to acquire.
- /// </summary>
- /// <returns>The chordlists to acquire.</returns>
- System::Collections::Generic::IReadOnlyList<ChordList^>^ GetChordLists()
- {
- OINA::Extender::Data::Chord^ chord1 = gcnew OINA::Extender::Data::Chord(3, 0, 5);
- OINA::Extender::Data::Chord^ chord2 = gcnew OINA::Extender::Data::Chord(0, 0, 3);
- OINA::Extender::Data::Chord^ chord3 = gcnew OINA::Extender::Data::Chord(10, 0, 20);
- OINA::Extender::Data::Chord^ chord4 = gcnew OINA::Extender::Data::Chord(550, 44, 30);
- OINA::Extender::Data::Chord^ chord5 = gcnew OINA::Extender::Data::Chord(0, 270, 10);
- OINA::Extender::Data::Chord^ chord6 = gcnew OINA::Extender::Data::Chord(898, 634, 15);
- OINA::Extender::Data::Chord^ chord7 = gcnew OINA::Extender::Data::Chord(266, 768, 40);
- List< OINA::Extender::Data::Chord^>^ chords = gcnew List<OINA::Extender::Data::Chord^>();
- chords->Add(chord1);
- chords->Add(chord2);
- chords->Add(chord3);
- chords->Add(chord4);
- chords->Add(chord5);
- chords->Add(chord6);
- chords->Add(chord7);
-
- OINA::Extender::Data::ChordList^ chordsList = gcnew OINA::Extender::Data::ChordList(chords, 1/1024.0);
-
- List<ChordList^>^ ListchordsList = gcnew List<ChordList^>();
- ListchordsList->Add(chordsList);
-
- return ListchordsList;
- }
- IEdChordListSettings^ OxfordControllerWrapper::GetChordlistSettings()
- {
- if (_edsChordListSetting == nullptr)
- {
- _edsChordListSetting = AcquireFactory::CreateEdChordListSettings();
- if (_edsChordListSetting == nullptr)
- {
- CString sMessage(_T("Create EDS chordlist setting failed."));
- LogErrorTrace(__FILE__, __LINE__, sMessage);
-
- ASSERT(FALSE);
- }
- else
- {
- _edsChordListSetting->EdSettings->AcquisitionMode = EdAcquireMode::LiveTime;
- //_edsChordListSetting->EdSettings->AcquisitionTime = TimeSpan::FromMilliseconds(100);// :FromSeconds(1);
- _edsChordListSetting->EdSettings->NumberOfChannels =4096;
- _edsChordListSetting->EdSettings->ProcessTime = g_nOxfordControllerProcessTime;
- _edsChordListSetting->EdSettings->EnergyRange = g_nOxfordControllerEnergyRange;
-
- /*_edsChordListSetting->AutoIdSettings->SetKnownElement(79, true);
- _edsChordListSetting->NumberOfProcessingThreads = 1;*/
- //_edsChordListSetting->ChordLists = GetChordLists();
- }
- }
- return _edsChordListSetting;
- }
- void OxfordControllerWrapper::LogMessage(CString a_sMessage)
- {
- LogTrace(__FILE__, __LINE__, a_sMessage);
-
- }
|