| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666 | //时间:20200610//作者:郝爽//功能:测量线程using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Threading;using System.IO;using SmartSEMControl;using MeasureData;using FileManager;using WebManager;namespace MeasureThread{    //图片模式    public enum ImageMode    {        FIB,        SEM    }    public delegate void ThreadStatusHandler(object sender, ThreadStatusEventArgs e);  //声明委托    public delegate void CutHolesStatusHandler(object sender, CutHolesStatusEventArgs e);    public class ThreadStatusEventArgs    {        //状态        public string State        {            get { return m_state; }            set { m_state = value; }        }        private string m_state;        //时间        public DateTime Time        {            get { return m_time; }            set { m_time = value; }        }        private DateTime m_time;        //步骤代码        public String Step_Code        {            get { return step_Code; }            set { step_Code = value; }        }        private String step_Code;        //其他消息        public String Message        {            get { return this.message; }            set { this.message = value; }        }        private String message;        //孔名        public String HoleName        {            get { return this.holeName; }            set { this.holeName = value; }        }        private String holeName;        //图片信息        public class PictureInformation        {            public String Picture_FullPath            {                get { return picture_FullPath; }                set { picture_FullPath = value; }            }            private String picture_FullPath;            public double Work_Voltage            {                get { return work_Voltage; }                set { work_Voltage = value; }            }            private double work_Voltage;            public double Magnification            {                get { return magnification; }                set { magnification = value; }            }            private double magnification;            public double Work_Distance            {                get { return work_Distance; }                set { work_Distance = value; }            }            private double work_Distance;            public String Work_Status            {                get { return work_Status; }                set { work_Status = value; }            }            private String work_Status;        }        //图片信息实例类        public PictureInformation Picture_Information        {            get { return picture_Information; }            set { picture_Information = value; }        }        private PictureInformation picture_Information;        //图像信息        public class ImageInformation        {            public int Method_Name            {                get { return method_Name; }                set { method_Name = value; }            }            private int method_Name;            public Source_Img_Degree_Direction SIDD;            public Cut_Position CP;            public Cut_Success CS;            public Trapezoid_Top_Center_Position TTCP;            public Auto_Foucs AF;            public Auto_Stigmatic AS;            public Center_Position_OffsetAngle_Direction CPOD;            public Measure_Size MS;            public ImageInformation()            {                SIDD = new Source_Img_Degree_Direction();                CP = new Cut_Position();                CS = new Cut_Success();                TTCP = new Trapezoid_Top_Center_Position();                AF = new Auto_Foucs();                AS = new Auto_Stigmatic();                CPOD = new Center_Position_OffsetAngle_Direction();                MS = new Measure_Size();            }            //1-计算原始图像偏移角度及方向            public class Source_Img_Degree_Direction            {                public Boolean Is_Image = false;                public double Degree                {                    get { return degree; }                    set { degree = value; }                }                private double degree;                public int Direction                {                    get { return direction; }                    set { direction = value; }                }                private int direction;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }            //2-计算切割点位置            public class Cut_Position            {                public Boolean Is_Image = false;                public double Offsetx                {                    get { return offsetx; }                    set { offsetx = value; }                }                private double offsetx;                public double Offsety                {                    get { return offsety; }                    set { offsety = value; }                }                private double offsety;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }            //3-是否切割成功            public class Cut_Success            {                public Boolean Is_Image = false;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }            //4-计算切割后图像梯形区域上边中心点坐标            public class Trapezoid_Top_Center_Position            {                public Boolean Is_Image = false;                public double TopCenterX                {                    get { return topCenterX; }                    set { topCenterX = value; }                }                private double topCenterX;                public double TopCenterY                {                    get { return topCenterY; }                    set { topCenterY = value; }                }                private double topCenterY;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }            //5-自动对焦            public class Auto_Foucs            {                public Boolean Is_Image = true;                public String Img_Path                {                    get { return img_Path; }                    set { img_Path = value; }                }                private String img_Path;            }            //6-自动像闪            public class Auto_Stigmatic            {                public Boolean Is_Image = true;                public String Img_Path                {                    get { return img_Path; }                    set { img_Path = value; }                }                private String img_Path;            }            //7-计算切割面区域中心坐标,以及偏移角度及方向            public class Center_Position_OffsetAngle_Direction            {                public Boolean Is_Image = false;                 public double CenterX                {                    get { return centerX; }                    set { centerX = value; }                }                private double centerX;                public double CenterY                {                    get { return centerY; }                    set { centerY = value; }                }                private double centerY;                public double Degree                {                    get { return degree; }                    set { degree = value; }                }                private double degree;                public int Direction                {                    get { return direction; }                    set { direction = value; }                }                private int direction;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }            //8-测量尺寸            public class Measure_Size            {                public Boolean Is_Image = false;                public int State                {                    get { return state; }                    set { state = value; }                }                private int state;            }        }        //图像信息实例类        public ImageInformation Image_Information        {            get { return image_Information; }            set { image_Information = value; }        }        private ImageInformation image_Information;        public ThreadStatusEventArgs(string a_State)        {            picture_Information = new PictureInformation();            image_Information = new ImageInformation();        }    }    public class CutHolesStatusEventArgs    {        public string State        {            get { return m_state; }            set { m_state = value; }        }        private string m_state;        public string HoleName        {            get { return m_holeName; }            set { m_holeName = value; }        }        private string m_holeName;        public CutHolesStatusEventArgs(string a_state, string a_holeName)        {            this.m_state = a_state;            this.m_holeName = a_holeName;        }    }    public class Measure    {        /// <summary>        /// 图像拉直算法        /// </summary>        /// <param name="Slope">倾斜角度</param>        /// <param name="x0">圆心坐标x</param>        /// <param name="y0">圆心坐标y</param>        /// <param name="x1">倾斜情况下帧图的坐标x</param>        /// <param name="y1">倾斜情况下帧图的坐标y</param>        /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>        /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>        /// <returns></returns>        public bool Straightening(double Slope, int x0, int y0, int x1, int y1, ref int Hx, ref int Hy)        {            try            {                double xr = x1 - x0;//倾斜图到中心的距离差x                double yr = y1 - y0;//倾斜图到中心的距离差y                double R = Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度                //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度                double k = Math.Atan(y1 / x1) / Math.PI * 180;//x1,y1的直角三角形圆心角度                double k_S = k - Slope;//通过夹角差求x2,y2                int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);                int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);                if (Slope > 0 || Slope < 0)                {                    Hx = x1 - x2;                    Hy = y1 - y2;                }                else                {                    Hx = 0;                    Hy = 0;                }                return true;            }            catch (Exception)            {                return false;            }        }        public WebResult wr = null;        public event ThreadStatusHandler SendThreadStatus;  // 声明事件        public event CutHolesStatusHandler SendCutHolesStatus;  // 声明事件        //定义一个全局的消息类        ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");        //全局只有一个fatorySEM        static FactoryHardware factorySEM = FactoryHardware.Instance;        ISEMControl iSEM = factorySEM.ISEM;        //@的作用是不用转义字符\\只打一个就行        const String ImageName1 = @"ImageSEM600X.tif"; //传给客户,作水平校正        const String ImageName2 = @"ImageFIB600X1.tif";//传给客户,找到切割点        const String ImageName3 = @"ImageFIB600X2.tif";        const String ImageName4 = @"ImageSEM300X.tif";//传给客户,找到已经切割点        const String ImageName5 = @"ImageSEM6000X.tif";//传给客户,水平校正        const String ImageName6 = @"ImageSEMMag.tif";//传给客户,测量层高        const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针        const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针        const String MacoScanPic = "Scan picture.MLF";//一般质量抓图的宏        const String MacoGoodPic = "Good picture.MLF";//高质量抓图的宏        const String MacoExportTif = "Export TIFF.MLF";// 导出有标尺的图像,这个图像为使用工具SmartSEM工具的图像        const String ElyDeposition = @"Deposition.ely"; //沉积        const String ElyCrossSection = @"CrossSection.ely"; //切割        const float fMin = (float)0.0000002; //单位是米        int m_nWorkHoleNo = -1;        //测量文件        private MeasureFile m_measureFile;        public MeasureFile MeasureFile        {            get { return this.m_measureFile; }            set { this.m_measureFile = value; }        }        //测量的切割孔        private List<MeasureData.CutHole> m_cutHoles;        public List<MeasureData.CutHole> cutHoles        {            get { return this.m_cutHoles; }            set { this.m_cutHoles = value; }        }        //工作文件夹        private string m_WorkingFolder;        public string WorkingFolder        {            get { return this.m_WorkingFolder; }            set { this.m_WorkingFolder = value; }        }        //程序当前路径        private string m_ProgramFolder = Directory.GetCurrentDirectory();        //线程状态        private ThreadStatus m_ThreadStatus;        public ThreadStatus TStatus        {            get { return this.m_ThreadStatus; }            set { this.m_ThreadStatus = value; }        }        //测量参数        private MeasureParam m_MsParam;        public MeasureParam MeasParam        {            get { return this.m_MsParam; }            set { this.m_MsParam = value; }        }        //构造函数        public Measure(String webServerIP, String webServerPort, String webServerUrl)        {            MeasParam = new MeasureParam();            TStatus = new ThreadStatus();            cutHoles = new List<MeasureData.CutHole>();            //配置远程连接            wr = new WebResult(webServerIP,webServerPort,webServerUrl);        }        //初始化测量业务, 读测量文件,判断是否有可测试的切孔        public bool InitMeas(MeasureFile a_measureFile)        {            m_measureFile = a_measureFile;            List<CutHole> listHoles = m_measureFile.ListCutHole;            foreach (CutHole h in listHoles)            {                if (h.SWITCH == true)                {                    m_cutHoles.Add(h);                }            }            if (m_cutHoles.Count == 0)                return false;            this.m_MsParam = m_measureFile.MParam;            return true;        }        public void SendMsg(string step_code)        {            arg.Step_Code = step_code;            arg.Time = DateTime.Now;            switch(step_code)            {                //拍照                case "1-3":                case "1-9":                case "1-16":                case "1-24":                    //电压、放大倍数、工作距离、位置信息、图片路径                    arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();                    arg.Picture_Information.Work_Status = "SEM";                    arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();                    arg.Picture_Information.Magnification = iSEM.GetMagnification();                    break;                case "1-10":                case "1-18":                    //获取偏移信息                    break;                case "1-12":                case "1-20":                    //验证移动准备性                    break;                case "1-26":                    //取消电子束校正并初始化                    break;                default:                    arg.State = "1";                    break;            }            SendThreadStatus(this, arg);        }        public void SendCutHoleMsg(string a_state, string a_holeName)        {            CutHolesStatusEventArgs arg = new CutHolesStatusEventArgs(a_state, a_holeName);            arg.HoleName = a_holeName;            arg.State = a_state;            SendCutHolesStatus(this, arg);        }        //测量流程        public void DoMeasure()        {            //创建线程的测量状态的更新            this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);            if (SendThreadStatus != null)            {                SendMsg("开始测量。");            }            //检查硬件连接是否正常            if (!ConnectHardware())            {                SendMsg("连接硬件失败。");                this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);                return;            }            SendMsg("硬件连接成功。");            //设置工作文件夹            if (!SetWorkingFolderStr())            {                SendMsg("设置工作文件夹失败");                this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);                return;            }            SendMsg("创建工作文件路径为" + WorkingFolder);            float[] firstPosition;            for (int i = 0; i < m_cutHoles.Count; i++)            {                m_nWorkHoleNo = i;                arg.HoleName = cutHoles[m_nWorkHoleNo].HoleName;                if (i == 0)                {                    SendMsg("第一个切孔开始测量");                    //切孔操作-开始                    SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);                    firstPosition = iSEM.GetStagePosition();                    //第一个孔的测试                    FirstHole();                    //切孔操作-完成                    SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);                }                else                {                    //非第一个孔的测试                    SendMsg("第" + i.ToString() + "个切孔开始测量");                    //切孔操作-开始                    SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);                    OtherHole();                    //切孔操作-完成                    SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);                }            }        }        //检查硬件连接是否正常        public bool ConnectHardware()        {            //返回硬件的连接状态            return iSEM.ConnectStatus();        }        //设置工作文件夹        public bool SetWorkingFolderStr()        {            WorkingFolder = m_measureFile.FilePath;            return true;        }        //插入PT针        public bool InsertPT()        {            string fn = m_ProgramFolder + "\\Macro\\" + MacoInsertPt;            SendMsg("调用宏插入PT针宏文件" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(1000);            return true;        }        //撤出PT针        public bool RetractPT()        {            string fn = m_ProgramFolder + "\\Macro\\" + MacoRetractPt;            SendMsg("调用宏撤出PT针宏文件" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(1000);            return true;        }        //PT沉积        public bool PTWork()        {            //执行PT沉积的ELY文件            string fn = m_ProgramFolder + "\\Macro\\" + ElyDeposition;            SendMsg("执行PT沉积Ely文件:" + fn);            if (!ExcuteEly(fn))            {                return false;            }            //等待沉积完成            while (true)            {                Thread.Sleep(10000);                if (iSEM.GetFIBMode() == 0)                {                    break;                }            }            return true;        }        //FIB切割        public bool FIBWork()        {            //执行PT沉积的ELY文件            string fn = m_ProgramFolder + "\\Macro\\" + ElyCrossSection;            SendMsg("执行FIB切割Ely文件:" + fn);            if (!ExcuteEly(fn))            {                return false;            }            //等待切割完成            while (true)            {                Thread.Sleep(10000);                if (iSEM.GetFIBMode() == 0)                {                    break;                }            }            return true;        }        public bool ExcuteEly(string a_filename)        {            //执行ELy文件有三个动作            //1. 选择ELY文件            SendMsg("选择ELY文件");            if (!iSEM.CmdFIBLoadELY(a_filename))            {                SendMsg("选择ELY文件失败");                return false;            }            Thread.Sleep(1000);            //2. 确认ELY文件            SendMsg("确认ELY文件");            if (!iSEM.CmdFIBEXPOSUREELY())            {                SendMsg("确认ELY文件失败");                return false;            }            Thread.Sleep(1000);            //3. 执行ELY文件            SendMsg("执行ELY文件");            if (!iSEM.CmdFIBSTARTELY())            {                SendMsg("执行ELY文件失败");                return false;            }            Thread.Sleep(1000);            return true;        }        /// <summary>        ///13. 自动 定位功能        /// </summary>        /// <returns></returns>        public bool GetPoistion(Boolean isFirst)        {            //SendMsg("自动定位");            //13.自动定位切割            {                //1.控制SEM放大600X                if (!iSEM.SetMagnification(m_measureFile.MParam.Photograph_Magnification))                {                    arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍失败";                    SendMsg("1-1");                    return false;                }                arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍成功";                SendMsg("1-1");                //2.控制SEM自动对焦、亮度、对比度                if (m_measureFile.MParam.FocusMode==1)//手动                {                    if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))                    {                        arg.Message = "自动对焦完成";                        SendMsg("1-2");                        //return true;                    }                    else                    {                        arg.Message = "自动对焦失败";                        SendMsg("1-2");                        return false;                    }                }                else if (m_measureFile.MParam.FocusMode == 2)//自有自动                {                    //郝工增加自动对焦算法                }                else     //客户自动                {                    //后期和客户对接接口                    List<string> filenames = new List<string>();                    String retfilename = wr.Img_Auto_Focus(filenames);                }                //3.第一次不需要进行角度补偿,其他需要设置SEM进行角度补偿54度                if (!isFirst)                {                    if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))                    {                        arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";                        SendMsg("1-15");                        return false;                    }                    arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";                    SendMsg("1-15");                    Thread.Sleep(5000);                }                //4.控制SEM拍照,5保存照片                String fileName1 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName1;                arg.Picture_Information.Picture_FullPath = fileName1;                if (!GetImage(ImageMode.SEM, fileName1))                {                    arg.Message = "SEM拍照失败";                    SendMsg("1-3");                    return false;                }                arg.Message = "SEM拍照成功";                SendMsg("1-3");                Thread.Sleep(3000);                                //6.设置FIB拍照参数——扫描时间、束流等                //7.控制FIB自动亮度、对比度                SendMsg("切换FIB控制");                if (!iSEM.CmdFIBModeFIB())                {                    SendMsg("FIB模式切换失败");                    return false;                }                Thread.Sleep(10000);                //8.控制FIB拍照                //9.保存照片                SendMsg("FIB拍照");                {                    //1. 设置图片名称                    //2. 保存图片2                    String fileName2 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName2;                    if (!GetImage(ImageMode.FIB, fileName2))                    {                        SendMsg("FIB拍照失败");                        return false;                    }                    Thread.Sleep(3000);                }                //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)                SendMsg("调用识别位置");                if (DialogResult.Yes == MessageBox.Show("移动已完成?", "确认消息", MessageBoxButtons.YesNo))                {                    SendMsg("移动已完成");                    //return true;                }                else                {                    SendMsg("移动已失败");                    return false;                }                SendMsg("进行PT沉积");                //11.自动工具样品类型参数确定是否需要PT沉积                {                    //1. 根据客户PT沉积坐标控制FIB调整到中心位置                    //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确                    //3. 根据坐标进行PT沉积                       if (!PTWork())                    {                        SendMsg("PT沉积失败");                        return false;                    }                }                return true;                //模拟为客户返回的坐标值                float x0 = 0, y0 = 0;                SendMsg("移动到新(" + x0.ToString() + "," + y0.ToString() + ")位置失败");                //12.根据梯形坐标控制FIB调整到中心位置                if (!iSEM.MoveStageXY(x0, y0))                {                    SendMsg("移动到新(" + x0.ToString() + "," + y0.ToString() + ")位置失败");                    return false;                }                //电镜移动是有一个延时的操作的?                //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确                float x1 = iSEM.GetStageAtX();                float y1 = iSEM.GetStageAtY();                if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)                {                    SendMsg("目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败");                    return false;                }                //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库                float[] firstPosition = iSEM.GetStagePosition();                //这里要调用文件保存功能                SendMsg("坐标1(" + firstPosition[0].ToString() + ","                    + firstPosition[1].ToString() + ","                    + firstPosition[2].ToString() + ","                    + firstPosition[3].ToString() + ","                    + firstPosition[4].ToString() + ","                    + firstPosition[5].ToString() + ")");            }            return false;        }        /// <summary>        /// 14. FIB切割        /// </summary>        /// <returns></returns>        public bool FIBCross()        {            //14.自动控制FIB切割            {                //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流                //2.控制FIB进行切割                SendMsg("FIB切割");                if (!FIBWork())                {                    SendMsg("FIB切割失败");                    return false;                }                Thread.Sleep(5000);                //3.控制FIB拍照600X                //4.保存图片                {                    //1.设置图片名称                    //2.保存图片3                    WorkingFolder = m_measureFile.FilePath;                    String fileName3 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName3;                    SendMsg("SEM拍照存储到" + fileName3);                    if (!GetImage(ImageMode.FIB, fileName3))                    {                        SendMsg("FIB拍照失败");                        return false;                    }                    Thread.Sleep(3000);                }                //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警                //6.设置FIB解冻:先读取状态,如果冻结状态则进行解冻            }            return true;        }        /// <summary>        /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转        /// </summary>        /// <returns></returns>        public bool FindCross()        {            //16.自动调整SEM找到切割位置            {                //1.控制SEM放大到300倍                if (!iSEM.SetMagnification(300))                {                    return false;                }                //2.控制SEM自动对焦、亮度、对比度-接口                if (MeasParam.FocusMode==1)                {                    //弹出手动对焦的窗口                }                else                {                    //调用自动对焦模块                }                Thread.Sleep(5000);                //3.控制SEM拍照                String fileName4 = WorkingFolder + ImageName4;                if (!GetImage(ImageMode.SEM, fileName4))                {                    return false;                }                Thread.Sleep(3000);                //4.将照片传给客户,获取偏移坐标,以及偏移角度                float x4 = 0, y4 = 0;                float angle = 0;                //5.根据坐标控制SEM移动到切孔位置,居中                if (!iSEM.MoveStageXY(x4, y4))                {                    return false;                }                if (!iSEM.SetScanRotation(angle))                {                    return false;                }                ////6.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确                //float x5 = iSEM.GetStageAtX();                //float y5 = iSEM.GetStageAtY();                //if (Math.Abs(x5 - x4) > fMin && Math.Abs(y5 - y4) > fMin)                //{                //    return false;                //}            }            return true;        }        public bool CommonWork()        {            SendMsg("插入PT针");            //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入            //if (firstHole.PT == true)            {                if (!InsertPT())                {                    SendMsg("插入PT针失败");                    return false;                }            }            //13. 自动 定位功能            SendMsg("自动定位切割位置");            if (!GetPoistion(false))            {                SendMsg("自动定位切割位置失败");                return false;            }            //14.自动控制FIB切割            SendMsg("FIB切割");            if (!FIBCross())            {                SendMsg("FIB切割失败");                return false;            }            //{            //    //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流            //    //2.控制FIB进行切割            //    //3.控制FIB拍照600X            //    //4.保存图片            //    {            //        //1.设置图片名称            //        //2.保存图片3            //        String fileName3 = WorkingFolder + ImageName3;            //        if (!GetImage(ImageMode.FIB, fileName3))            //        {            //            return false;            //        }            //    }            //    //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警            //    //6.设置FIB解冻:先读取状态,如果冻结状态则进行解冻            //}            //15.根据样品类型决定是否撤出PT针            SendMsg("撤出PT针");            //if (firstHole.PT == false)            //{            if (!RetractPT())            {                SendMsg("撤出PT针失败");                return false;            }            //}            // 16.找到切割位置            SendMsg("找到切割位置");            //17.自动控制SEM拍截面照            SendMsg("观测层高");            SendMsg("切换SEM控制");            if (!iSEM.CmdFIBModeSEM())            {                SendMsg("SEM模式切换失败");                return false;            }            Thread.Sleep(10000);            SendMsg("放大6000倍");            if (!iSEM.SetMagnification(6000))            {                SendMsg("放大倍数调整失败");                return false;            }            if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))            {                SendMsg("拍摄照片完成");                //return true;            }            else            {                SendMsg("拍摄照片失败");                return false;            }            SendMsg("图像校正36度");            //3.设置SEM角度补偿cos36度            if (!TiltCorrection(36))            {                return false;            }            Thread.Sleep(3000);            string fn;            //用宏抓一般图            Thread.Sleep(5000);            fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;            SendMsg("用宏抓一般图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(5000);            //用宏抓好图            fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;            SendMsg("用宏抓好图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(30000);            Thread.Sleep(10000);            WorkingFolder = m_measureFile.FilePath;            String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;            SendMsg("SEM拍照存储到" + fileName6);            if (!GetImage(ImageMode.SEM, fileName6))            {                SendMsg("SEM拍照失败");                return false;            }            //用宏抓标志图            fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;            SendMsg("用宏抓标志图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(30000);            //恢复简单抓图            Thread.Sleep(5000);            fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;            SendMsg("用宏抓一般图" + fn);            iSEM.CMDMCFFilename(fn);            SendMsg("所有图结束");            return true;        }        //第一个孔的测试过程        public bool FirstHole()        {            MeasureData.CutHole firstHole = m_cutHoles[0];                                    //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入            if (m_MsParam.PT == true)            {                if (!InsertPT())                {                    arg.Message = "插入PT针失败";                    SendMsg("1-0");                    return false;                }                arg.Message = "插入PT针成功";                SendMsg("1-0");            }            //13. 自动 定位功能            SendMsg("自动定位切割位置");            if (!GetPoistion(true))            {                SendMsg("自动定位切割位置失败");                return false;            }            //14.自动控制FIB切割            SendMsg("FIB切割");            if (!FIBCross())            {                SendMsg("FIB切割失败");                return false;            }            //{            //    //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流            //    //2.控制FIB进行切割            //    //3.控制FIB拍照600X            //    //4.保存图片            //    {            //        //1.设置图片名称            //        //2.保存图片3            //        String fileName3 = WorkingFolder + ImageName3;            //        if (!GetImage(ImageMode.FIB, fileName3))            //        {            //            return false;            //        }            //    }            //    //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警            //    //6.设置FIB解冻:先读取状态,如果冻结状态则进行解冻            //}            //15.根据样品类型决定是否撤出PT针            if (m_MsParam.PT == true)            {                if (!RetractPT())                {                    arg.Message = "撤出PT针失败";                    SendMsg("1-23");                    return false;                }                arg.Message = "撤出PT针成功";                SendMsg("1-23");            }            // 16.找到切割位置            SendMsg("找到切割位置");            //17.自动控制SEM拍截面照            SendMsg("观测层高");            SendMsg("切换SEM控制");            if (!iSEM.CmdFIBModeSEM())            {                SendMsg("SEM模式切换失败");                return false;            }            Thread.Sleep(10000);            SendMsg("放大6000倍");            if (!iSEM.SetMagnification(6000))            {                SendMsg("放大倍数调整失败");                return false;            }            if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))            {                SendMsg("拍摄照片完成");                //return true;            }            else            {                SendMsg("拍摄照片失败");                return false;            }            SendMsg("图像校正36度");            //3.设置SEM角度补偿cos36度            if (!TiltCorrection(36))            {                return false;            }            Thread.Sleep(3000);            string fn;            //用宏抓一般图            Thread.Sleep(5000);            fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;            SendMsg("用宏抓一般图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(5000);            //用宏抓好图            fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;            SendMsg("用宏抓好图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(30000);            Thread.Sleep(10000);            WorkingFolder = m_measureFile.FilePath;            String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;            SendMsg("SEM拍照存储到" + fileName6);            if (!GetImage(ImageMode.SEM, fileName6))            {                SendMsg("SEM拍照失败");                return false;            }            //用宏抓标志图            fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;            SendMsg("用宏抓标志图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(30000);            Thread.Sleep(5000);            fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;            SendMsg("用宏抓一般图" + fn);            iSEM.CMDMCFFilename(fn);            //延时1s??            Thread.Sleep(5000);            SendMsg("所有图结束");            ////17.自动控制SEM拍截面照            //{            //    //1.控制SEM放大到指定参数大小范围,6000x            //    if (!iSEM.SetMagnification(6000))            //    {            //        return false;            //    }            //    //2.控制SEM自动对焦、消像散、亮度、对比度            //    if (!MeasParam.FocusMode)            //    {            //        //弹出手动对焦的窗口            //    }            //    else            //    {            //        //调用自动对焦模块            //    }            //    //3.设置SEM角度补偿cos36度            //    if (!TiltCorrection(36))            //    {            //        return false;            //    }            //    //4.控制SEM拍照            //    //5.保存照片4            //    String fileName5 = WorkingFolder + ImageName5;            //    if (!GetImage(ImageMode.SEM, fileName5))            //    {            //        return false;            //    }            //    //6.将照片传给客户,获取偏移坐标            //    float x6 = 0, y6 = 0;            //    float angle1 = 0;            //    float mage = 10000;            //    //7.根据坐标控制SEM移动到分析位置            //    if (!iSEM.MoveStageXY(x6, y6))            //    {            //        return false;            //    }            //    //8.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确            //    float x7 = iSEM.GetStageAtX();            //    float y7 = iSEM.GetStageAtY();            //    if (Math.Abs(x6 - x7) > fMin && Math.Abs(y6 - y7) > fMin)            //    {            //        return false;            //    }            //    //9.控制SEM平行校正,并记录校正前初始值            //    float foldAnagle = iSEM.GetScanRotation();            //    if (foldAnagle == float.NaN)            //    {            //        return false;            //    }            //    if (!iSEM.SetScanRotation(angle1))            //    {            //        return false;            //    }            //    //10.控制SEM放大到指定参数大小范围            //    if (!iSEM.SetMagnification(mage))            //    {            //        return false;            //    }            //    //11.控制SEM自动对焦、消像散、亮度、对比度            //    if (!MeasParam.FocusMode)            //    {            //        //弹出手动对焦的窗口            //    }            //    else            //    {            //        //调用自动对焦模块            //    }            //    //12.控制SEM对分析位置拍照            //    String fileName6 = WorkingFolder + ImageName6;            //    if (!GetImage(ImageMode.SEM, fileName6))            //    {            //        return false;            //    }            //    //13.保存照片            //    //14.控制SEM取消电子束校正,回到初始值            //    if (!iSEM.SetScanRotation(foldAnagle))            //    {            //        return false;            //    }            //}            ////18.自动层高分析            //{            //    //1.获取SEM Pixel Size给客户传入参数            //    if (iSEM.GetPixelSize() == float.NaN)            //    {            //        return false;            //    }            //    //2.将照片传给客户,客户进行层高分析(返回分析后的图像、相对坐标、分辨率、各层编号以及各层对应的层高数据),如果客户自行出分析报告则无需返回数据            //}            ////19.自动能谱分析            //{            //    //1. 确定能谱位置            //    //2. 控制牛津打能谱            //    //3. 能谱分析——面扫+线扫描            //}            return true;        }        //非第一个孔的测试过程        public void OtherHole()        {            //for (int i = 1; i < m_cutHoles.Count; i++)            //{            SendMsg("当前切孔号为"+ m_nWorkHoleNo.ToString());                CutHole currentHole = m_cutHoles[m_nWorkHoleNo];                //1. 初始化                {                    //1. 设置FIB解冻:先读取状态,如果冻结则进行解冻                    //读取图像冻结状态                    float ffrozen = iSEM.GetImageFrozen();                    if (ffrozen == float.NaN)                    {                        return;                    }                    if (DialogResult.Yes == MessageBox.Show("样品台可以旋转恢复到水平吗?", "确认消息", MessageBoxButtons.YesNo))                    {                        SendMsg("样品台恢复到水平");                        //return true;                    }                    else                    {                        SendMsg("禁止样品台恢复到水平");                        return;                    }                    //2. 调节样品1号孔的样品台6轴坐标                    //3. 将样品1号孔坐标2存入数据库                    //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变                    if (!iSEM.SetStageGotoT(0))                    {                        return;                    }                    while (true)                    {                        Thread.Sleep(10000);                        if (iSEM.GetStageIs() == 0)                        {                            break;                        }                    }                    //5. 获取光镜2号孔XY坐标                    SendMsg("移动到"+m_nWorkHoleNo+"号孔位置:(" + currentHole.Position.X.ToString()+","+currentHole.Position.Y.ToString()+")");                                        //6. 根据光镜坐标控制样品台移动                    if (!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))                    {                        SendMsg("移动失败");                    }                    while (true)                    {                        Thread.Sleep(10000);                        if (iSEM.GetStageIs() == 0)                        {                            break;                        }                    }                                        //7. 控制样品台,调整T轴54度、M/Z/R轴不变                    if (DialogResult.Yes == MessageBox.Show("样品台可以旋转吗?", "确认消息", MessageBoxButtons.YesNo))                    {                        SendMsg("样品台旋转");                        //return true;                    }                    else                    {                        SendMsg("禁止样品台旋转");                        return;                    }                    if (!iSEM.SetStageGotoT(54))                    {                        return;                    }                    while (true)                    {                        Thread.Sleep(10000);                        if (iSEM.GetStageIs() == 0)                        {                            break;                        }                    }                }                SendMsg("拉直操作");                SendMsg("其他操作与1号孔操作一致");                if (!CommonWork())                {                    return;                }                //2. 定位切割                {                    //1. 拉直操作                    {                        //1.1 控制SEM进行拍照                        //1.2 图片传给客户,返回偏移角度                        //1.3 根据返回角度,控制样品台转动                    }                    //2. 与1号孔13步相同                }                //3. 以后步骤与1号孔以后步骤一致            //}        }        //角度补偿        public bool TiltCorrection(float a_fAngle)        {            //记录原来电镜的状态            // bool bTilt = false;            //float fOldTilt = iSEM.GetTiltCorrection();            //if (fOldTilt == float.NaN)            //{            //    return false;            //}            //else if (fOldTilt == 1)            //{            //    bTilt = true;            //}            //else if (fOldTilt == 0)            //{            //    bTilt = false;            //}            //float fOldAngle = iSEM.GetTiltAngle();            //if (fOldAngle == float.NaN)            //{            //    return false;            //}            //开启校正            SendMsg("开启校正");            if (!iSEM.SetTiltAngleOn())            {                return false;            }            //设置校正角度            //if (!iSEM.SetTiltAngle(fOldAngle))            //{            //    return false;            //}            //恢复原始状态            SendMsg("校正角度"+ a_fAngle.ToString());            if (!iSEM.SetTiltAngle(a_fAngle))            {                return false;            }            //if (bTilt)            //{            //    if (!iSEM.SetTiltCorrectionOn())            //    {            //        return false;            //    }            //}            //else            //{            //    if (!iSEM.SetTiltCorrectionOff())            //    {            //        return false;            //    }            //}            return true;        }        //拍图        public bool GetImage(ImageMode a_mode, String a_fileName)        {            //1. 图像解冻            float foldFrozen = iSEM.GetImageFrozen();            if (foldFrozen == float.NaN)            {                return false;            }            if (!iSEM.ImageLive())            {                return false;            }            //2. 确认图像模式            if (ImageMode.SEM == a_mode)            {                if (!iSEM.CmdFIBModeSEM())                {                    return false;                }            }            else if (ImageMode.FIB == a_mode)            {                if (!iSEM.CmdFIBModeFIB())                {                    return false;                }            }            else            {                return false;            }            //3. 获取分辨率            int[] ImageSize = iSEM.GetImageStore();            if (ImageSize[0] == 0 || ImageSize[1] == 0)            {                return false;            }            short width = (short)ImageSize[0];            short height = (short)ImageSize[1];            //4. 抓图            if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))            {                return false;            }            //5. 恢复初始状态            if (foldFrozen == 0)            {                if (!iSEM.ImageLive())                {                    return false;                }            }            else if (foldFrozen == 1)            {                if (!iSEM.ImageFrozen())                {                    return false;                }            }            return true;        }        //自动聚焦        public bool AutoFocus(string a_strPath, out int a_nWd)        {            a_nWd = 0;            a_nWd = (int)Math.Ceiling(iSEM.GetWorkingDistance() * 100000000 + 0.5);//获取当前的工作距离            return true;        }    }}
 |