浏览代码

修正牛津驱动

gsp 4 年之前
父节点
当前提交
bffee53e65
共有 2 个文件被更改,包括 492 次插入5 次删除
  1. 491 4
      ExtenderControl/Extender.cs
  2. 1 1
      ExtenderControl/ExtenderInterface.cs

+ 491 - 4
ExtenderControl/Extender.cs

@@ -25,13 +25,470 @@ using OINA.Extender.Processing.Quant;
 
 using System.ComponentModel;
 using OINA.Extender.Data.Ed;
-
+using System.Threading;
 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,
+
+    }
+    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 struct PointXrayParam
+    {
+      public  double dMilliSecondsTime;
+        public     int x;
+          public  int 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;
+        AutoResetEvent startEvent= new AutoResetEvent(false);
+        AutoResetEvent endEvent = new AutoResetEvent(false);
+        public ExtenderWrapper()
+        {
+            myExtender = new Extender();
+            controlThread = new Thread(this.ControlerThread);
+            controlThread.Start();
+        }
+        private void ControlerThread()
+        {
+            while (true)
+            {
+
+                while (true)
+                {
+                    if (startEvent.WaitOne(0, true))
+                    {
+
+                        break;
+                    }
+
+                    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;
+                            if (myExtender.GrabImage(p.filename, p.xoff, p.yoff, p.width, p.height, p.type))
+                            {
+                                currentCommand.returnType = true;
+                            }
+                            else
+                            {
+                                currentCommand.returnType = false;
+                            }
+                            endEvent.Set();
+                        }
+                        break;
+                   
+                    case OxfordCommand.XrayPointCollectiong:
+                        {
+                            PointXrayParam p = currentCommand.pointXrayPrm;
+                            if (myExtender.XrayPointCollectiong(p.dMilliSecondsTime, p.x, p.y, out p.XrayData,out p.listElement))
+                            {
+                                currentCommand.returnType = true;
+                            }
+                            else
+                            {
+                                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.returnType = true;
+                            }
+                            else
+                            {
+                                currentCommand.returnType = false;
+                            }
+                            endEvent.Set();
+                        }
+                        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;
+                }
+            }
+            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)
+        {
+            currentCommand.areaXrayPrm = new AreaXrayParam();
+            var p = currentCommand.areaXrayPrm;
+            p.dMilliSecondsTime = dMilliSecondsTime;
+            p.a_listChord = a_listChord;
+            
+            currentCommand.commandType = OxfordCommand.XrayAreaCollectiong;
+            startEvent.Set();
+            while (true)
+            {
+                if (endEvent.WaitOne(0, false))
+                {
+                    break;
+                }
+            }
+            if (currentCommand.returnType == true)
+            {
+                XrayData=p.XrayData  ;
+                 a_listElement=p.a_listElement ;
+                return true;
+            }
+            else
+            {
+                XrayData = p.XrayData;
+                a_listElement = p.a_listElement;
+                return false;
+            }
+        }
+
+        public bool XrayPointCollectiong(double dMilliSecondsTime, int x, int y, out long[] XrayData, out Dictionary<string, double> a_listElement)
+        {
+            currentCommand.pointXrayPrm = new PointXrayParam();
+            var p = currentCommand.pointXrayPrm;
+            p.dMilliSecondsTime = dMilliSecondsTime;
+            p.x = x;
+            p.y = y;
+          
+            currentCommand.commandType = OxfordCommand.XrayPointCollectiong;
+            startEvent.Set();
+            while (true)
+            {
+                if (endEvent.WaitOne(0, false))
+                {
+                    break;
+                }
+            }
+            if (currentCommand.returnType == true)
+            {
+                XrayData=p.XrayData  ;
+                a_listElement=p.listElement  ;
+                return true;
+            }
+            else
+            {
+                XrayData = p.XrayData;
+                a_listElement = p.listElement;
+                return false;
+            }
+        }
+    }
     public class Extender : IExtenderControl
     {
-        //构造函数
-        public Extender()
+       
+        
+    //构造函数
+    public Extender()
         {
             InitMicroscopeController();
             InitImageAcquisition();
@@ -739,6 +1196,7 @@ namespace Extender
 
             try
             {
+                int lastingTime = 0;
                 IEnumerable<IElectronImage> images = imageAcquisitionController.StartAcquisition(imageAcquisitionSettings);
                 images.ToList().ForEach(i =>
                 {
@@ -773,6 +1231,14 @@ namespace Extender
                         }
                         break;
                     }
+                    Application.DoEvents();
+
+                    Thread.Sleep(100);
+                    lastingTime += 100;
+                    if (lastingTime > EDSColletionTimeOut*3)
+                    {
+                        return false;
+                    }
                 }
             }
             catch (InvalidSettingsException settingsException)
@@ -898,6 +1364,7 @@ namespace Extender
         private int XRayChannelLength = 2000;
         private long[] m_XrayData = null;
         private bool m_bXrayDone = false;
+        private int EDSColletionTimeOut=5000;
         /// <summary>
         /// List of EdSpectrum objects
         /// </summary>
@@ -1152,6 +1619,7 @@ namespace Extender
                 // Start spectrum acquisition
                 try
                 {
+                    int lastingTime = 0;
                     IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
                     edSpectrum.Label = string.Format(@"Point({0},{1})",x,y);
                     Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 8");
@@ -1162,9 +1630,18 @@ namespace Extender
                         {
                             XrayData = m_XrayData;
                             a_listElement =listElement;
-
+                            
                             break;
                         }
+                        Application.DoEvents();
+
+                        Thread.Sleep(100);                       
+                        lastingTime += 100;
+                        if (lastingTime > EDSColletionTimeOut)
+                        {
+                            EdSpectrumAcquisitionController.EndMultipleAcquisition();
+                            return false;
+                        }
                     }
                 }
                 catch (InvalidSettingsException invalidSettingsException)
@@ -1217,6 +1694,7 @@ namespace Extender
                 // Start spectrum acquisition
                 try
                 {
+                    int lastingTime = 0;
                     IEdSpectrum edSpectrum = EdSpectrumAcquisitionController.StartAcquisition(EdSpectrumSettings);
                     edSpectrum.Label = string.Format(@"chord");
 
@@ -1228,6 +1706,15 @@ namespace Extender
                             a_listElement = listElement;
                             break;
                         }
+                   
+                        Thread.Sleep(100);
+                        Application.DoEvents();
+                        lastingTime += 100;
+                        if (lastingTime > EDSColletionTimeOut)
+                        {
+                            EdSpectrumAcquisitionController.EndMultipleAcquisition();
+                            return false;
+                        }
                     }
                 }
                 catch (InvalidSettingsException invalidSettingsException)

+ 1 - 1
ExtenderControl/ExtenderInterface.cs

@@ -33,7 +33,7 @@ namespace Extender
         }
 
         //其他使用的成员变量
-        private readonly IExtenderControl m_iExtender = new Extender(); //成员变量
+        private readonly IExtenderControl m_iExtender = new ExtenderWrapper(); //成员变量
 
         public IExtenderControl IExtender
         {