Browse Source

增加FIB自动对焦,SEM的消像散功能

HaoShuang 4 years ago
parent
commit
6efc5704ad

+ 23 - 1
HOZProject/App.config

@@ -59,12 +59,34 @@
       <!--远程算法地址-->
       <add key="WebServerUrl" value="FIB_degree_recognize,FIB_cal_cut_location,FIB_verify,FIB_cut_center_location,test5,test6,FIB_degree_recognize_trap,test8,test9"/>
 
-      <!--调节上限-->
+      <!--聚焦调节-->
       <add key="Focus_UP" value="3000"/>
       <add key="Focus_Down" value="4000"/>
       <add key="Focus_Step" value="1000"/>
       <add key="Focus_Range" value="50"/>
       <add key="Focus_FStep" value="50"/>
+
+      <!--FIB聚焦调节-->
+      <add key="FIB_UP" value="300"/>
+      <add key="FIB_Down" value="300"/>
+      <add key="FIB_Step" value="100"/>
+      <add key="FIB_Range" value="150"/>
+      <add key="FIB_FStep" value="50"/>
+
+      <!--StigX调节-->
+      <add key="StigX_UP" value="-1000"/>
+      <add key="StigX_Down" value="1000"/>
+      <add key="StigX_Step" value="1000"/>
+      <add key="StigX_Range" value="1000"/>
+      <add key="StigX_FStep" value="50"/>
+
+      <!--StigY调节-->
+      <add key="StigY_UP" value="-1000"/>
+      <add key="StigY_Down" value="1000"/>
+      <add key="StigY_Step" value="1000"/>
+      <add key="StigY_Range" value="1000"/>
+      <add key="StigY_FStep" value="50"/>
+      
       <!--距离、矩阵-->
       <add key="distance" value="30"/>
       <add key="rag" value="4"/>

+ 19 - 0
HOZProject/FormHOZMain.cs

@@ -92,6 +92,25 @@ namespace HOZProject
                 m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
                 m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
 
+                m_MeasureFile.MParam.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+                m_MeasureFile.MParam.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+                m_MeasureFile.MParam.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+                m_MeasureFile.MParam.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+                m_MeasureFile.MParam.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+                m_MeasureFile.MParam.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+                m_MeasureFile.MParam.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+                m_MeasureFile.MParam.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+                m_MeasureFile.MParam.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+                m_MeasureFile.MParam.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+                m_MeasureFile.MParam.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+                m_MeasureFile.MParam.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+                m_MeasureFile.MParam.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+                m_MeasureFile.MParam.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+                m_MeasureFile.MParam.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+
                 m_Ms.X_Min = Convert.ToSingle(ConfigurationManager.AppSettings["X_Min"]);
                 m_Ms.X_Max = Convert.ToSingle(ConfigurationManager.AppSettings["X_Max"]);
                 m_Ms.Y_Min = Convert.ToSingle(ConfigurationManager.AppSettings["Y_Min"]);

+ 25 - 0
HOZProject/UserControls/UControl_Init.cs

@@ -812,6 +812,31 @@ namespace HOZProject
 
             cfm.Firm = config.AppSettings.Settings["Firms"].Value;
 
+            cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+            cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+            cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+            cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+            cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+            cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+            cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+            cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+            cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+            cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+            cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+            cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+            cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+            cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+            cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+            cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
+            cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
+            cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
+            cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
+            cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
+
+
             return cfm;
         }
 

+ 32 - 1
MeasureData/FocusParam.cs

@@ -59,6 +59,21 @@ namespace MeasureData
             get { return this.m_ffStep; }
             set { this.m_ffStep = value; }
         }
+        //调试控制量
+        //enum WorkType
+        //{
+        //    AutoFocus = 1, //SEM自动对焦
+        //    AutoStigx = 2, //SEM自动消像散x
+        //    AutoStigy = 3, //SEM自动消像散y
+        //    AutoFIBFocus = 4, //FIB自动对焦
+        //    AllThing = 5
+        //};
+        private int m_nType;
+        public int TYPE
+        {
+            get { return this.m_nType; }
+            set { this.m_nType = value; }
+        }
         #endregion
 
         public FocusParam()
@@ -73,6 +88,7 @@ namespace MeasureData
             this.Step = 0;
             this.Range = 0;
             this.fStep = 0;
+            this.TYPE = 1;
         }
 
         //XML文件保存测量参数
