1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945 |
-
- using OINA.Extender;
- using OINA.Extender.Acquisition;
- using OINA.Extender.Acquisition.Ed;
- using OINA.Extender.Acquisition.Image;
- using OINA.Extender.Data;
- using OINA.Extender.Data.Ed;
- using OINA.Extender.Data.Image;
- using OINA.Extender.MicroscopeControl;
- using OINA.Extender.Processing;
- using OINA.Extender.Processing.Ed;
- using OINA.Extender.Processing.Quant;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows;
- using System.Windows.Forms;
- using static OxfordExtenderWrapper.ExtenderIpcUI;
- namespace OxfordExtenderWrapper
- {
- enum OxfordControllerState
- {
- READY = 0,
- WORKING = 1,
- SUCCEEDED = 2,
- FAILED = 3,
- ABORT = 4
- };
- [Serializable]
- public class Segment
- {
- private int m_nX;
- private int m_nY;
- private int m_nLength;
- public int X
- {
- get { return m_nX; }
- set
- {
- if (value > 0)
- {
- m_nX = value;
- }
- }
- }
- public int Y
- {
- get { return m_nY; }
- set
- {
- if (value > 0)
- {
- m_nY = value;
- }
- }
- }
- public int Length
- {
- get { return m_nLength; }
- set
- {
- if (value > 0)
- {
- m_nLength = value;
- }
- }
- }
- };
- /// <summary>
- /// Enum EDSConst definition.
- /// </summary>
- enum EDSConst
- {
- MAX_XRAY_BATCH = 1024,
- XANA_CHANNELS = 2000,
- XANA_CHANNELS_MAX = 4192,
- MAX_AMPTIME_CONSTANTS = 10,
- MAX_EV_PER_CHANNELS = 5,
- MAX_ANALYZERS = 5,
- MAX_LEN_ANALYZER_NAME = 16
- };
- [Serializable]
- struct OxfordChord
- {
- public long m_nX;
- public long m_nY;
- public long m_nLength;
- };
- enum OxfordCommandType
- {
-
- GetMagnification = 0,
- SetMagnification = 1,
-
- GetWorkingDistance = 2,
- SetWorkingDistance = 3,
-
- GetBrightness = 4,
- SetBrightness = 5,
-
- GetContrast = 6,
- SetContrast = 7,
-
- GetSEMVoltage = 8,
- SetSEMVoltage = 9,
- //样品台
- GetStagePosition = 10,
- SetStagePosition = 11,
- GetStageAtX = 12,
- GetStageAtY = 13,
- GetStageAtZ = 14,
- GetStageAtT = 15,
- GetStageAtR = 16,
- SetStageGotoX = 17,
- SetStageGotoY = 18,
- SetStageGotoZ = 19,
- SetStageGotoT = 20,
- SetStageGotoR = 21,
- MoveStageXY = 22,
- //拍图
- ImageAquisition = 23,
- //采集参数设置
- SetImageAcquistionSetting = 24,
- //获取分辨率
- GetImageResolution = 25,
- //设置分辨率
- SetImageResolution= 26,
- //获取bitmap
- GetBitmap = 27,
- //X-ray
- //点采集
- XrayPointCollection = 29,
- COLLECT_XRAYPOINTS=30,
- //面采集
- XrayAreaCollection = 31,
- COLLECT_XRAYFEATURES = 32,
- Exit = 100,
- }
- [Serializable]
- public class ImageAquistionParam
- {
- public enum ImageRegionType
- {
- FullField=0,
- Rectangle=1
- }
- public ImageAquistionParam()
- {
- this.ImageData = new byte[width * height];
- regionType = ImageRegionType.FullField;
- }
- //in
- public ImageRegionType regionType;
- public int width;
- public int height;
- public Rect ImgRectRegion;
- public double DwellTime;
- public ImageInputSourceType sourceType;
- //out
- public byte[] ImageData;
- }
- [Serializable]
- public class PointXrayParam
- {
- public PointXrayParam()
- {
- this.XrayData = new uint[2000];
- this.listElement = new Dictionary<string, double>();
- }
- public double dMilliSecondsTime;
- public double x;
- public double y;
- //out
- public uint[] XrayData;
- public Dictionary<string, double> listElement;
- public bool b_quant;
- }
- [Serializable]
- public class AreaXrayParam
- {
- public AreaXrayParam()
- {
- this.XrayData = new uint[2000];
- this.listElement = new Dictionary<string, double>();
- }
- public double dMilliSecondsTime;
- public List<Segment> a_listChord=new List<Segment>();
- public uint[] XrayData;
- public Dictionary<string, double> listElement;
- public bool b_quant;
- }
- [Serializable]
- public struct MoveStageParam
- {
- public float x;
- public float y;
- }
- struct oxfordCommandData
- {
- public OxfordCommandType commandType;
- public bool returnType;
- public MoveStageParam moveStagePrm;
- public ImageAquistionParam grabImgParam;
- public PointXrayParam pointXrayPrm;
- public AreaXrayParam areaXrayPrm;
- public List<PointXrayParam> XrayPrmForPoints;
- public int PointXrayDataReceived;
- public List<AreaXrayParam> XrayPrmForFeatures;
- public int AreaXrayDataReceived;
- }
- public class ExtenderWrapper:MarshalByRefObject
- {
- NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- private oxfordCommandData currentCommand;
-
- //控制电镜
- private IMicroscopeController microscopeController = null;
- /// <summary>
- /// IImageAcquisitionController object
- /// </summary>
- private IImageAcquisitionController imageAcquisitionController = null;
- /// <summary>
- /// IImageSettings object
- /// </summary>
- private IImageAcquisitionSettings imageAcquisitionSettings = null;
- //控制器
- private IEdSpectrumAcquisitionController EdSpectrumAcquisitionController = null;
- private IEdSpectrumSettings EdSpectrumSettings = null;
- private IEdSpectrumProcessing EdSpectrumProcessing = null;
- // Use the autoIdSettings to define elements that are known or elements that you want to exclude. They also list elements that cannot be identified
- private IAutoIdSettings autoIdSettings = null;
- private ISEMQuantSettings quantSettings = null;
- //private IEdChordListAcquisitionController _edsChordListController = null;
-
- private IEdChordListSettings _edsChordListSetting;
- private int XRayChannelLength = 2000;
- private int EDSColletionTimeOut = 10000;
-
-
- const int g_nOxfordControllerProcessTime = 4;
- const int g_nOxfordControllerEnergyRange = 20;
- private bool m_bXrayDone = false;
- //电压
- private double m_dHighVoltage;
- //放大倍数
- private double m_dMagnification;
- //工作距离
- private double m_dWorkingDistance;
- //亮度
- private double m_dBirghtness;
- //对比度
- private double m_dContrast;
- //BeamOn
- private bool m_bBeamOn;
- //FilamentOn
- private bool m_bFilamentOn;
- //样品台位置
- private double m_dStageX;
- private double m_dStageY;
- private double m_dStageZ;
- private double m_dStageR;
- private double m_dStageT;
-
-
- private byte[] m_ImageBit = null;
- private long m_nImageWidth = 0;
- private long m_nImageHeight = 0;
- private double m_dImagePixelsize = 0;//it will be initialized when we get an image from the EDS.
- bool m_bAcquistionDone = false;
- private bool m_StageUpdated;
- private bool m_CollumnUpdated;
- private bool m_ExternalScanUpdated;
- const String theElementNameList = ("H,He") +
- (",Li,Be,B,C,N,O,F,Ne") +
- (",Na,Mg,Al,Si,P,S,Cl,Ar") +
- (",K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr") +
- (",Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe") +
- (",Cs,Ba,La") +
- (",Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu") +
- (",Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn") +
- (",Fr,Ra,Ac") +
- (",Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr");
- private bool m_ifautoid = true;
- private string m_knownelements;
- //构造函数
- public ExtenderWrapper()
- {
- //ConnectToEDSHardware();
- }
- public bool ConnectToEDSHardware()
- {
- try
- {
- InitMicroscopeController();
- InitImageAcquisition();
- InitXrayAcquistion();
-
- return true;
- }
- catch (Exception e)
- {
- log.Error(e.Message);
- return false;
- }
-
- }
-
- //结束
- public void CloseExtender()
- {
-
- CloseMicroscopeController();
- CloseImageAcquisition();
- CloseXrayAcquistion();
-
-
- }
-
- public bool AquisitionImage(ref ImageAquistionParam p)
- {
- currentCommand.grabImgParam = p;
- currentCommand.commandType = OxfordCommandType.ImageAquisition;
- SetImageAcquistionSetting(p);
- try
- {
- int lastingTime = 0;
- m_bAcquistionDone = false;
- imageAcquisitionController.BeginMultipleAcquisition();
- IEnumerable<IElectronImage> images = imageAcquisitionController.StartAcquisition(imageAcquisitionSettings);
- int time1 = Environment.TickCount;
- while (true)
- {
- if (m_bAcquistionDone)
- {
- p.ImageData = m_ImageBit;
- currentCommand.returnType = true;
- break;
- }
-
- Application.DoEvents();
- int time2;
-
- time2 = Environment.TickCount;
- if (time2 - time1 > EDSColletionTimeOut*6)
- {
- currentCommand.returnType = false;
- break;
- }
-
- }
- }
- catch (InvalidSettingsException settingsException)
- {
- var sb = new StringBuilder(@"Invalid settings have been supplied: ");
- sb.AppendLine();
- settingsException.ValidationResults.ValidationErrors.ToList().ForEach(ve => sb.AppendFormat("{0}{1}", Environment.NewLine, ve));
- NLog.LogManager.GetCurrentClassLogger().Error(sb.ToString());
- }
- catch (AcquisitionStartException startException)
- {
- string msg = string.Format(@"AcquisitionStartException: {0}", startException.Message);
- NLog.LogManager.GetCurrentClassLogger().Error(msg);
- }
-
- if (currentCommand.returnType == true)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool MoveStageXY(float x, float y)
- {
-
- currentCommand.moveStagePrm = new MoveStageParam();
- currentCommand.moveStagePrm.x = x;
- currentCommand.moveStagePrm.y = y;
- currentCommand.commandType = OxfordCommandType.MoveStageXY;
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageX, (double)x/1000.0 },
- { Stage.StageY, (double)y /1000.0}
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- currentCommand.returnType = true;
-
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
-
-
- time2 = Environment.TickCount;
- if (time2-time1 > 60000)
- {
- currentCommand.returnType = false;
- break;
- }
- }
- if (currentCommand.returnType == true)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool XrayAreaCollecting(ref AreaXrayParam p)
- {
-
- currentCommand.areaXrayPrm = p;
- currentCommand.commandType = OxfordCommandType.XrayAreaCollection;
- m_bXrayDone = false;
- SetXrayAcquisitionParam(p.dMilliSecondsTime);
- List<Chord> Chords = new List<Chord>();
- foreach (Segment seg in p.a_listChord)
- {
- Chord chord = new Chord(seg.X, seg.Y, seg.Length);
- Chords.Add(chord);
- }
- var chordsList = new ChordList(Chords, m_dImagePixelsize);
- EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreateChordListRegion(chordsList);
- EdSpectrumAcquisitionController.BeginMultipleAcquisition();
- try
- {
-
- IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
- var time1 = Environment.TickCount;
- while (true)
- {
- if (m_bXrayDone)
- {
- currentCommand.returnType = true;
- break;
- }
-
- Application.DoEvents();
- var time2 = Environment.TickCount;
- if (time2-time1 > EDSColletionTimeOut * 6)
- {
- currentCommand.returnType = false;
- break;
- }
- }
- }
- catch (InvalidSettingsException invalidSettingsException)
- {
- string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",
- invalidSettingsException.Message,
- invalidSettingsException.ValidationResults.ValidationErrors);
- log.Error(msg);
- }
- catch (AcquisitionStartException acquisitionStartException)
- {
- string msg = string.Format(@"Acquisition Start Exception:{0}", acquisitionStartException.Message);
- log.Error(msg);
- }
-
- if (currentCommand.returnType == true)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool XrayPointCollecting(ref PointXrayParam p)
- {
-
- currentCommand.pointXrayPrm = p;
- currentCommand.commandType = OxfordCommandType.XrayPointCollection;
- m_bXrayDone = false;
- p.XrayData = new uint[XRayChannelLength];
- p.listElement = new Dictionary<string, double>();
- SetXrayAcquisitionParam(p.dMilliSecondsTime);
-
- EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreatePointRegion(new System.Windows.Point(p.x * m_dImagePixelsize, p.y * m_dImagePixelsize));
- EdSpectrumAcquisitionController.BeginMultipleAcquisition();
- try
- {
- m_bXrayDone = false;
-
- IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
- var time1 = Environment.TickCount;
- while (true)
- {
- if (m_bXrayDone)
- {
- currentCommand.returnType = true;
- break;
- }
- Application.DoEvents();
- var time2 = Environment.TickCount;
- if (time2-time1 > EDSColletionTimeOut * 6)
- {
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
- log.Warn("XrayStartAcquisition 超时!");
- currentCommand.returnType = false;
- }
- }
- }
- catch (InvalidSettingsException invalidSettingsException)
- {
- string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",
- invalidSettingsException.Message,
- invalidSettingsException.ValidationResults.ValidationErrors);
- log.Error(msg);
- }
- catch (AcquisitionStartException acquisitionStartException)
- {
- string msg = string.Format(@"Acquisition Start Exception:{0}", acquisitionStartException.Message);
- log.Error(msg);
- }
-
- if (currentCommand.returnType == true)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool CollectXrayByPoints(ref List<PointXrayParam> a_listPoints, uint a_nXRayAQTime, bool a_bElementInfo)
- {
- currentCommand.XrayPrmForPoints = a_listPoints;
- currentCommand.commandType = OxfordCommandType.COLLECT_XRAYPOINTS;
-
- //log.Info("线程:开始采集多点xray");
- var PointXrayDatas = currentCommand.XrayPrmForPoints;
- currentCommand.PointXrayDataReceived = 0;
- m_bXrayDone = false;
-
- var dMilliSecondsTime = PointXrayDatas[0].dMilliSecondsTime;
- SetXrayAcquisitionParam(dMilliSecondsTime);
- EdSpectrumAcquisitionController.BeginMultipleAcquisition();
- foreach (var prm in PointXrayDatas)
- {
- prm.b_quant = a_bElementInfo;
- EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreatePointRegion(new System.Windows.Point(prm.x * m_dImagePixelsize, prm.y * m_dImagePixelsize));
- try
- {
- m_bXrayDone = false;
- IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
- }
- catch (InvalidSettingsException invalidSettingsException)
- {
- string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",
- invalidSettingsException.Message,
- invalidSettingsException.ValidationResults.ValidationErrors);
- log.Error(msg);
- }
- catch (AcquisitionStartException acquisitionStartException)
- {
- string msg = string.Format(@"Acquisition Start Exception:{0}", acquisitionStartException.Message);
- log.Error(msg);
- }
- }
- var time1 = Environment.TickCount;
- while (true)
- {
- if (m_bXrayDone)
- {
- currentCommand.returnType = true;
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
- break;
- }
- Application.DoEvents();
- var time2 = Environment.TickCount;
-
- if (time2-time1 > EDSColletionTimeOut * PointXrayDatas.Count)
- {
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
-
- currentCommand.returnType = false;
- }
- }
- if (currentCommand.returnType == true)
- {
-
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool CollectXrayByFeatures(ref List<AreaXrayParam> a_listFeatures, double a_nXRayAQTime, bool a_bElementInfo)
- {
- currentCommand.XrayPrmForFeatures = a_listFeatures;
- currentCommand.commandType = OxfordCommandType.COLLECT_XRAYFEATURES;
- var p = currentCommand.XrayPrmForFeatures;
- currentCommand.AreaXrayDataReceived = 0;
-
-
- m_bXrayDone = false;
-
- var dMilliSecondsTime = p[0].dMilliSecondsTime;
- SetXrayAcquisitionParam(p[0].dMilliSecondsTime);
- EdSpectrumAcquisitionController.BeginMultipleAcquisition();
- foreach (var prm in p)
- {
- prm.b_quant = a_bElementInfo;
- List<Chord> Chords = new List<Chord>();
- Chord chord;
- foreach (Segment seg in prm.a_listChord)
- {
- if (seg.Length >= 3)
- {
- chord = new Chord(seg.X+1, seg.Y, seg.Length-2);//get the middle part
- }
- else
- {
- chord = new Chord(seg.X, seg.Y, seg.Length);
- }
-
- Chords.Add(chord);
- }
- var chordsList = new ChordList(Chords, m_dImagePixelsize);
- EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreateChordListRegion(chordsList);
- try
- {
- m_bXrayDone = false;
- IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
- }
- catch (InvalidSettingsException invalidSettingsException)
- {
- string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",
- invalidSettingsException.Message,
- invalidSettingsException.ValidationResults.ValidationErrors);
- log.Error(msg);
- }
- catch (AcquisitionStartException acquisitionStartException)
- {
- string msg = string.Format(@"Acquisition Start Exception:{0}", acquisitionStartException.Message);
- log.Error(msg);
- }
- }
- var time1 = Environment.TickCount;
- while (true)
- {
- if (m_bXrayDone)
- {
- currentCommand.returnType = true;
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
- break;
- }
- Application.DoEvents();
-
- var time2 = Environment.TickCount;
- if (time2-time1 > EDSColletionTimeOut * p.Count)
- {
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
-
-
- currentCommand.returnType = false;
- break;
- }
- }
- if (currentCommand.returnType == true)
- {
- a_listFeatures = currentCommand.XrayPrmForFeatures;
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
- //控制电镜初始化
- void InitMicroscopeController()
- {
- this.microscopeController = AcquireFactory.CreateMicroscopeControl();
- this.microscopeController.ColumnChange += this.OnMicroscopeColumnChange;
- this.microscopeController.StageChange += this.OnMicroscopeStageChange;
- this.microscopeController.ColumnConnected += this.OnMicroscopeColumnConnected;
- this.microscopeController.StageConnected += this.OnMicroscopeStageConnected;
- this.microscopeController.ChangeCompleted += this.OnMicroscopeChangeCompleted;
-
- //ReadMicroscopeColumn();
- //ReadStage();
- }
- //控制电镜释放
- void CloseMicroscopeController()
- {
- if (microscopeController != null)
- {
-
- this.microscopeController.ColumnChange -= this.OnMicroscopeColumnChange;
- this.microscopeController.StageChange -= this.OnMicroscopeStageChange;
- this.microscopeController.ColumnConnected -= this.OnMicroscopeColumnConnected;
- this.microscopeController.StageConnected -= this.OnMicroscopeStageConnected;
- this.microscopeController.ChangeCompleted -= this.OnMicroscopeChangeCompleted;
- microscopeController = null;
- }
-
- }
- //读取当前的电镜控制值
- private void ReadMicroscopeColumn()
- {
- var columnCapabilities = this.microscopeController.ColumnCapabilities;
- var columnConditions = this.microscopeController.ColumnConditions;
- if (columnCapabilities.Magnification.CanRead)
- {
- m_dMagnification = columnConditions.Magnification;
- }
- if (columnCapabilities.WorkingDistance.CanRead)
- {
- m_dWorkingDistance = columnConditions.WorkingDistance;
- }
- if (columnCapabilities.HighVoltage.CanRead)
- {
- m_dHighVoltage = columnConditions.HighVoltage;
- }
- if (columnCapabilities.Brightness.CanRead)
- {
- m_dBirghtness = columnConditions.Brightness;
- }
- if (columnCapabilities.Contrast.CanRead)
- {
- m_dContrast = columnConditions.Contrast;
- }
- if (columnCapabilities.BeamOn.CanRead)
- {
- m_bBeamOn = Convert.ToBoolean(columnConditions.BeamOn);
- }
- if (columnCapabilities.FilamentOn.CanRead)
- {
- m_bFilamentOn = Convert.ToBoolean(columnConditions.FilamentOn);
- }
- }
- //读取样品台位置
- private void ReadStage()
- {
- var stageCapabilities = this.microscopeController.StageCapabilities;
- var stageConditions = this.microscopeController.StageConditions;
- while (!stageCapabilities.StageX.CanRead)
- {
- Thread.Sleep(100);
- }
- if (stageCapabilities.StageX.CanRead)
- {
- this.m_dStageX = stageConditions.StageX*1000.0;
- }
- if (stageCapabilities.StageY.CanRead)
- {
- this.m_dStageY = stageConditions.StageY*1000.0;
- }
- if (stageCapabilities.StageZ.CanRead)
- {
- this.m_dStageZ = stageConditions.StageZ;
- }
- if (stageCapabilities.StageT.CanRead)
- {
- this.m_dStageT = stageConditions.StageT;
- }
- if (stageCapabilities.StageR.CanRead)
- {
- this.m_dStageR = stageConditions.StageR;
- }
- }
- //电镜控制改变事件
- private void OnMicroscopeColumnChange(object sender, EventArgs e)
- {
-
- ReadMicroscopeColumn();
- }
- //样品台控制改变事件
- private void OnMicroscopeStageChange(object sender, EventArgs e)
- {
-
- ReadStage();
- }
- //镜筒控制连接或断开时的事件
- private void OnMicroscopeColumnConnected(object sender, EventArgs e)
- {
- ReadMicroscopeColumn();
- }
- //样品台控制连接或断开时的事件
- private void OnMicroscopeStageConnected(object sender, EventArgs e)
- {
-
- ReadStage();
- }
- //样品台控制、电镜控制、外围控制的事件改变完成
- private void OnMicroscopeChangeCompleted(object sender, CompletedEventArgs e)
- {
- if (e.Control == MicroscopeControlType.Stage)
- {
- if (e.Success)
- {
-
- m_StageUpdated = true;
-
- }
- }
- else if (e.Control == MicroscopeControlType.Column)
- {
- if (e.Success)
- {
- m_CollumnUpdated = true;
- }
- }
- else if (e.Control == MicroscopeControlType.ExternalScan)
- {
- if (e.Success)
- {
- m_ExternalScanUpdated = true;
- }
-
- }
- ReadMicroscopeColumn();
- ReadStage();
- }
- public float GetMagnification()
- {
- ReadMicroscopeColumn();
- return (float)m_dMagnification;
- }
- public Boolean SetMagnification(float set)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.Magnification, (double)set }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 10000)
- {
- currentCommand.returnType = false;
- return false;
-
- }
- }
- return true;
- }
- //焦距
- public float GetWorkingDistance()
- {
- ReadMicroscopeColumn();
- return (float)m_dWorkingDistance;
- }
- public Boolean SetWorkingDistance(float set)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.WorkingDistance, (double)set }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 10000)
- {
- currentCommand.returnType = false;
- return false;
- }
- }
- return true;
- }
- //亮度
- public float GetBrightness()
- {
- ReadMicroscopeColumn();
- return (float)m_dBirghtness;
- }
- public Boolean SetBrightness(float set)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.Brightness, (double)set }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 2000)
- {
- currentCommand.returnType = false;
- return false;
-
- }
- }
- return true;
- }
- //对比度
- public float GetContrast()
- {
- ReadMicroscopeColumn();
- return (float)m_dContrast;
- }
- public Boolean SetContrast(float set)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.Contrast, (double)set }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 2000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- //SEM电压
- public float GetSEMVoltage()
- {
- ReadMicroscopeColumn();
- return (float)m_dHighVoltage;
- }
- public Boolean SetSEMVoltage(float set)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.HighVoltage, (double)set }
- };
-
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 10000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- public bool SetSemScanExternal(bool b)
- {
- m_ExternalScanUpdated = false;
- if (!b)
- {
- EndMultipleAquisition();
- }
- this.microscopeController.SetExternalScan(b);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_ExternalScanUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 2000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
-
-
- return true;
- }
-
- //样品台
- public float[] GetStagePosition()
- {
- ReadStage();
- float[] ret = new float[5];
- ret[0] = (float)m_dStageX;
- ret[1] = (float)m_dStageY;
- ret[2] = (float)m_dStageZ;
- ret[3] = (float)m_dStageT;
- ret[4] = (float)m_dStageR;
- return ret;
- }
- public Boolean SetStagePosition(float[] set)
- {
- double stageX = (double)set[0];
-
- double stageY = (double)set[1];
-
- double stageZ = (double)set[2];
-
- double stageT = (double)set[3];
-
- double stageR = (double)set[4];
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageX, (double)stageX/1000.0 },
- { Stage.StageY, (double)stageY/1000.0 },
- { Stage.StageZ, (double)stageZ },
- { Stage.StageT, (double)stageT },
- { Stage.StageR, (double)stageR }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- public float GetStageAtX()
- {
- ReadStage();
- return (float)m_dStageX;
- }
- public float GetStageAtY()
- {
- ReadStage();
- return (float)m_dStageY;
- }
- public float GetStageAtZ()
- {
- ReadStage();
- return (float)m_dStageZ;
- }
- public float GetStageAtT()
- {
- ReadStage();
- return (float)m_dStageT;
- }
- public float GetStageAtR()
- {
- ReadStage();
- return (float)m_dStageR;
- }
- public Boolean SetStageGotoX(float set)
- {
- double stageX = (double)set;
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageX, (double)stageX/1000.0 }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- public Boolean SetStageGotoY(float set)
- {
- double stageY = (double)set;
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageY, (double)stageY/1000.0 }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- public Boolean SetStageGotoZ(float set)
- {
- double stageZ = (double)set;
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageZ, (double)stageZ }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
- public Boolean SetStageGotoT(float set)
- {
- double stageT = (double)set;
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageT, (double)stageT }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
-
- }
- }
- return true;
- }
- public Boolean SetStageGotoR(float set)
- {
- double stageR = (double)set;
-
- var stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageR, (double)stageR }
- };
- m_StageUpdated = false;
- this.microscopeController.SetStageConditions(stageDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_StageUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 20000)
- {
- currentCommand.returnType = false;
- return false;
- //break;
- }
- }
- return true;
- }
-
- #region 拍图
-
- //图像扫描尺寸
- public double[] ImageScanSize =
- {
- 32,
- 64,
- 128,
- 256,
- 512,
- 704,
- 768,
- 1408,
- 1024,
- 1536,
- 2048,
- 3072,
- 4096,
- 8192
- };
-
- public double GetDImagePixelsize()
- {
- return m_dImagePixelsize;
- }
- public void SetDImagePixelsize(double value)
- {
- m_dImagePixelsize = value;
- }
- void InitImageAcquisition()
- {
- imageAcquisitionController = AcquireFactory.CreateImageServer();
- imageAcquisitionSettings = AcquireFactory.CreateImageSettings();
-
-
- imageAcquisitionController.ExperimentStarted += this.OnImageExperimentStarted;
- imageAcquisitionController.ExperimentFinished += this.OnImageExperimentFinished;
-
- }
- void InitXrayAcquistion()
- {
- EdSpectrumSettings = AcquireFactory.CreateEdSpectrumSettings();
- EdSpectrumAcquisitionController = AcquireFactory.CreateEdSpectrumServer();
- 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
- autoIdSettings = ProcessingFactory.CreateAutoIdSettings();
-
- quantSettings = ProcessingFactory.CreateSEMQuantSettings();
- EdSpectrumAcquisitionController.ExperimentFinished += this.OnEdSpectrumExperimentFinished;
- //EdSpectrumAcquisitionController.ExperimentStarted += this.OnEdSpectrumExperimentStarted;
-
- }
- //控制电镜释放
- void CloseImageAcquisition()
- {
- if (imageAcquisitionController != null)
- {
- imageAcquisitionController.ExperimentStarted -= this.OnImageExperimentStarted;
- imageAcquisitionController.ExperimentFinished -= this.OnImageExperimentFinished;
- imageAcquisitionController = null;
- }
-
- }
- void CloseXrayAcquistion()
- {
- if (EdSpectrumAcquisitionController != null)
- {
- EdSpectrumAcquisitionController.ExperimentFinished -= this.OnEdSpectrumExperimentFinished;
- //EdSpectrumAcquisitionController.ExperimentStarted -= this.OnEdSpectrumExperimentStarted;
- EdSpectrumAcquisitionController = null;
- }
- }
- /// <summary>
- /// OnImageExperimentStarted
- /// </summary>
- private void OnImageExperimentStarted(object sender, AcquisitionStartedEventArgs<IElectronImage[]> e)
- {
- NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- log.Info("拍图开始事件!");
- }
- //int m_nState;
- /// <summary>
- /// OnImageExperimentFinished
- /// </summary>
- private void OnImageExperimentFinished(object sender, AcquisitionFinishedEventArgs<IElectronImage[]> e)
- {
- IElectronImage electronImage = e.Value[0];
- if (!ReadImageData(electronImage, out m_ImageBit, out m_nImageWidth, out m_nImageHeight, out m_dImagePixelsize))
- {
-
- NLog.LogManager.GetCurrentClassLogger().Error("图像采集完成,获取图像像素失败!");
- }
- if (m_ImageBit != null && m_ImageBit.Length == m_nImageWidth * m_nImageHeight)
- {
- m_bAcquistionDone = true;
- }
- }
- bool ReadImageData(IElectronImage a_electronImage, out Byte[] a_pImageBits, out long a_nImageHeight, out long a_nImageWidth, out double a_nPixelSize)
- {
- a_nImageHeight = 0;
- a_nImageWidth = 0;
- a_nPixelSize = 0;
- a_pImageBits = null;
- if (a_electronImage == null)
- {
- return false;
- }
- a_nImageHeight = a_electronImage.Height;
- a_nImageWidth = a_electronImage.Width;
- a_nPixelSize = a_electronImage.PixelSize;
- int nBytesPerPixel = a_electronImage.BytesPerPixel;
- long nImageSize = a_nImageHeight * a_nImageWidth;
- long nBufferSize = nImageSize * nBytesPerPixel;
- Byte[] imageData = new Byte[nBufferSize];
- a_electronImage.GetData(imageData);
- a_pImageBits = new Byte[nImageSize];
- // 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
- {
- string msg = string.Format("image byte per pixel other than 2({0}), image convert may wrong", nBytesPerPixel);
- NLog.LogManager.GetCurrentClassLogger().Error(msg);
- int nOffset = nBytesPerPixel - 1;
- for (int i = 0; i < nImageSize; ++i)
- {
- a_pImageBits[i] = imageData[nOffset + i * nBytesPerPixel];
- }
- }
- return true;
- }
- //a_dDwellTime : 1~100000之间的数
- //a_sImageType : 1: SE, 2: Bse
-
- public bool SetImageAcquistionSetting(ImageAquistionParam p)
- {
- IImageSettings imageSettings = imageAcquisitionSettings.ImageSettings;
- IImageCapabilities imageCapabilities = imageAcquisitionSettings.ImageCapabilities;
- IImageScanSettings scanSettings = imageAcquisitionSettings.ScanSettings;
- if (p.DwellTime > imageCapabilities.MaximumImageDwellMicroseconds)
- {
- imageSettings.DwellTimeMicroSeconds = imageCapabilities.MaximumImageDwellMicroseconds;
- }
- if (p.DwellTime < imageCapabilities.MinimumImageDwellMicroseconds)
- {
- imageSettings.DwellTimeMicroSeconds = imageCapabilities.MinimumImageDwellMicroseconds;
- }
- else
- {
- imageSettings.DwellTimeMicroSeconds = p.DwellTime;
- }
- imageSettings.InputSources.ToList().ForEach(i => imageSettings.EnableInputSource(i.Key, false));
- imageSettings.EnableInputSource((ImageInputSources)p.sourceType, true);
- if (!ImageScanSize.Contains(p.width))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("图像尺寸输入无效");
- return false;
- }
- var pixelSize = 1d / p.width;
- if (p.regionType == ImageAquistionParam.ImageRegionType.FullField)
- {
- scanSettings.AcquisitionRegion.CreateFullFieldRegion(pixelSize);
- }
- else
- {
- scanSettings.AcquisitionRegion.CreateRectangleRegion(p.ImgRectRegion,pixelSize);
- }
-
-
- return true;
- }
-
- #endregion
- #region X-ray
- void SetXrayAcquisitionParam(double a_dMilliSecondsTime)
- {
- EdSpectrumSettings.EdSettings.AcquisitionMode = EdAcquireMode.LiveTime; // RealTime or LiveTime
- EdSpectrumSettings.EdSettings.AcquisitionTime = TimeSpan.FromMilliseconds(a_dMilliSecondsTime);
- EdSpectrumSettings.EdSettings.ProcessTime = 4;
- EdSpectrumSettings.EdSettings.EnergyRange = 20;
- EdSpectrumSettings.EdSettings.NumberOfChannels = 4096;
-
- }
- private bool GetAtomicNumberByEleName(string name,out int atomicNum)
- {
- var allelenames = theElementNameList.Split(',');
- for (int i = 0; i < allelenames.Length; i++)
- {
- if (allelenames[i] == name)
- {
- atomicNum= i+1;
- return true;
- }
-
- }
- atomicNum=0;
- return false;
- }
-
- /// <summary>
- /// Called when IEdSpectrumAcquisitionController Experiment Finished
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">The instance containing the event data.</param>
- private void OnEdSpectrumExperimentFinished(object sender, AcquisitionFinishedEventArgs<IEdSpectrum> e)
- {
- IEdSpectrumAcquisitionController edSpectrumAcquisitionController = sender as IEdSpectrumAcquisitionController;
- uint[] m_XrayData;
- NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- IEdSpectrum edSpectrum = e.Value;
- if (!ReadXrayData(edSpectrum, out m_XrayData, XRayChannelLength))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("Xray采集完成,获取xray失败!");
- }
- long nXraycount = 0;
- for (int i = 0; i < 2000; i++)
- {
- nXraycount += m_XrayData[i];
- }
- //Quantify processing
- bool bquant=false;
- if (currentCommand.commandType == OxfordCommandType.XrayPointCollection)
- {
- bquant = currentCommand.pointXrayPrm.b_quant;
- }
- else if (currentCommand.commandType == OxfordCommandType.XrayAreaCollection)
- {
- bquant = currentCommand.areaXrayPrm.b_quant;
- }
- else if (currentCommand.commandType == OxfordCommandType.COLLECT_XRAYPOINTS)
- {
- var curXrayData = currentCommand.XrayPrmForPoints[currentCommand.PointXrayDataReceived];
- bquant = curXrayData.b_quant;
- }
- else if (currentCommand.commandType == OxfordCommandType.COLLECT_XRAYFEATURES)
- {
- var curXrayData = currentCommand.XrayPrmForFeatures[currentCommand.AreaXrayDataReceived];
- bquant = curXrayData.b_quant;
- }
- var m_listElement = new Dictionary<string, double>();
- if (bquant)
- {
- if (m_ifautoid == false)
- {
- log.Warn(autoIdSettings.KnownElements);
- autoIdSettings.ClearKnownElements();
- //m_knownelements = "K,Ca,Sc,Ti,V,Mn,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr";
- var knownelenames = m_knownelements.Split(',');
- foreach (var ele in knownelenames)
- {
- int atomicnum;
- if (GetAtomicNumberByEleName(ele, out atomicnum))
- {
-
- autoIdSettings.SetKnownElement(atomicnum, true);
- }
- }
- log.Warn(autoIdSettings.KnownElements);
-
- }
- else
- {
-
- }
-
- EdSpectrumProcessing.IdentifyElements(e.Value, autoIdSettings);
- // While it is possible to choose other elements, Oxygen is the only supported element by stoichiometry.
- quantSettings.CombinedElement = 8;
- quantSettings.Normalised = true;
- ISEMQuantStatus quantStatus = EdSpectrumProcessing.SEMQuantifySpectrum(e.Value, quantSettings);//(a_nChannelData, OIHelper::SEMQuantSettings);
- IEnumerable<ISEMQuantResult> Results = quantStatus.Results;
- var ie = Results.GetEnumerator();
-
- while (ie.MoveNext())
- {
- ISEMQuantResult result = ie.Current;
- if (result.WeightPercent != 0)
- {
- m_listElement.Add(ElementProperties.GetElementSymbol(result.AtomicNumber), result.WeightPercent);
- }
- }
- }
- //------------------------
- if (m_XrayData != null && m_XrayData.Length == XRayChannelLength)
- {
- if (currentCommand.commandType == OxfordCommandType.XrayPointCollection)
- {
- currentCommand.pointXrayPrm.XrayData = m_XrayData;
- currentCommand.pointXrayPrm.listElement = m_listElement;
- m_bXrayDone = true;
- }
- else if (currentCommand.commandType == OxfordCommandType.XrayAreaCollection)
- {
- currentCommand.areaXrayPrm.XrayData = m_XrayData;
- currentCommand.areaXrayPrm.listElement = m_listElement;
- m_bXrayDone = true;
- }
- else if (currentCommand.commandType == OxfordCommandType.COLLECT_XRAYPOINTS)
- {
- var curXrayData = currentCommand.XrayPrmForPoints[currentCommand.PointXrayDataReceived];
- curXrayData.XrayData = m_XrayData;
- curXrayData.listElement = m_listElement;
- currentCommand.PointXrayDataReceived += 1;
- if (currentCommand.PointXrayDataReceived == currentCommand.XrayPrmForPoints.Count)
- {
- m_bXrayDone = true;
- }
- }
- else if (currentCommand.commandType == OxfordCommandType.COLLECT_XRAYFEATURES)
- {
- var curXrayData = currentCommand.XrayPrmForFeatures[currentCommand.AreaXrayDataReceived];
- curXrayData.XrayData = m_XrayData;
- curXrayData.listElement = m_listElement;
- currentCommand.AreaXrayDataReceived += 1;
- if (currentCommand.AreaXrayDataReceived == currentCommand.XrayPrmForFeatures.Count)
- {
- m_bXrayDone = true;
- }
- }
-
- }
- }
- bool ReadXrayData(IEdSpectrum a_spectrum, out uint[] a_pSpectrumData, int a_nBufferSize)
- {
- a_pSpectrumData = new uint[a_nBufferSize];
- int[] xrayData = new 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)
- {
- uint nValue = (uint)(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
- uint nValueToLeftBin = (uint)((double)nValue * dLeft_Percent + 0.5);
- // put data into bins
- a_pSpectrumData[nLeftBin] += nValueToLeftBin;
- if ((nLeftBin + 1) < a_nBufferSize)
- {
- a_pSpectrumData[nLeftBin + 1] += (nValue - nValueToLeftBin);
- }
- }
- return true;
- }
-
- public bool IsAcquiringSpectrum()
- {
- return EdSpectrumAcquisitionController.IsAcquiring;
- }
-
- public void BeginMultipleAquisition()
- {
- EdSpectrumAcquisitionController.BeginMultipleAcquisition();
- }
- public void EndMultipleAquisition()
- {
- EdSpectrumAcquisitionController.EndMultipleAcquisition();
- }
-
- public bool GetSemBeamOn()
- {
- var beamon = microscopeController.ColumnConditions.BeamOn;
- if (beamon == 1)
- {
- return true;
- }
- else
- {
- return false;
-
- }
-
- }
- public bool SetSemBeamOnOrOff(bool val)
- {
- double beamon ;
- if (val)
- {
- beamon = 1;
- }
- else
- {
- beamon = 0;
- }
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.BeamOn, (double)beamon }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 10000)
- {
- currentCommand.returnType = false;
- return false;
- }
- }
- return true;
- }
- public bool SetSemFilamentOnOrOff(bool val)
- {
- double beamon;
- if (val)
- {
- beamon = 1;
- }
- else
- {
- beamon = 0;
- }
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.FilamentOn, (double)beamon }
- };
- m_CollumnUpdated = false;
- this.microscopeController.SetColumnConditions(columnDictionary);
- int time1 = Environment.TickCount;
- int time2;
- while (!m_CollumnUpdated)
- {
- Application.DoEvents();
- time2 = Environment.TickCount;
- if (time2 - time1 > 10000)
- {
- currentCommand.returnType = false;
- return false;
- }
- }
- return true;
- }
- public void StopXrayAquisition()
- {
- EdSpectrumAcquisitionController.StopAcquisition();
- }
- public void SetQuantifiCationParam(bool IfAutoId, string knownElements)
- {
- m_ifautoid = IfAutoId;
- m_knownelements = knownElements;
- }
- #endregion
- }
- }
|