| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857 | 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.Drawing;using System.Drawing.Imaging;using System.IO;using System.Linq;using System.Text;using System.Threading;//显示弹出信息using System.Windows.Forms;namespace Extender{    enum OxfordCommand    {        //缩放        GetMagnification = 0,        SetMagnification = 1,        //焦距        GetWorkingDistance = 2,        SetWorkingDistance = 3,        //亮度        GetBrightness = 4,        SetBrightness = 5,        //对比度        GetContrast = 6,        SetContrast = 7,        //SEM电压        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,        //拍图        GrabImage = 23,        //采集参数设置        SetImageAcquistionSetting = 24,        //获取分辨率        GetImageStore = 25,        //设置分辨率        SetImageStore = 26,        //获取bitmap        GetBitmap = 27,        IsAcquiringSpectrum = 28,        //X-ray        //点采集        XrayPointCollectiong = 29,        //面采集        XrayAreaCollectiong = 30,        BeginMultipleAquisition=31,        EndMultipleAquisition=32,        Exit=100,    }    public struct GrabImageParam    {      public  GrabImageParam(string filename, short xoff, short yoff, short width, short height, short type)        {            this.filename = filename;            this.xoff = xoff;            this.yoff = yoff;            this.width = width;            this.height = height;            this.type = type;        }        public string filename;        public short xoff;        public short yoff;        public short width;        public short height;        public short type;    }    public class PointXrayParam    {      public  PointXrayParam()      {                     this.XrayData = new long[2000];         this.listElement=new  Dictionary<string, double> ();       }      public  double dMilliSecondsTime;        public     double x;          public  double y;        public long[] XrayData ;          public   Dictionary<string, double> listElement;    }    public struct AreaXrayParam    {       public double dMilliSecondsTime;       public List<Segment> a_listChord;      public  long[] XrayData;       public Dictionary<string, double> a_listElement;    }    public struct MoveStageParam    {        public float x;        public float y;    }    public class ExtenderWrapper : IExtenderControl    {        struct oxfordCommandData        {           public OxfordCommand commandType;            public bool returnType;            public MoveStageParam moveStagePrm;            public GrabImageParam grabImgParam;            public PointXrayParam pointXrayPrm;            public AreaXrayParam areaXrayPrm;        }                               private Thread controlThread;        private oxfordCommandData currentCommand;        private Extender myExtender=null;        AutoResetEvent startEvent= new AutoResetEvent(false);        AutoResetEvent endEvent = new AutoResetEvent(false);        private NLog.Logger log;        public ExtenderWrapper()        {            if (myExtender == null)            {                myExtender = new Extender();            }            log = NLog.LogManager.GetCurrentClassLogger();            controlThread = new Thread(this.ControlerThread);            //controlThread.IsBackground = true;            controlThread.Start();            //Thread.Sleep(100);//wait untill the new thread has been started        }        public void CloseExtender()        {            if (myExtender != null)            {                myExtender.CloseExtender();                currentCommand.commandType = OxfordCommand.Exit;                startEvent.Set();                controlThread.Join();            }                   }          ~ExtenderWrapper()        {            this.CloseExtender();        }        private void ControlerThread()        {            log.Info("myExtender has been initialized");            while (true)            {                while (true)                {                    if (startEvent.WaitOne(0, true))                    {                        break;                    }                    Thread.Sleep(50);                    Application.DoEvents();                }                switch (currentCommand.commandType)                {                    case OxfordCommand.MoveStageXY:                        {                            MoveStageParam p = currentCommand.moveStagePrm;                            if (myExtender.MoveStageXY(p.x, p.y))                            {                                currentCommand.returnType = true;                            }                            else                            {                                currentCommand.returnType = false;                            }                            endEvent.Set();                        }                        break;                    case OxfordCommand.GrabImage:                        {                            GrabImageParam p = currentCommand.grabImgParam;                            log.Info("begin:GrabImage:oxford thread 线程ID:" + Thread.CurrentThread.ManagedThreadId.ToString() );                            if (myExtender.GrabImage(p.filename, p.xoff, p.yoff, p.width, p.height, p.type))                            {                                currentCommand.returnType = true;                                log.Info("GrabImage:oxford thread return: " + currentCommand.returnType.ToString());                            }                            else                            {                                currentCommand.returnType = false;                                log.Info("GrabImage:oxford thread return: " + currentCommand.returnType.ToString());                            }                            endEvent.Set();                        }                        break;                                       case OxfordCommand.XrayPointCollectiong:                        {                            PointXrayParam p = currentCommand.pointXrayPrm;                                                       log.Info("线程:开始采集单点xray");                                                        if (myExtender.XrayPointCollecting(p.dMilliSecondsTime, p.x, p.y, out p.XrayData,out p.listElement))                            {                                                                currentCommand.pointXrayPrm = p;                                currentCommand.returnType = true;                            }                            else                            {                                log.Error("线程:采集单点xray失败");                                currentCommand.returnType = false;                            }                            endEvent.Set();                        }                        break;                    case OxfordCommand.XrayAreaCollectiong:                        {                            AreaXrayParam p = currentCommand.areaXrayPrm;                            if (myExtender.XrayAreaCollectiong( p.dMilliSecondsTime, p.a_listChord,out p.XrayData, out p.a_listElement))                            {                                currentCommand.areaXrayPrm = p;                                currentCommand.returnType = true;                                                           }                            else                            {                                currentCommand.returnType = false;                            }                            endEvent.Set();                        }                        break;                    case OxfordCommand.BeginMultipleAquisition:                        {                            myExtender.BeginMultipleAquisition();                            endEvent.Set();                                                   }                        break;                    case OxfordCommand.EndMultipleAquisition:                        {                            myExtender.EndMultipleAquisition();                            endEvent.Set();                        }                        break;                    case OxfordCommand.Exit:                        {                         endEvent.Set();                            log.Info("receive exit command");                        }                       break;                }                if (currentCommand.commandType == OxfordCommand.Exit)                {                    log.Info("exiting the thread");                    break;                }            }        }        public Bitmap GetBitmap()        {            return myExtender.GetBitmap();        }        public float GetBrightness()        {            return myExtender.GetBrightness();        }        public float GetContrast()        {            return myExtender.GetContrast();        }        public int[] GetImageStore()        {            return myExtender.GetImageStore();        }        public float GetMagnification()        {            return myExtender.GetMagnification();        }        public float GetSEMVoltage()        {            return myExtender.GetSEMVoltage();        }        public float GetStageAtR()        {            return myExtender.GetStageAtR();        }        public float GetStageAtT()        {            return myExtender.GetStageAtT();        }        public float GetStageAtX()        {            return myExtender.GetStageAtX();        }        public float GetStageAtY()        {            return myExtender.GetStageAtY();        }        public float GetStageAtZ()        {            return myExtender.GetStageAtZ();        }        public float[] GetStagePosition()        {            return myExtender.GetStagePosition();        }        public float GetWorkingDistance()        {            return myExtender.GetWorkingDistance();        }        public bool GrabImage(string filename, short xoff, short yoff, short width, short height, short type)        {            currentCommand.grabImgParam =new GrabImageParam(filename, xoff, yoff, width, height, type);            currentCommand.commandType = OxfordCommand.GrabImage;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }                Thread.Sleep(100);                Application.DoEvents();            }            log.Info("GrabImage:oxford thread return: " + currentCommand.returnType.ToString());            if (currentCommand.returnType == true)            {                return true;            }            else            {                return false;            }                    }        public bool IsAcquiringSpectrum()        {            return myExtender.IsAcquiringSpectrum();        }        public bool MoveStageXY(float x, float y)        {            currentCommand.moveStagePrm = new MoveStageParam();            currentCommand.moveStagePrm.x = x;            currentCommand.moveStagePrm.y = y;            currentCommand.commandType = OxfordCommand.MoveStageXY;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }            }            if (currentCommand.returnType == true)            {                return true;            }            else            {                return false;            }        }        public bool SetBrightness(float set)        {            return myExtender.SetBrightness(set);        }        public bool SetContrast(float set)        {            return myExtender.SetContrast(set);        }        public bool SetImageAcquistionSetting(double a_dDwellTime, int a_nImageType, double a_dImageScanSize)        {            return myExtender.SetImageAcquistionSetting(a_dDwellTime, a_nImageType, a_dImageScanSize);        }        public bool SetImageStore(float set)        {            return myExtender.SetImageStore(set);        }        public bool SetMagnification(float set)        {            return myExtender.SetMagnification(set);        }        public bool SetSEMVoltage(float set)        {            return myExtender.SetSEMVoltage(set);        }        public bool SetStageGotoR(float set)        {            return myExtender.SetStageGotoR(set);        }        public bool SetStageGotoT(float set)        {            return myExtender.SetStageGotoT(set);        }        public bool SetStageGotoX(float set)        {            return myExtender.SetStageGotoX(set);        }        public bool SetStageGotoY(float set)        {            return myExtender.SetStageGotoY(set);        }        public bool SetStageGotoZ(float set)        {            return myExtender.SetStageGotoZ(set);        }        public bool SetStagePosition(float[] set)        {            return myExtender.SetStagePosition(set);        }        public bool SetWorkingDistance(float set)        {            return myExtender.SetWorkingDistance(set);        }        public bool XrayAreaCollectiong( double dMilliSecondsTime, List<Segment> a_listChord, out long[] XrayData, out Dictionary<string, double> a_listElement)        {            var p = new AreaXrayParam();             p = currentCommand.areaXrayPrm;            p.dMilliSecondsTime = dMilliSecondsTime;            p.a_listChord = a_listChord;            currentCommand.areaXrayPrm = p;            currentCommand.commandType = OxfordCommand.XrayAreaCollectiong;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }            }            if (currentCommand.returnType == true)            {                XrayData= currentCommand.areaXrayPrm.XrayData  ;                 a_listElement= currentCommand.areaXrayPrm.a_listElement ;                return true;            }            else            {                XrayData = p.XrayData;                a_listElement = p.a_listElement;                return false;            }        }        public bool XrayPointCollecting(double dMilliSecondsTime, double x, double y, out long[] XrayData, out Dictionary<string, double> a_listElement)        {            var p = new PointXrayParam();                       p.dMilliSecondsTime = dMilliSecondsTime;            p.x = x;            p.y = y;            currentCommand.pointXrayPrm = p;            currentCommand.commandType = OxfordCommand.XrayPointCollectiong;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }                Application.DoEvents();            }            if (currentCommand.returnType == true)            {                XrayData= currentCommand.pointXrayPrm.XrayData  ;                a_listElement= currentCommand.pointXrayPrm.listElement  ;                return true;            }            else            {                XrayData = p.XrayData;                a_listElement = p.listElement;                return false;            }        }               public void BeginMultipleAquisition()        {            currentCommand.commandType = OxfordCommand.BeginMultipleAquisition;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }                Application.DoEvents();            }                              }        public void EndMultipleAquisition()        {            currentCommand.commandType = OxfordCommand.EndMultipleAquisition;            startEvent.Set();            while (true)            {                if (endEvent.WaitOne(0, false))                {                    break;                }                Application.DoEvents();            }        }    }    public class Extender : IExtenderControl    {                  //构造函数    public Extender()        {            InitMicroscopeController();            InitImageAcquisition();            InitXrayAcquistion();        }        //结束        public void CloseExtender()        {            CloseMicroscopeController();            CloseImageAcquisition();            CloaseXrayAcquistion();        }        #region 电镜控制、样品台        //控制电镜        private IMicroscopeController microscopeController = null;        //电压        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 double m_dStageXMax;        public double StageXMax        {            get { return this.m_dStageXMax; }            set { this.m_dStageXMax = value; }        }        private double m_dStageXMin;        public double StageXMin        {            get { return this.m_dStageXMin; }            set { this.m_dStageXMin = value; }        }        private double m_dStageYMax;        public double StageYMax        {            get { return this.m_dStageYMax; }            set { this.m_dStageYMax = value; }        }        private double m_dStageYMin;        public double StageYMin        {            get { return this.m_dStageYMin; }            set { this.m_dStageYMin = value; }        }        private double m_dStageZMax;        public double StageZMax        {            get { return this.m_dStageZMax; }            set { this.m_dStageZMax = value; }        }        private double m_dStageZMin;        public double StageZMin        {            get { return this.m_dStageZMin; }            set { this.m_dStageZMin = value; }        }        private double m_dStageTMax;        public double StageTMax        {            get { return this.m_dStageTMax; }            set { this.m_dStageTMax = value; }        }        private double m_dStageTMin;        public double StageTMin        {            get { return this.m_dStageTMin; }            set { this.m_dStageTMin = value; }        }        private double m_dStageRMax;        public double StageRMax        {            get { return this.m_dStageRMax; }            set { this.m_dStageRMax = value; }        }        private double m_dStageRMin;        public double StageRMin        {            get { return this.m_dStageRMin; }            set { this.m_dStageRMin = value; }        }        //控制电镜初始化        void InitMicroscopeController(float a_fStageXMin = 0, float a_fStageXMax = 130,            float a_fStageYMin = 0, float a_fStageYMax = 130,            float a_fStageZMin = 0, float a_fStageZMax = 40,            float a_fStageTMin = 0, float a_fStageTMax = 90,            float a_fStageRMin = 0, float a_fStageRMax = 360)        {            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();            StageXMax = a_fStageXMax;            StageXMin = a_fStageXMin;            StageYMax = a_fStageYMax;            StageYMin = a_fStageYMin;            StageZMax = a_fStageZMax;            StageZMin = a_fStageZMin;            StageTMax = a_fStageTMax;            StageTMin = a_fStageTMin;            StageRMax = a_fStageRMax;            StageRMin = a_fStageRMin;        }        //控制电镜释放        void CloseMicroscopeController()        {            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;        }        //读取当前的电镜控制值        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;            if (stageCapabilities.StageX.CanRead)            {                this.m_dStageX = stageConditions.StageX;            }            if (stageCapabilities.StageY.CanRead)            {                this.m_dStageY = stageConditions.StageY;            }            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)        {            //MessageBox.Show("电镜控制改变ColumnChange");            ReadMicroscopeColumn();        }        //样品台控制改变事件        private void OnMicroscopeStageChange(object sender, EventArgs e)        {            //MessageBox.Show("样品控制改变StageChange");            ReadStage();        }        //列控制连接或断开时的事件        private void OnMicroscopeColumnConnected(object sender, EventArgs e)        {            //MessageBox.Show("电镜控制连接ColumnConnected");        }        //样品台控制连接或断开时的事件        private void OnMicroscopeStageConnected(object sender, EventArgs e)        {            //MessageBox.Show("样品台连接StageConnected");            ReadStage();        }        //样品台控制、电镜控制、外围控制的事件改变完成        private void OnMicroscopeChangeCompleted(object sender, EventArgs e)        {            //MessageBox.Show("电镜控制完成ChangeCompleted");            ReadMicroscopeColumn();            ReadStage();        }        //电镜控制        //电压        //放大倍数        //工作距离        //亮度        //对比度        //BeamOn        //FilamentOn        //缩放        public float GetMagnification()        {            return (float)m_dMagnification;        }        public Boolean SetMagnification(float set)        {            Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>            {                { Column.Magnification, (double)set }            };            this.microscopeController.SetColumnConditions(columnDictionary);            return true;        }        //焦距        public float GetWorkingDistance()        {            return (float)m_dWorkingDistance;        }        public Boolean SetWorkingDistance(float set)        {            Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>            {                { Column.WorkingDistance, (double)set }            };            this.microscopeController.SetColumnConditions(columnDictionary);            return true;        }        //亮度        public float GetBrightness()        {                       return (float)m_dBirghtness;        }        public Boolean SetBrightness(float set)        {            Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>            {                { Column.Brightness, (double)set }            };            this.microscopeController.SetColumnConditions(columnDictionary);            return true;        }        //对比度        public float GetContrast()        {            return (float)m_dContrast;        }        public Boolean SetContrast(float set)        {            Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>            {                { Column.Contrast, (double)set }            };            this.microscopeController.SetColumnConditions(columnDictionary);            return true;        }        //SEM电压        public float GetSEMVoltage()        {            return (float)m_dHighVoltage;        }        public Boolean SetSEMVoltage(float set)        {            Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>            {                { Column.HighVoltage, (double)set }            };            this.microscopeController.SetColumnConditions(columnDictionary);            return true;        }        //样品台        public float[] GetStagePosition()        {            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];            if (stageX > StageXMax || stageX < StageXMin)            {                return false;            }            double stageY = (double)set[1];            if (stageY > StageYMax || stageY < StageYMin)            {                return false;            }            double stageZ = (double)set[2];            if (stageZ > StageZMax || stageZ < StageZMin)            {                return false;            }            double stageT = (double)set[3];            if (stageT > StageTMax || stageT < StageTMin)            {                return false;            }            double stageR = (double)set[4];            if (stageR > StageRMax || stageR < StageRMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageX, (double)stageX },                { Stage.StageY, (double)stageY },                { Stage.StageZ, (double)stageZ },                { Stage.StageT, (double)stageT },                { Stage.StageR, (double)stageR }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public float GetStageAtX()        {            return (float)m_dStageX;        }        public float GetStageAtY()        {            return (float)m_dStageY;        }        public float GetStageAtZ()        {            return (float)m_dStageZ;        }        public float GetStageAtT()        {            return (float)m_dStageT;        }        public float GetStageAtR()        {            return (float)m_dStageR;        }        public Boolean SetStageGotoX(float set)        {            double stageX = (double)set;            if (stageX > StageXMax || stageX < StageXMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageX, (double)stageX }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public Boolean SetStageGotoY(float set)        {            double stageY = (double)set;            if (stageY > StageYMax || stageY < StageYMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageY, (double)stageY }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public Boolean SetStageGotoZ(float set)        {            double stageZ = (double)set;            if (stageZ > StageZMax || stageZ < StageZMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageZ, (double)stageZ }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public Boolean SetStageGotoT(float set)        {            double stageT = (double)set;            if (stageT > StageTMax || stageT < StageTMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageT, (double)stageT }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public Boolean SetStageGotoR(float set)        {            double stageR = (double)set;            if (stageR > StageRMax || stageR < StageRMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageR, (double)stageR }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        public Boolean MoveStageXY(float x, float y)        {            double stageX = (double)x;            if (stageX > StageXMax || stageX < StageXMin)            {                return false;            }            double stageY = (double)y;            if (stageY > StageYMax || stageY < StageYMin)            {                return false;            }            var stageDictionary = new Dictionary<Stage, double>            {                { Stage.StageX, (double)stageX },                { Stage.StageY, (double)stageY }            };            this.microscopeController.SetStageConditions(stageDictionary);            return true;        }        #endregion        #region 拍图        /// <summary>        /// IImageAcquisitionController object        /// </summary>        private IImageAcquisitionController imageAcquisitionController = null;        /// <summary>        /// IImageSettings object        /// </summary>        private IImageAcquisitionSettings imageAcquisitionSettings = null;        //图像扫描尺寸        public double[] ImageScanSize =        {            32,            64,            128,            256,            512,            1024,            4096,            8192        };        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 Bitmap m_Bitmap = null;        void InitImageAcquisition()        {            imageAcquisitionController = AcquireFactory.CreateImageServer();            imageAcquisitionSettings = AcquireFactory.CreateImageSettings();            //imageAcquisitionSettings.            imageAcquisitionController.ExperimentStarted += this.OnImageExperimentStarted;            imageAcquisitionController.ExperimentFinished += this.OnImageExperimentFinished;                  }        //控制电镜释放        void CloseImageAcquisition()        {            imageAcquisitionController.ExperimentStarted -= this.OnImageExperimentStarted;            imageAcquisitionController.ExperimentFinished -= this.OnImageExperimentFinished;        }        /// <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))            {                MessageBox.Show("图像采集完成,获取图像像素失败!");            }            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);                MessageBox.Show(msg);                int nOffset = nBytesPerPixel - 1;                for (int i = 0; i < nImageSize; ++i)                {                    a_pImageBits[i] = imageData[nOffset + i * nBytesPerPixel];                }            }            return true;        }        void AcquisitionParamInit()        {            m_ImageBit = null;            m_nImageWidth = 0;            m_nImageHeight = 0;            m_bAcquistionDone = false;            Bitmap m_Bitmap = null;        }        //a_dDwellTime : 1~100000之间的数         //a_sImageType : 1: SE, 2: Bse        //a_dImageScanSize : 图像分辨率,图像的高        public bool SetImageAcquistionSetting(double a_dDwellTime, int a_nImageType, double a_dImageScanSize)        {                                  IImageSettings imageSettings = imageAcquisitionSettings.ImageSettings;            IImageCapabilities imageCapabilities = imageAcquisitionSettings.ImageCapabilities;            IImageScanSettings scanSettings = imageAcquisitionSettings.ScanSettings;                                 if (a_dDwellTime > imageCapabilities.MaximumImageDwellMicroseconds)            {                imageSettings.DwellTimeMicroSeconds = imageCapabilities.MaximumImageDwellMicroseconds;            }            if (a_dDwellTime < imageCapabilities.MinimumImageDwellMicroseconds)            {                imageSettings.DwellTimeMicroSeconds = imageCapabilities.MinimumImageDwellMicroseconds;            }            else            {                imageSettings.DwellTimeMicroSeconds = a_dDwellTime;            }            imageSettings.InputSources.ToList().ForEach(i => imageSettings.EnableInputSource(i.Key, false));            imageSettings.EnableInputSource((ImageInputSources)a_nImageType, true);            if (!ImageScanSize.Contains(a_dImageScanSize))            {                MessageBox.Show("图像尺寸输入无效");                return false;            }            var pixelSize = 1d / a_dImageScanSize;                     scanSettings.AcquisitionRegion.CreateFullFieldRegion(pixelSize);            return true;        }        ////拍图        public Boolean GrabImage(String filename, short xoff, short yoff, short width, short height, short type)        {           SetImageAcquistionSetting(1, 1, 1024);            AcquisitionParamInit();            try            {                int lastingTime = 0;                NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();                                              //imageAcquisitionController.BeginMultipleAcquisition();                IEnumerable<IElectronImage> images = imageAcquisitionController.StartAcquisition(imageAcquisitionSettings);                               log.Info("拍图开始 startAcquisition 完成");                images.ToList().ForEach(i =>                {                    i.Label = string.Format(@"Code example image - {0:HH:mm:ss} - {1}", DateTime.Now, i.InputSource.ToString());                });                while (true)                {                    if (m_bAcquistionDone)                    {                        // 图像对象                        m_Bitmap = ToGrayBitmap(m_ImageBit, (int)m_nImageHeight, (int)m_nImageWidth);                        switch (Path.GetExtension(filename))                        {                            case ".bmp":                                m_Bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);                                break;                            case ".jpg":                                m_Bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);                                break;                            case ".gif":                                m_Bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Gif);                                break;                            case ".tif":                                m_Bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff);                                break;                            case ".png":                                m_Bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);                                break;                            default:                                break;                        }                        break;                    }                    Application.DoEvents();                    Thread.Sleep(100);                    lastingTime += 100;                    if (lastingTime > EDSColletionTimeOut*6)                    {                        return false;                    }                }            }            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));                MessageBox.Show(sb.ToString());            }            catch (AcquisitionStartException startException)            {                string msg = string.Format(@"AcquisitionStartException: {0}", startException.Message);                MessageBox.Show(msg);            }            return true;        }        /// <summary>            /// 将一个byte的数组转换为8bit灰度位图        /// </summary>            /// <param name="data">数组</param>            /// <param name="width">图像宽度</param>            /// <param name="height">图像高度</param>            /// <returns>位图</returns>            Bitmap ToGrayBitmap(byte[] data, int width, int height)        {            // 申请目标位图的变量,并将其内存区域锁定                Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);            //BitmapData这部分内容  需要 using System.Drawing.Imaging;              BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height),            ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);            // 获取图像参数                // 扫描线的宽度               int stride = bmpData.Stride;            // 显示宽度与扫描线宽度的间隙              int offset = stride - width;            // 获取bmpData的内存起始位置            IntPtr iptr = bmpData.Scan0;            // 用stride宽度,表示这是内存区域的大小            int scanBytes = stride * height;            // 下面把原始的显示大小字节数组转换为内存中实际存放的字节数组                int posScan = 0;            int posReal = 0;// 分别设置两个位置指针,指向源数组和目标数组                byte[] pixelValues = new byte[scanBytes];  //为目标数组分配内存                for (int x = 0; x < height; x++)            {                int startIndex = x * width;                //// 下面的循环节是模拟行扫描                    for (int y = 0; y < width; y++)                {                    pixelValues[posScan++] = data[posReal++];                }                posScan += offset;  //行扫描结束,要将目标位置指针移过那段“间隙”                }            // 用Marshal的Copy方法,将刚才得到的内存字节数组复制到BitmapData中                System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, iptr, scanBytes);            bmp.UnlockBits(bmpData);  // 解锁内存区域                // 下面的代码是为了修改生成位图的索引表,从伪彩修改为灰度                ColorPalette tempPalette;            using (Bitmap tempBmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))            {                tempPalette = tempBmp.Palette;            }            for (int i = 0; i < 256; i++)            {                tempPalette.Entries[i] = Color.FromArgb(i, i, i);            }            bmp.Palette = tempPalette;            return bmp;        }        //获取分辨率        public int[] GetImageStore()        {            int[] ImageStore = new int[8];            for (int i = 0; i < 8; i++)            {                ImageStore[i] = (int)ImageScanSize[i];            }            return ImageStore;        }        //设置分辨率        public Boolean SetImageStore(float set)        {            IImageScanSettings scanSettings = imageAcquisitionSettings.ScanSettings;            if (!ImageScanSize.Contains(set))            {                MessageBox.Show("图像尺寸输入无效");                return false;            }            var pixelSize = 1d / (double)set;            scanSettings.AcquisitionRegion.CreateFullFieldRegion(pixelSize);            return true;        }        public Bitmap GetBitmap()        {            return m_Bitmap;        }        #endregion        #region X-ray        //控制器        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 int XRayChannelLength = 2000;        private long[] m_XrayData = null;        private bool m_bXrayDone = false;        private int EDSColletionTimeOut=10000;        /// <summary>        /// List of EdSpectrum objects        /// </summary>        private Dictionary<string, double> listElement = null;        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 CloaseXrayAcquistion()        {            EdSpectrumAcquisitionController.ExperimentFinished -= this.OnEdSpectrumExperimentFinished;            //EdSpectrumAcquisitionController.ExperimentStarted -= this.OnEdSpectrumExperimentStarted;        }        void SetXrayAcquisitionParam(ref double a_dMilliSecondsTime)        {            EdSpectrumSettings.EdSettings.AcquisitionMode = EdAcquireMode.LiveTime; // RealTime or LiveTime            if (a_dMilliSecondsTime < 5000)            {                a_dMilliSecondsTime = 5000;            }            EdSpectrumSettings.EdSettings.AcquisitionTime = TimeSpan.FromMilliseconds(a_dMilliSecondsTime);            EdSpectrumSettings.EdSettings.ProcessTime = 4;            EdSpectrumSettings.EdSettings.EnergyRange = 20;            EdSpectrumSettings.EdSettings.NumberOfChannels = 4096;           // EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreateFullFieldRegion(1.0 / 1024.0);        }        void SetPointAcquistionRegion(double a_nX, double a_nY)        {                        EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreatePointRegion(new System.Windows.Point(a_nX, a_nY));        }        void SetAreaAcquistionRegion(List<Chord> a_nChords)        {            ChordList chordsList = null;            if (m_nImageWidth != 0)            {                chordsList = new ChordList(a_nChords, 1 / (double)m_nImageWidth);            }            else            {                chordsList = new ChordList(a_nChords, 1 / 1024.0);            }            EdSpectrumSettings.ScanSettings.AcquisitionRegion.CreateChordListRegion(chordsList);        }        void XrayParamInit()        {            m_XrayData = null;            m_bXrayDone = false;        }        /// <summary>        /// Called when IEdSpectrumAcquisitionController Experiment Starting.        /// </summary>        /// <param name="sender">The sender.</param>        /// <param name="e">The <see cref="AcquisitionFinishedEventArgs{IEdSpectrum}"/> instance containing the event data.</param>        private void OnEdSpectrumExperimentStarting(object sender, AcquisitionStartingEventArgs<IEdSpectrum> e)        {                    }        /// <summary>        /// Called when IEdSpectrumAcquisitionController Experiment Started.        /// </summary>        /// <param name="sender">The sender.</param>        /// <param name="e">The <see cref="AcquisitionFinishedEventArgs{IEdSpectrum}"/> instance containing the event data.</param>        private void OnEdSpectrumExperimentStarted(object sender, AcquisitionStartedEventArgs<IEdSpectrum> e)        {                    }        /// <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;                       NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();            IEdSpectrum edSpectrum = e.Value;            if (!ReadXrayData(edSpectrum, out m_XrayData, XRayChannelLength))            {                MessageBox.Show("Xray采集完成,获取图像像素失败!");            }            long nXraycount = 0;            for (int i = 0; i < 2000; i++)            {                nXraycount += m_XrayData[i];            }            //Quantify processing                        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;            //Get element result for single point            //quantStatus.Results.            var ie = Results.GetEnumerator();            listElement = new Dictionary<string, double>();            while (ie.MoveNext())            {                ISEMQuantResult result = ie.Current;                if (result.WeightPercent != 0)                {                    listElement.Add(ElementProperties.GetElementSymbol(result.AtomicNumber), result.WeightPercent );                }                            }            if (m_XrayData != null && m_XrayData.Length == XRayChannelLength)            {                               log.Info("xray 采集结束事件,采集成功 当前线程" + Thread.CurrentThread.ManagedThreadId.ToString());                log.Info("计数率为:" + nXraycount.ToString());                if (nXraycount < 5000)                {                    log.Warn("计数率低于5000!");                }                m_bXrayDone = true;            }                   }        bool ReadXrayData(IEdSpectrum a_spectrum, out long[] a_pSpectrumData, int a_nBufferSize)        {            a_pSpectrumData = new long[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)            {                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;        }        /// <summary>        /// Called when IEdSpectrum DataChanged        /// </summary>        /// <param name="sender">Event source</param>        /// <param name="e">Event arguments</param>        private void OnDataChanged(object sender, EventArgs e)        {                    }        public bool IsAcquiringSpectrum()        {             return EdSpectrumAcquisitionController.IsAcquiring;         }        //点扫描        //X-ray        public Boolean XrayPointCollecting(double dMilliSecondsTime, double x, double y, out long[] XrayData, out Dictionary<string, double> a_listElement)        {                       XrayParamInit();                       XrayData = new long[XRayChannelLength];            a_listElement = new Dictionary<string, double>();                       SetXrayAcquisitionParam(ref dMilliSecondsTime);                      SetPointAcquistionRegion(x*m_dImagePixelsize, y*m_dImagePixelsize);            NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();            log.Info("开始XrayStartAcquisition:t="+dMilliSecondsTime.ToString()+"pos="+"("+x.ToString()+","+y.ToString()+")");            if (EdSpectrumAcquisitionController.IsEdHardwareReady(EdSpectrumSettings))            {                // Start spectrum acquisition                try                {                    m_bXrayDone = false;                    int lastingTime = 0;                                      IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);                    edSpectrum.Label = string.Format(@"Point({0},{1})",x,y);                                                          while (true)                    {                        if (m_bXrayDone)                        {                            XrayData = m_XrayData;                            a_listElement =listElement;                                                        break;                        }                        Application.DoEvents();                        Thread.Sleep(100);                                               lastingTime += 100;                        if (lastingTime > EDSColletionTimeOut*3)                        {                            //EdSpectrumAcquisitionController.EndMultipleAcquisition();                            log.Warn("XrayStartAcquisition 超时!");                            return false;                        }                    }                }                catch (InvalidSettingsException invalidSettingsException)                {                                       string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",                        invalidSettingsException.Message,                        invalidSettingsException.ValidationResults.ValidationErrors);                    MessageBox.Show(msg);                }                catch (AcquisitionStartException acquisitionStartException)                {                                       string msg = string.Format(@"Acquisition Start Exception:{0}",acquisitionStartException.Message);                    MessageBox.Show(msg);                }            }                       return true;        }        //面扫描        public Boolean XrayAreaCollectiong( double dMilliSecondsTime, List<Segment> a_listChord, out long[] XrayData, out Dictionary<string, double> a_listElement)        {            XrayParamInit();            XrayData = new long[XRayChannelLength];            a_listElement = new Dictionary<string, double>();            SetXrayAcquisitionParam(ref dMilliSecondsTime);            List<Chord> Chords = new List<Chord>();            foreach (Segment seg in a_listChord)            {                Chord chord = new Chord(seg.X, seg.Y, seg.Length);                Chords.Add(chord);            }            SetAreaAcquistionRegion(Chords);            // IEdSpectrumSettings.EdCapabilities will validate settings and hardware availability.            if (EdSpectrumAcquisitionController.IsEdHardwareReady(EdSpectrumSettings))            {                // This only used for multiple acquisition:                //      if this is the first acquisition, call BeginMultipleAcquisition                 //      on the IEdSpectrumAcquisitionController to suppress external scan switching                //if (m_bXrayDone)                //    EdSpectrumAcquisitionController.BeginMultipleAcquisition();                // Start spectrum acquisition                try                {                    int lastingTime = 0;                    IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);                    edSpectrum.Label = string.Format(@"chord");                    while (true)                    {                        if (m_bXrayDone)                        {                            XrayData = m_XrayData;                            a_listElement = listElement;                            break;                        }                                           Thread.Sleep(100);                        Application.DoEvents();                        lastingTime += 100;                        if (lastingTime > EDSColletionTimeOut*3)                        {                            //EdSpectrumAcquisitionController.EndMultipleAcquisition();                            return false;                        }                    }                }                catch (InvalidSettingsException invalidSettingsException)                {                    string msg = string.Format(@"Invalid Settings Exception:{0}, {1}",                        invalidSettingsException.Message,                        invalidSettingsException.ValidationResults.ValidationErrors);                    MessageBox.Show(msg);                }                catch (AcquisitionStartException acquisitionStartException)                {                    string msg = string.Format(@"Acquisition Start Exception:{0}", acquisitionStartException.Message);                    MessageBox.Show(msg);                }            }            return true;        }        public void BeginMultipleAquisition()        {            EdSpectrumAcquisitionController.BeginMultipleAcquisition();        }        public void EndMultipleAquisition()        {            EdSpectrumAcquisitionController.EndMultipleAcquisition();        }        #endregion    }}
 |