@@ -85,6 +101,21 @@ namespace MeasureData
             xDouble dStep = new xDouble();
             xDouble dRange = new xDouble();
             xDouble dfStep = new xDouble();
+            xInt nType = new xInt();
+
+            dUp.AssignValue(this.UP);
+            dDown.AssignValue(this.Down);
+            dStep.AssignValue(this.Step);
+            dRange.AssignValue(this.Range);
+            dfStep.AssignValue(this.fStep);
+            nType.AssignValue(this.TYPE);
+
+            slo_fcsparam.Register("UP", dUp);
+            slo_fcsparam.Register("Down", dDown);
+            slo_fcsparam.Register("Step", dStep);
+            slo_fcsparam.Register("Range", dRange);
+            slo_fcsparam.Register("fStep", dfStep);
+            slo_fcsparam.Register("Type", nType);
 
             if (isStoring)
             {
@@ -99,7 +130,7 @@ namespace MeasureData
                 this.Step = (float)dStep.value();
                 this.Range = (float)dRange.value();
                 this.fStep = (float)dfStep.value();
-
+                this.TYPE = (int)nType.value();
             }
         }
     }

+ 36 - 1
MeasureData/MeasureParam.cs

@@ -131,7 +131,7 @@ namespace MeasureData
             set { this.firm = value; }
         }
 
-        //对焦参数
+        //对焦参数, SEM
         private FocusParam focusP;
         public FocusParam AutoFocus
         {
@@ -139,6 +139,30 @@ namespace MeasureData
             set { this.focusP = value; }
         }
 
+        //对焦参数, FIB
+        private FocusParam focusF;
+        public FocusParam FIBFocus
+        {
+            get { return this.focusF; }
+            set { this.focusF = value; }
+        }
+
+        //消像散x参数
+        private FocusParam StigX;
+        public FocusParam AutoStigX
+        {
+            get { return this.StigX; }
+            set { this.StigX = value; }
+        }
+
+        //消像散Y参数
+        private FocusParam StigY;
+        public FocusParam AutoStigY
+        {
+            get { return this.StigY; }
+            set { this.StigY = value; }
+        }
+
         //能谱参数
 
         #endregion
@@ -157,6 +181,14 @@ namespace MeasureData
             this.PTTemp = @"";
             this.FocusMode = 2;
             this.AutoFocus = new FocusParam();
+            this.AutoFocus.TYPE = 1;
+            this.AutoStigX = new FocusParam();
+            this.AutoStigX.TYPE = 2;
+            this.AutoStigY = new FocusParam();
+            this.AutoStigY.TYPE = 3;
+            this.FIBFocus = new FocusParam();
+            this.FIBFocus.TYPE = 4;
+
         }
 
         //XML文件保存测量参数
@@ -220,6 +252,9 @@ namespace MeasureData
 
             //对焦参数
             sFile.Register("Focus_Param", this.focusP);
+            sFile.Register("FIBFocus_Param", this.FIBFocus);
+            sFile.Register("StigX_Param", this.AutoStigX);
+            sFile.Register("StigY_Param", this.AutoStigY);
 
             if (isStoring)
             {

+ 706 - 31
MeasureThread/Measure.cs

@@ -463,6 +463,9 @@ namespace MeasureThread
         public Boolean key_stop = false;
 
         String focus_path = "";
+        String FIBfocus_path = "";
+        String StigX_path = "";
+        String StigY_path = "";
         String data_path = "";
 
         int m_nWorkHoleNo = -1;
@@ -628,8 +631,29 @@ namespace MeasureThread
                 {
                     Directory.CreateDirectory(focus_path);
                 }
+                //FIB对焦数据存放目录
+                FIBfocus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\FIBFocus";
+                m_MsParam.FIBFocus.Path = FIBfocus_path;
+                if (!Directory.Exists(focus_path))
+                {
+                    Directory.CreateDirectory(focus_path);
+                }
+                //StigX数据存放目录
+                StigX_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigX";
+                m_MsParam.AutoStigX.Path = StigX_path;
+                if (!Directory.Exists(focus_path))
+                {
+                    Directory.CreateDirectory(focus_path);
+                }
+                //StigY数据存放目录
+                StigY_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigY";
+                m_MsParam.AutoStigY.Path = StigY_path;
+                if (!Directory.Exists(focus_path))
+                {
+                    Directory.CreateDirectory(focus_path);
+                }
                 //判断孔状态
-                if(m_cutHoles[i].STATE != State.Ready)
+                if (m_cutHoles[i].STATE != State.Ready)
                 {
                     continue;
                 }
@@ -955,6 +979,203 @@ namespace MeasureThread
             return true;
         }
 
+        //执行自动消像散
+        public bool ImageStig(String step_code)
+        {
+            if (m_measureFile.MParam.FocusMode == 1)//手动
+            {
+                if (DialogResult.Yes == MessageBox.Show("图像自动消像散已完成?", "确认消息", MessageBoxButtons.YesNo))
+                {
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            else if (m_measureFile.MParam.FocusMode == 2)//自有自动
+            {
+                //郝工增加自动对焦算法
+                //处理文件夹
+                if (Directory.Exists(StigX_path))
+                {
+                    Directory.Delete(StigX_path, true);
+                }
+                Thread.Sleep(3000);
+                arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
+                Thread.Sleep(1000);
+                arg.Picture_Information.Magnification = iSEM.GetMagnification();
+                Thread.Sleep(1000);
+
+                //再创建文件夹
+                Directory.CreateDirectory(StigX_path);
+
+                //1、对焦参数类,2、输出像散值
+                int stigX = 0;
+
+                //根据当前的stigX重新计算像散值
+                float currentStigX = iSEM.GetAstigmatismX();
+                m_MsParam.AutoStigX.Step = 10; //像散的步长为10
+                m_MsParam.AutoStigX.UP = currentStigX - m_MsParam.AutoStigX.Step;
+                m_MsParam.AutoStigX.Down = currentStigX + m_MsParam.AutoStigX.Step;
+
+                LogManager.AddHardwareLog("修改消像散参数", true);
+                AutoStig(m_MsParam.AutoStigX, out stigX, step_code);
+
+                //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
+                //设置工作距离
+                iSEM.SetAstigmatismX((float)(stigX * 0.01));
+                //设置完工作距离后必须延迟5秒
+                Thread.Sleep(5000);
+                //处理图片位置
+                //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
+
+                //处理文件夹
+                if (Directory.Exists(StigY_path))
+                {
+                    Directory.Delete(StigY_path, true);
+                }
+                Thread.Sleep(3000);
+                arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
+                Thread.Sleep(1000);
+                arg.Picture_Information.Magnification = iSEM.GetMagnification();
+                Thread.Sleep(1000);
+
+                //再创建文件夹
+                Directory.CreateDirectory(StigY_path);
+
+                //1、对焦参数类,2、输出像散值
+                int stigY = 0;
+
+                //根据当前的stigX重新计算像散值
+                float currentStigY = iSEM.GetAstigmatismY();
+                m_MsParam.AutoStigY.Step = 10; //像散的步长为10
+                m_MsParam.AutoStigY.UP = currentStigY - m_MsParam.AutoStigY.Step;
+                m_MsParam.AutoStigY.Down = currentStigY + m_MsParam.AutoStigY.Step;
+
+                LogManager.AddHardwareLog("修改消像散参数", true);
+                AutoStig(m_MsParam.AutoStigY, out stigY, step_code);
+
+                //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
+                //设置工作距离
+                iSEM.SetAstigmatismY((float)(stigY * 0.01));
+                //设置完工作距离后必须延迟5秒
+                Thread.Sleep(5000);
+            }
+            else if (m_MsParam.FocusMode == 3)     //客户自动
+            {
+                //后期和客户对接接口
+                List<string> filenames = new List<string>();
+                String retfilename = wr.Img_Auto_Focus(filenames);
+            }
+            else        //蔡司自动对焦
+            {
+                iSEM.CmdAutoFocusCoarse();
+                while (true)
+                {
+                    Thread.Sleep(10000);
+
+                    if (0 == iSEM.GetAutoFunction())
+                    {
+                        break;
+                    }
+                }
+                iSEM.CmdAutoFocusFine();
+                while (true)
+                {
+                    Thread.Sleep(10000);
+
+                    if (0 == iSEM.GetAutoFunction())
+                    {
+                        break;
+                    }
+                }
+            }
+            return true;
+        }
+
+
+        //执行FIB自动对焦,FIBFocus
+        //执行自动消像散
+        public bool FIBFocus(String step_code)
+        {
+            if (m_measureFile.MParam.FocusMode == 1)//手动
+            {
+                if (DialogResult.Yes == MessageBox.Show("FIB图像对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
+                {
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            else if (m_measureFile.MParam.FocusMode == 2)//自有自动
+            {
+                //郝工增加自动对焦算法
+                //处理文件夹
+                if (Directory.Exists(FIBfocus_path))
+                {
+                    Directory.Delete(FIBfocus_path, true);
+                }
+                Thread.Sleep(3000);
+                arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
+                Thread.Sleep(1000);
+                arg.Picture_Information.Magnification = iSEM.GetMagnification();
+                Thread.Sleep(1000);
+
+                //再创建文件夹
+                Directory.CreateDirectory(FIBfocus_path);
+
+                //1、对焦参数类,2、输出对焦值
+                int FIBFocus = 0;
+
+                //根据当前的stigX重新计算像散值
+                float currentFIBFocus = iSEM.GetFIBObjectivePotential();
+                m_MsParam.FIBFocus.Step = 10; //像散的步长为10
+                m_MsParam.FIBFocus.UP = currentFIBFocus - m_MsParam.FIBFocus.Step;
+                m_MsParam.FIBFocus.Down = currentFIBFocus + m_MsParam.FIBFocus.Step;
+
+                LogManager.AddHardwareLog("修改FIB自动对焦参数", true);
+                AutoFIBFocus(m_MsParam.FIBFocus, out FIBFocus, step_code);
+
+                //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
+                //设置工作距离
+                iSEM.SetFIBObjectivePotential((float)(FIBFocus * 0.01));
+                //设置完工作距离后必须延迟5秒
+                Thread.Sleep(5000);
+                //处理图片位置
+                //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);               
+            }
+            else if (m_MsParam.FocusMode == 3)     //客户自动
+            {
+                //后期和客户对接接口
+                List<string> filenames = new List<string>();
+                String retfilename = wr.Img_Auto_Focus(filenames);
+            }
+            else        //蔡司自动对焦
+            {
+                iSEM.CmdAutoFocusCoarse();
+                while (true)
+                {
+                    Thread.Sleep(10000);
+
+                    if (0 == iSEM.GetAutoFunction())
+                    {
+                        break;
+                    }
+                }
+                iSEM.CmdAutoFocusFine();
+                while (true)
+                {
+                    Thread.Sleep(10000);
+
+                    if (0 == iSEM.GetAutoFunction())
+                    {
+                        break;
+                    }
+                }
+            }
+            return true;
+        }
         /// <summary>
         ///13. 自动 定位功能,沉积
         /// </summary>
@@ -1009,6 +1230,24 @@ namespace MeasureThread
                 return false;
             }
 
+            //1.1大于10000倍进行消像散处理
+            float dMag = iSEM.GetMagnification();
+            if (dMag > 10000)//需要消像散
+            {
+                if (!ImageStig("1-3"))
+                {
+                    LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
+                    arg.Message = "拉直操作自动消像散失败!";
+                    arg.State = false;
+                    SendMsg("1-3");
+                    return false;
+                }
+                arg.Message = "拉直操作自动消像散成功!";
+                arg.State = true;
+                SendMsg("1-3");
+            }
+
+
             //3.控制SEM拍照,找到切割位置
             String fileName1 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Location_Magnification.ToString("0") + "_" + ImageName1;
             arg.Picture_Information.Picture_FullPath = fileName1;
@@ -1060,8 +1299,7 @@ namespace MeasureThread
                 if (key_stop)
                 {
                     return false;
-                }
-
+                }              
                 //8.控制FIB拍照
                 //9.保存照片======更改路径
                 String fileName2 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString("0") + "_" + ImageName2;
@@ -1091,6 +1329,28 @@ namespace MeasureThread
                 cycle_time = iSEM.GetCycleTime();
                 Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
 
+                //增加FIB对焦
+                //2.控制SEM自动对焦、亮度、对比度
+                if (FIBFocus("1-8"))
+                {
+                    arg.Message = "自动FIB对焦完成";
+                    arg.State = true;
+                    SendMsg("1-8");
+                }
+                else
+                {
+                    LogManager.AddHardwareLog("设置观测点后,自动FIB对焦失败。", true);
+                    arg.Message = "自动FIB对焦失败";
+                    arg.State = false;
+                    SendMsg("1-8");
+                }
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+
+
                 if (!GetImage(ImageMode.FIB, fileName2))
                 {
                     arg.Message = "FIB拍照失败";
@@ -1292,6 +1552,27 @@ namespace MeasureThread
             }
             Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
 
+            //增加FIB对焦
+            if (FIBFocus("1-8"))
+            {
+                arg.Message = "FIB自动对焦完成";
+                arg.State = true;
+                SendMsg("1-8");
+            }
+            else
+            {
+                LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
+                arg.Message = "自动对焦失败";
+                arg.State = false;
+                SendMsg("1-8");
+            }
+            //判断是否停止进程
+            if (key_stop)
+            {
+                return false;
+            }
+
+
             String fileName31 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName31;
             arg.Picture_Information.Picture_FullPath = fileName31;
             arg.Picture_Information.Work_Status = "FIB";
@@ -1653,6 +1934,23 @@ namespace MeasureThread
                 return false;
             }
 
+            //1.1大于10000倍进行消像散处理
+            float dMag = iSEM.GetMagnification();
+            if (dMag > 10000)//需要消像散
+            {
+                if (!ImageStig("1-3"))
+                {
+                    LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
+                    arg.Message = "拉直操作自动消像散失败!";
+                    arg.State = false;
+                    SendMsg("1-3");
+                    return false;
+                }
+                arg.Message = "拉直操作自动消像散成功!";
+                arg.State = true;
+                SendMsg("1-3");
+            }
+
             //3、设置SEM补偿角度
             if (m_MsParam.Is_Photograph == false)
             {
@@ -1759,24 +2057,41 @@ namespace MeasureThread
                     return false;
                 }
 
-                ////11、自动对焦。与之前操作相同
-                //if (ImageFocus("1-28"))
-                //{
-                //    arg.Message = "自动对焦完成";
-                //    arg.State = true;
-                //    SendMsg("1-28");
-                //}
-                //else
-                //{
-                //    arg.Message = "自动对焦失败";
-                //    arg.State = false;
-                //    SendMsg("1-28");
-                //}
-                ////判断是否停止进程
-                //if (key_stop)
-                //{
-                //    return false;
-                //}
+                //11、自动对焦。与之前操作相同
+                if (ImageFocus("1-28"))
+                {
+                    arg.Message = "自动对焦完成";
+                    arg.State = true;
+                    SendMsg("1-28");
+                }
+                else
+                {
+                    arg.Message = "自动对焦失败";
+                    arg.State = false;
+                    SendMsg("1-28");
+                }
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+
+                //1.1大于10000倍进行消像散处理
+                dMag = iSEM.GetMagnification();
+                if (dMag > 10000)//需要消像散
+                {
+                    if (!ImageStig("1-3"))
+                    {
+                        LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
+                        arg.Message = "拉直操作自动消像散失败!";
+                        arg.State = false;
+                        SendMsg("1-3");
+                        return false;
+                    }
+                    arg.Message = "拉直操作自动消像散成功!";
+                    arg.State = true;
+                    SendMsg("1-3");
+                }
 
                 //12拍照
                 String fileName6 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName6;
@@ -2454,17 +2769,40 @@ namespace MeasureThread
             arg.State = true;
             SendMsg("1-3");
 
-            //2、拍张照片
-            String fileName0 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Stretch_Magnification.ToString("0") + "_" + ImageName0;
-            //拍照前改变速度,延时
-            iSEM.CmdSaveRate();
-            cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
-            if (!GetImage(ImageMode.SEM, fileName0))
+            //判断是否停止进程
+            if (key_stop)
             {
-                arg.Message = "拉直拍照成功";
-                arg.State = false;
-                SendMsg("1-4");
+                return false;
+            }
+
+            //1.1大于10000倍进行消像散处理
+            float dMag = iSEM.GetMagnification();
+            if (dMag > 10000)//需要消像散
+            {
+                if (!ImageStig("1-3"))
+                {
+                    LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
+                    arg.Message = "拉直操作自动消像散失败!";
+                    arg.State = false;
+                    SendMsg("1-3");
+                    return false;
+                }
+                arg.Message = "拉直操作自动消像散成功!";
+                arg.State = true;
+                SendMsg("1-3");
+            }
+
+            //2、拍张照片
+            String fileName0 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Stretch_Magnification.ToString("0") + "_" + ImageName0;
+            //拍照前改变速度,延时
+            iSEM.CmdSaveRate();
+            cycle_time = iSEM.GetCycleTime();
+            Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+            if (!GetImage(ImageMode.SEM, fileName0))
+            {
+                arg.Message = "拉直拍照成功";
+                arg.State = false;
+                SendMsg("1-4");
                 return false;
             }
             arg.Message = "拉直拍照成功!";
@@ -2720,6 +3058,343 @@ namespace MeasureThread
 
         }
 
+        //自动消像散 AutoStig
+        public bool AutoStig(FocusParam a_param, out int a_nWd, String step_code)
+        {
+            a_nWd = 0;
+            float wd = 0;
+            if (a_param.TYPE == 2)
+            {
+                wd = iSEM.GetAstigmatismX();
+            }
+            else if (a_param.TYPE == 3)
+            {
+                wd = iSEM.GetAstigmatismY();
+            }
+            else
+            {
+                LogManager.AddHardwareLog("自动消像散参数设置有误", true);
+                return false;
+            }
+            
+            a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
+
+            if (a_param == null)
+            {
+                LogManager.AddHardwareLog("空参数", true);
+                return false;
+            }
+
+            string path = a_param.Path;
+            if (!Directory.Exists(path))
+            {
+                LogManager.AddHardwareLog("文件夹丢失", true);
+                return false;
+            }
+            string path_coarse = a_param.Path + "\\Coarse";
+            if (!Directory.Exists(path_coarse))
+            {
+                Directory.CreateDirectory(path_coarse);
+            }
+            string path_fine = a_param.Path + "\\Fine";
+            if (!Directory.Exists(path_fine))
+            {
+                Directory.CreateDirectory(path_fine);
+            }
+
+
+            //1. 拍照
+            //1.1, 粗拍照
+            //1.1.1, 根据参数计算拍照次数
+            double nUp = a_param.UP * 100.0;
+            double nDown = a_param.Down * 100.0;
+            double nStep = a_param.Step * 100.0;
+            double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
+            LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
+            //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
+
+            //粗拍照
+            for (int i = 0; i < nTimes; i++)
+            {
+
+                int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
+
+                if (a_param.TYPE == 2)
+                {
+                    iSEM.SetAstigmatismX((float)(cWd * 0.01));
+                }
+                else if (a_param.TYPE == 3)
+                {
+                    iSEM.SetAstigmatismY((float)(cWd * 0.01));
+                }
+                else
+                {
+                    LogManager.AddHardwareLog("自动消像散参数设置有误", true);
+                    return false;
+                }
+
+                //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
+                Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+
+                int swd = cWd / 100;
+                //SendMsg("wd = " + swd.ToString() +"um");
+
+                String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
+                arg.Picture_Information.Picture_FullPath = fileName;
+                if (!GetImage(ImageMode.SEM, fileName))
+                {
+                    return false;
+                }
+                arg.State = true;
+                arg.Message = "自动对焦";
+                SendMsg(step_code);
+
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+                //Thread.Sleep(3000);
+            }
+
+            //1.2, 选定细拍照的工作距离
+            int CorWd;
+            ChooseBest(path_coarse, out CorWd);
+
+            a_nWd = CorWd;
+
+            //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
+
+
+            //1.3, 细拍照
+            if ((CorWd - a_param.Range * 100.0) <= -10000)
+            {
+                return false;
+            }
+
+            double nfUp = CorWd - a_param.Range * 100.0;
+            double nfStep = a_param.fStep * 100.0;
+            double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
+
+
+            //SendMsg("粗对焦:最小值" + nfUp.ToString()  + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
+
+
+            for (int i = 0; i < nfTimes; i++)
+            {
+                int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
+                if (a_param.TYPE == 2)
+                {
+                    iSEM.SetAstigmatismX((float)(cWd * 0.01));
+                }
+                else if (a_param.TYPE == 3)
+                {
+                    iSEM.SetAstigmatismY((float)(cWd * 0.01));
+                }
+                else
+                {
+                    LogManager.AddHardwareLog("自动消像散参数设置有误", true);
+                    return false;
+                }
+                //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
+                Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+
+                int swd = cWd / 100;
+                //SendMsg("wd = " + swd.ToString() + "um");
+
+                String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
+                arg.Picture_Information.Picture_FullPath = fileName;
+                if (!GetImage(ImageMode.SEM, fileName))
+                {
+                    return false;
+                }
+                arg.State = true;
+                arg.Message = "自动对焦";
+                SendMsg(step_code);
+
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+                //Thread.Sleep(2000);
+            }
+
+            int fineWd;
+            ChooseBest(path_fine, out fineWd);
+
+            //SendMsg("wd fine max = " + fineWd.ToString());
+
+            a_nWd = fineWd;
+
+            //SendMsg("细选工作距离wd = " + a_nWd.ToString());
+
+            return true;
+
+        }
+
+        //自动FIB对焦        AutoFIBFocus
+        public bool AutoFIBFocus(FocusParam a_param, out int a_nWd, String step_code)
+        {
+            a_nWd = 0;
+            float wd = 0;
+            if (a_param.TYPE == 4)
+            {
+                wd = iSEM.GetFIBObjectivePotential();
+            }
+            else
+            {
+                LogManager.AddHardwareLog("FIB自动聚焦参数设置有误", true);
+                return false;
+            }
+
+            a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
+
+            if (a_param == null)
+            {
+                LogManager.AddHardwareLog("空参数", true);
+                return false;
+            }
+
+            string path = a_param.Path;
+            if (!Directory.Exists(path))
+            {
+                LogManager.AddHardwareLog("文件夹丢失", true);
+                return false;
+            }
+            string path_coarse = a_param.Path + "\\Coarse";
+            if (!Directory.Exists(path_coarse))
+            {
+                Directory.CreateDirectory(path_coarse);
+            }
+            string path_fine = a_param.Path + "\\Fine";
+            if (!Directory.Exists(path_fine))
+            {
+                Directory.CreateDirectory(path_fine);
+            }
+
+
+            //1. 拍照
+            //1.1, 粗拍照
+            //1.1.1, 根据参数计算拍照次数
+            double nUp = a_param.UP * 100.0;
+            double nDown = a_param.Down * 100.0;
+            double nStep = a_param.Step * 100.0;
+            double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
+            LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
+            //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
+
+            //粗拍照
+            for (int i = 0; i < nTimes; i++)
+            {
+
+                int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
+
+                if (a_param.TYPE == 4)
+                {
+                    iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
+                }
+                else
+                {
+                    LogManager.AddHardwareLog("自动消像散参数设置有误", true);
+                    return false;
+                }
+
+                //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
+                Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+
+                int swd = cWd / 100;
+                //SendMsg("wd = " + swd.ToString() +"um");
+
+                String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
+                arg.Picture_Information.Picture_FullPath = fileName;
+                if (!GetImage(ImageMode.SEM, fileName))
+                {
+                    return false;
+                }
+                arg.State = true;
+                arg.Message = "自动对焦";
+                SendMsg(step_code);
+
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+                //Thread.Sleep(3000);
+            }
+
+            //1.2, 选定细拍照的工作距离
+            int CorWd;
+            ChooseBest(path_coarse, out CorWd);
+
+            a_nWd = CorWd;
+
+            //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
+
+
+            //1.3, 细拍照
+            if ((CorWd - a_param.Range * 100.0) <0)
+            {
+                return false;
+            }
+
+            double nfUp = CorWd - a_param.Range * 100.0;
+            double nfStep = a_param.fStep * 100.0;
+            double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
+
+
+            //SendMsg("粗对焦:最小值" + nfUp.ToString()  + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
+
+
+            for (int i = 0; i < nfTimes; i++)
+            {
+                int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
+                if (a_param.TYPE == 4)
+                {
+                    iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
+                }
+                else
+                {
+                    LogManager.AddHardwareLog("自动消像散参数设置有误", true);
+                    return false;
+                }
+                //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
+                Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+
+                int swd = cWd / 100;
+                //SendMsg("wd = " + swd.ToString() + "um");
+
+                String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
+                arg.Picture_Information.Picture_FullPath = fileName;
+                if (!GetImage(ImageMode.SEM, fileName))
+                {
+                    return false;
+                }
+                arg.State = true;
+                arg.Message = "自动对焦";
+                SendMsg(step_code);
+
+                //判断是否停止进程
+                if (key_stop)
+                {
+                    return false;
+                }
+                //Thread.Sleep(2000);
+            }
+
+            int fineWd;
+            ChooseBest(path_fine, out fineWd);
+
+            //SendMsg("wd fine max = " + fineWd.ToString());
+
+            a_nWd = fineWd;
+
+            //SendMsg("细选工作距离wd = " + a_nWd.ToString());
+
+            return true;
+
+        }
         //LoG算子计算
         private double LoGMean(string a_strImgPath)
         {