123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741 |
- //时间: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;
- using OpenCvSharp;
- using Extender;
- using DBManager;
- 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 Boolean State
- {
- get { return m_state; }
- set { m_state = value; }
- }
- private Boolean 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>
- /// <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(float Slope, float x0, float y0, float x1, float y1, ref float Hx, ref float Hy)
- {
- try
- {
- float xr = x1 - x0;//倾斜图到中心的距离差x
- float yr = y1 - y0;//倾斜图到中心的距离差y
- float R = (float)Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
- //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
- float k = (float)(Math.Atan(yr / xr) / Math.PI * 180);//x1,y1的直角三角形圆心角度
- float 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);
- float y2 = (float)(Math.Sin(Math.PI / (180 / k_S)) * R);
- float x2 = (float)(Math.Cos(Math.PI / (180 / k_S)) * R);
- if (Slope > 0 || Slope < 0)
- {
- Hx = x0 + x2;
- Hy = y0 + y2;
- }
- else
- {
- Hx = 0;
- Hy = 0;
- }
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- //Web接口类
- public WebResult wr = null;
- //扫描周期
- private float cycle_time = 0;
- //人工干预
- public int hand_intervene = 2;
- //样品台保护值
- public float X_Min = 0;
- public float X_Max = 0.13f;
- public float Y_Min = 0;
- public float Y_Max = 0.13f;
- public float Z_Min = 0;
- public float Z_Max = 0.05f;
- public float T_Min = -4;
- public float T_Max = 70;
- public float R_Min = -380;
- public float R_Max = 380;
- public float M_Min = 0;
- public float M_Max = 0.012f;
- public float x_center_point = 65;
- public float y_center_point = 65;
- public event ThreadStatusHandler SendThreadStatus; // 声明事件
- public event CutHolesStatusHandler SendCutHolesStatus; // 声明事件
- //定义一个全局的消息类
- ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");
- //全局只有一个fatorySEM
- static FactoryHardware factorySEM = FactoryHardware.Instance;
- ISEMControl iSEM = factorySEM.ISEM;
- //全局只有一个Extender
- static ExtenderInterface factoryExtender = null;// ExtenderInterface.Instance;
- IExtenderControl iExtender = null;// factoryExtender.IExtender;
- MeasureDB m_MeasDB = null;
- //@的作用是不用转义字符\\只打一个就行
- const String ImageName0 = @"Straighten.tif"; //传给客户,原始图像,为拉直操作
- const String ImageName1 = @"FindCutPostion.tif"; //传给客户,作水平校正
- const String ImageName2 = @"FIBCutPostion.tif";//传给客户,找到切割点
- const String ImageName31 = @"FIBBefore.tif";
- const String ImageName32 = @"FIBAfter.tif";
- const String ImageName4 = @"SEMTrapCP.tif";//传给客户,找到已经切割点
- const String ImageName5 = @"SEMDegreeTrap.tif";//传给客户,水平校正
- const String ImageName6 = @"SEMMagEnd.tif";//传给客户,测量层高
- const String ImageName7 = @"EDSImage.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; //单位是米
- public Boolean key_stop = false;
- String focus_path = "";
- String FIBfocus_path = "";
- String StigX_path = "";
- String StigY_path = "";
- String EDS_path = "";
- String data_path = "";
- int m_nWorkHoleNo = -1;
- int m_nXrayId = -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;
- if(m_measureFile.MParam.EDS == true)
- {
- factoryExtender = ExtenderInterface.Instance;
- iExtender = factoryExtender.IExtender;
- m_MeasDB = new MeasureDB(m_measureFile);
- }
- return true;
- }
- public void SendMsg(string step_code)
- {
- arg.Step_Code = step_code;
- arg.Time = DateTime.Now;
- 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 bool DoEDS(int a_PointNum, string PointsName)
- {
- //XrayID记录
- EDSParam param = m_measureFile.MParam.EDSP;
- double dDwellTime = param.DwellTime;
- int nImageType = param.ImageType;
- double dScanSizes = param.ScanSize;
- iExtender.SetImageAcquistionSetting(dDwellTime, nImageType, dScanSizes);
- string path = EDS_path;
- iExtender.GrabImage(path + "\\EDSImage.tif", 0, 0, 0, 0, 0);
-
- //送给客户,计算感兴趣的区域
- List<Point> listPoints = new List<Point>();
- List<List<Segment>> listFeature = new List<List<Segment>>();
- //向分析点数据库更新
- if (!m_MeasDB.InsetAPoint(a_PointNum, PointsName, EDS_path,listPoints.Count,listFeature.Count))
- {
- LogManager.AddHardwareLog("插入分析点失败", true);
- }
- int AreasNo = -1;
- if (param.PointMode == true)
- {
- //点采集
- foreach (Point pt in listPoints)
- {
- long[] XrayData = new long[2000];
- Dictionary<string, double> listElement = new Dictionary<string, double>();
- iExtender.XrayPointCollectiong(param.PointTime, pt.X, pt.Y, out XrayData, out listElement);
- //写入数据库
- m_nXrayId++;
- m_MeasDB.InsertAPointXay(a_PointNum, m_nXrayId, pt.X, pt.Y, XrayData, listElement);
-
- }
- }
- if (param.AreaMode == true)
- {
- //面采集
- long[] XrayData = new long[2000];
- Dictionary<string, double> listElement = new Dictionary<string, double>();
- foreach (List < Segment> listSeg in listFeature)
- {
- iExtender.XrayAreaCollectiong(param.AreaTime, listSeg, out XrayData, out listElement);
- //写入数据库
- m_nXrayId++;
-
- AreasNo++;
- m_MeasDB.InsertAAreaXay(a_PointNum, m_nXrayId, AreasNo, listSeg, XrayData, listElement);
- }
- }
- return true;
- }
- //测量流程
- public void DoMeasure()
- {
- //创建线程的测量状态的更新
- this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);
- if (SendThreadStatus != null)
- {
- //SendMsg("开始测量。");
- }
- LogManager.AddHardwareLog("开始测量",true);
- //检查硬件连接是否正常
- if (!ConnectHardware())
- {
- //SendMsg("连接硬件失败。");
- this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
- return;
- }
- //设置工作文件夹
- if (!SetWorkingFolderStr())
- {
- //SendMsg("设置工作文件夹失败");
- this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
- return;
- }
- //增加EDS控制
- //将停止键复位
- key_stop = false;
- //开始测量就将模式设置为SEM
- if (!iSEM.CmdFIBModeSEM())
- {
- LogManager.AddHardwareLog("开始切换到SEM模式失败,程序退出。", true);
- return;
- }
- arg.Picture_Information.Work_Status = "SEM";
- //自动亮度对比度
- if (!iSEM.SetAutoVideoBrightnessAndContrast())
- {
- LogManager.AddHardwareLog("开始设置自动亮度、对比度失败,程序退出。", true);
- return;
- }
- Thread.Sleep(5000);
- //设置扫描周期
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- if (cycle_time == 0)
- {
- LogManager.AddHardwareLog("获取扫描周期时间失败", true);
- return;
- }
- for (int i = 0; i < m_cutHoles.Count; i++)
- {
- //记录测量序号和孔名
- m_nWorkHoleNo = i;
- arg.HoleName = m_cutHoles[i].HoleName;
- //最终数据存放目录
- data_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName;
- //对焦数据存放目录
- focus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\Focus";
- m_MsParam.AutoFocus.Path = focus_path;
- if (!Directory.Exists(focus_path))
- {
- Directory.CreateDirectory(focus_path);
- }
- //FIB对焦数据存放目录
- FIBfocus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\FIBFocus";
- m_MsParam.FIBFocus.Path = FIBfocus_path;
- if (!Directory.Exists(FIBfocus_path))
- {
- Directory.CreateDirectory(FIBfocus_path);
- }
- //StigX数据存放目录
- StigX_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigX";
- m_MsParam.AutoStigX.Path = StigX_path;
- if (!Directory.Exists(StigX_path))
- {
- Directory.CreateDirectory(StigX_path);
- }
- //StigY数据存放目录
- StigY_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigY";
- m_MsParam.AutoStigY.Path = StigY_path;
- if (!Directory.Exists(StigY_path))
- {
- Directory.CreateDirectory(StigY_path);
- }
- //EDS数据存放路径
- if (m_measureFile.MParam.EDS == true)
- {
- EDS_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\EDS";
- m_MsParam.AutoStigY.Path = EDS_path;
- if (!Directory.Exists(EDS_path))
- {
- Directory.CreateDirectory(EDS_path);
- }
- }
- //判断孔状态
- if (m_cutHoles[i].STATE != State.Ready)
- {
- continue;
- }
- //开始循环工作
- if (i == 0)
- {
- m_cutHoles[i].START = DateTime.Now;
- //切孔操作-开始
- m_cutHoles[i].STATE = State.InProcess;
- //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
- SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
- //1、移动样品台到第一个观测点,先移动R轴,再移动XY轴
- if (!iSEM.SetStageGotoR(m_cutHoles[0].Position.R))
- {
- LogManager.AddHardwareLog("样品台R轴移动失败。", true);
- return;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return;
- }
- //移动XY轴
- if (!iSEM.MoveStageXY(m_cutHoles[0].Position.X, m_cutHoles[0].Position.Y))
- {
- LogManager.AddHardwareLog("样品台XY轴移动失败。", true);
-
- return;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return;
- }
- //成功
- if (FirstHole())
- {
- //保存文件,将测量状态更改
- m_cutHoles[i].STATE = State.Success;
- m_cutHoles[i].END = DateTime.Now;
- m_measureFile.Save();
- }
- //失败
- else
- {
- m_cutHoles[i].STATE = State.Failed;
- m_cutHoles[i].END = DateTime.Now;
- m_measureFile.Save();
- }
- //切孔操作-完成
- //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
- SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
- }
- else
- {
- //其他孔测量之前的初始化
- if (!OtherHole_Init())
- {
- arg.Message = "当前测量点位置初始失败!";
- arg.State = false;
- SendMsg("0-1");
- Thread.Sleep(5000);
- continue;
- }
- //其他孔的测量
- m_cutHoles[i].START = DateTime.Now;
- //非第一个孔的测试
- //SendMsg("第" + i.ToString() + "个切孔开始测量");
- //切孔操作-开始
- //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
- m_cutHoles[i].STATE = State.InProcess;
- SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
- //其他孔的测试
-
- //成功
- if (OtherHole())
- {
- //保存文件,将测量状态更改
- m_cutHoles[i].STATE = State.Success;
- m_cutHoles[i].END = DateTime.Now;
- m_measureFile.Save();
- }
- //失败
- else
- {
- m_cutHoles[i].STATE = State.Failed;
- m_cutHoles[i].END = DateTime.Now;
- m_measureFile.Save();
- }
- //切孔操作-完成
- //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
- SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
- }
- if(key_stop)
- {
- m_cutHoles[i].END = DateTime.Now;
- m_cutHoles[i].STATE = State.Ready;
- m_measureFile.Save();
- arg.Message = "用户停止测量";
- SendMsg("0-0");
- break;
- }
- }
- }
- //检查硬件连接是否正常
- 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(m_MsParam.PTTemp))
- {
- 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(m_MsParam.FIBTemp))
- {
- return false;
- }
- //等待切割完成
- while (true)
- {
- Thread.Sleep(10000);
- if (iSEM.GetFIBMode() == 0)
- {
- break;
- }
- }
- return true;
- }
- //执行ELY文件的步骤
- 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;
- }
- //执行自动对焦
- public bool ImageFocus(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(focus_path))
- {
- Directory.Delete(focus_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(focus_path);
- //1、对焦参数类,2、输出工作距离
- int wd = 0;
- //20201015 根据当前的工作距离重新计算对焦位置
- float currentWd = iSEM.GetWorkingDistance();
- m_MsParam.AutoFocus.UP = currentWd * 1000000 - m_MsParam.AutoFocus.Step;
- m_MsParam.AutoFocus.Down = currentWd * 1000000 + m_MsParam.AutoFocus.Step;
- LogManager.AddHardwareLog("修改对焦参数", true);
- AutoFocus(m_MsParam.AutoFocus, out wd, step_code);
- //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
- //设置工作距离
- iSEM.SetWorkingDistance((float)(wd * 0.00000001));
- //设置完工作距离后必须延迟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;
- }
- //执行自动消像散
- 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>
- /// <returns></returns>
- public bool GetPoistion()
- {
- float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
- int state = 1;
- //1.控制SEM放大600X
- if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
- {
- arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
- arg.State = false;
- SendMsg("1-5");
- return false;
- }
- if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification))
- {
- arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍失败";
- arg.State = false;
- SendMsg("1-5");
- return false;
- }
- arg.State = true;
- arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍成功";
- SendMsg("1-5");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //2.控制SEM自动对焦、亮度、对比度
- if(ImageFocus("1-6"))
- {
- arg.Message = "自动对焦完成";
- arg.State = true;
- SendMsg("1-6");
- }
- else
- {
- LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
- arg.Message = "自动对焦失败";
- arg.State = false;
- SendMsg("1-6");
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //1.1大于10000倍进行消像散处理
- float dMag = iSEM.GetMagnification();
- if (dMag > 10000)//需要消像散
- {
- if (!ImageStig("1-6"))
- {
- LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
- arg.Message = "拉直操作自动消像散失败!";
- arg.State = false;
- SendMsg("1-6");
- return false;
- }
- arg.Message = "拉直操作自动消像散成功!";
- arg.State = true;
- SendMsg("1-6");
- }
- //3.控制SEM拍照,找到切割位置
- String fileName1 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Location_Magnification.ToString("0") + "_" + ImageName1;
- arg.Picture_Information.Picture_FullPath = fileName1;
- arg.Picture_Information.Work_Voltage = m_MsParam.Location_Voltage;
- arg.Picture_Information.Magnification = m_MsParam.Location_Magnification;
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.SEM, fileName1))
- {
- arg.Message = "SEM拍照失败";
- arg.State = false;
- SendMsg("1-7");
- return false;
- }
- arg.State = true;
- arg.Message = "SEM拍照成功";
- SendMsg("1-7");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //判断是否为仅拍照,不是则执行FIB操作
- if (!m_MsParam.Is_Photograph)
- {
- //6.设置FIB拍照参数——扫描时间、束流等
- //7.控制FIB自动亮度、对比度
- if (!iSEM.CmdFIBModeFIB())
- {
- arg.Message = "FIB模式切换失败";
- arg.State = false;
- SendMsg("1-8");
- return false;
- }
- arg.State = true;
- arg.Picture_Information.Work_Status = "FIB";
- arg.Message = "FIB模式切换成功";
- SendMsg("1-8");
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //8.控制FIB拍照
- //9.保存照片======更改路径
- String fileName2 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString("0") + "_" + ImageName2;
- arg.Picture_Information.Picture_FullPath = fileName2;
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = iSEM.GetMagnification();
- Thread.Sleep(1000);
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //FIB的放大位数,将来会改
- if(!iSEM.SetFIBMagnification(m_MsParam.FIB_Magnification))
- {
- arg.Message = "FIB放大倍数设置失败";
- arg.State = false;
- SendMsg("1-9");
- return false;
- }
- arg.Message = "FIB放大倍数设置成功";
- arg.State = true;
- SendMsg("1-9");
- Thread.Sleep(1000);
- //增加FIB对焦
- //2.控制SEM自动对焦、亮度、对比度
- if (FIBFocus("1-10"))
- {
- arg.Message = "自动FIB对焦完成";
- arg.State = true;
- SendMsg("1-10");
- }
- else
- {
- LogManager.AddHardwareLog("设置观测点后,自动FIB对焦失败。", true);
- arg.Message = "自动FIB对焦失败";
- arg.State = false;
- SendMsg("1-10");
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.FIB, fileName2))
- {
- arg.Message = "FIB拍照失败";
- arg.State = false;
- SendMsg("1-11");
- return false;
- }
- arg.State = true;
- arg.Message = "FIB拍照成功";
- SendMsg("1-11");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
- LogManager.AddHardwareLog("准备移动样品台", true);
- LogManager.AddHardwareLog("文件名="+fileName2, true);
- LogManager.AddHardwareLog("样品类型="+m_MsParam.SampleName, true);
- LogManager.AddHardwareLog("供应商名称="+m_MsParam.Firm, true);
- wr.Img_Cut_Position(fileName2, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
- LogManager.AddHardwareLog("FIB梯形左上角和右上角位置信息= " + x1.ToString() + ", " + y1.ToString() + ", " + x2.ToString() + ", " + y2.ToString(), true);
- LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
- if (state == 1)
- {
- //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
- float xc = (x1 + x2) / 2;
- float yc = (y1 + y2) / 2;
- if (!MoveToPix(xc,yc))
- {
- arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
- arg.State = false;
- SendMsg("1-12");
- return false;
- }
- arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置成功";
- arg.State = true;
- SendMsg("1-12");
- if (hand_intervene == 1)
- {
- MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
- }
- }
- else
- {
- arg.Message = "图像接口参数state返回值为零";
- arg.State = false;
- SendMsg("1-12");
- if(hand_intervene==1)
- {
- if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //11.自动工具样品类型参数确定是否需要PT沉积
- if (m_MsParam.PT)
- {
- //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
- //第10步已经移动好位置
- //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确
- //x0 = iSEM.GetStageAtX();
- //y0 = iSEM.GetStageAtY();
- //if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
- //{
- // arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败";
- // arg.State = false;
- // SendMsg("1-1");
- // return false;
- //}
- //arg.State = true;
- //arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动成功";
- //SendMsg("1-8");
- //判断是否停止进程
- //if (key_stop)
- //{
- // return false;
- //}
- //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
- if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
- {
- if (!InsertPT())
- {
- arg.Message = "插入PT针失败";
- arg.State = false;
- SendMsg("1-13");
- return false;
- }
- arg.State = true;
- arg.Message = "插入PT针成功";
- SendMsg("1-13");
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //3. 根据坐标进行PT沉积
- if (!PTWork())
- {
- arg.Message = "PT沉积失败";
- arg.State = false;
- SendMsg("1-14");
- return false;
- }
- arg.State = true;
- arg.Message = "PT沉积成功";
- SendMsg("1-14");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //15.根据样品类型决定是否撤出PT针
- if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
- {
- if (!RetractPT())
- {
- arg.Message = "撤出PT针失败";
- arg.State = false;
- SendMsg("1-15");
- return false;
- }
- arg.State = true;
- arg.Message = "撤出PT针成功";
- SendMsg("1-15");
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- }
- //12.根据梯形坐标控制FIB调整到中心位置
- //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确
- //以上两步已经将程序移动到11内部去做
- //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库
- float[] firstPosition = iSEM.GetStagePosition();
- m_cutHoles[0].Position.X = firstPosition[0];
- m_cutHoles[0].Position.Y = firstPosition[1];
- m_cutHoles[0].Position.Z = firstPosition[2];
- m_cutHoles[0].Position.T = firstPosition[3];
- m_cutHoles[0].Position.R = firstPosition[4];
- m_cutHoles[0].Position.M = firstPosition[5];
- //这里要调用文件保存功能
- arg.Message = "坐标1(" + firstPosition[0].ToString() + ","
- + firstPosition[1].ToString() + ","
- + firstPosition[2].ToString() + ","
- + firstPosition[3].ToString() + ","
- + firstPosition[4].ToString() + ","
- + firstPosition[5].ToString() + ")";
- arg.State = true;
- SendMsg("1-16");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 14. FIB切割
- /// </summary>
- /// <returns></returns>
- public bool FIBCross()
- {
- int state = 0;
- //这里不知道PT沉积之后是否变回SEM,所以这里加一句切换到FIB命令
- if (!iSEM.CmdFIBModeFIB())
- {
- return false;
- }
- Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
- //增加FIB对焦
- if (FIBFocus("1-17"))
- {
- arg.Message = "FIB自动对焦完成";
- arg.State = true;
- SendMsg("1-17");
- }
- else
- {
- LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
- arg.Message = "自动对焦失败";
- arg.State = false;
- SendMsg("1-17");
- return false;
- }
- //判断是否停止进程
- 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";
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.SEM, fileName31))
- {
- arg.Message = "FIB切割前拍照SEM模式照失败";
- arg.State = false;
- SendMsg("1-18");
- return false;
- }
- arg.State = true;
- arg.Message = "FIB切割前拍照SEM模式照成功";
- SendMsg("1-18");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //14.自动控制FIB切割
- //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
- //2.控制FIB进行切割
- //以上1、2步全部用ELY文件代替
- if (!FIBWork())
- {
- arg.Message = "FIB切割失败";
- arg.State = false;
- SendMsg("1-19");
- return false;
- }
- arg.State = true;
- arg.Message = "FIB切割成功";
- SendMsg("1-19");
- Thread.Sleep(1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //切割后会切换到SEM,所以需要再切换回FIB模式
- if (!iSEM.CmdFIBModeFIB())
- {
- return false;
- }
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //3.控制FIB拍照600X
- //底层没有控制方法。
- //4.保存图片
- String fileName32 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName32;
- arg.Picture_Information.Picture_FullPath = fileName32;
- arg.Picture_Information.Work_Status = "FIB";
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //增加FIB对焦
- if (FIBFocus("1-20"))
- {
- arg.Message = "FIB自动对焦完成";
- arg.State = true;
- SendMsg("1-20");
- }
- else
- {
- LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
- arg.Message = "自动对焦失败";
- arg.State = false;
- SendMsg("1-20");
- return false;
- }
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.FIB, fileName32))
- {
- arg.Message = "FIB切割后拍照失败";
- arg.State = false;
- SendMsg("1-21");
- return false;
- }
- arg.State = true;
- arg.Message = "FIB切割后拍照成功";
- SendMsg("1-21");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
- wr.Img_Cut_Success(fileName31, fileName32, out state);
- if(state == 0)
- {
- arg.Message = "图像接口参数state返回值为零";
- arg.State = false;
- SendMsg("1-22");
- if (hand_intervene == 1)
- {
- if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- arg.State = true;
- arg.Message = "FIB切割校验成功";
- SendMsg("1-22");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
- /// </summary>
- /// <returns></returns>
- public bool FindCross()
- {
- float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
- int state = 0;
- //切换到SEM模式
- if (!iSEM.CmdFIBModeSEM())
- {
- arg.Message = "SEM模式切换失败";
- arg.State = false;
- SendMsg("1-23");
- return false;
- }
- arg.State = true;
- arg.Message = "SEM模式切换成功";
- SendMsg("1-23");
- arg.Picture_Information.Work_Status = "SEM";
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //1.控制SEM放大到300倍
- if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
- {
- arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
- arg.State = false;
- SendMsg("1-24");
- return false;
- }
- if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification/3))
- {
- arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification / 3).ToString("0.0") + "倍失败";
- arg.State = false;
- SendMsg("1-24");
- return false;
- }
- arg.State = true;
- arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification/3).ToString("0.0") + "倍成功";
- SendMsg("1-24");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //3.控制SEM拍照
- String fileName4 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + (m_MsParam.Location_Magnification/3).ToString("0") + "_" + ImageName4;
- arg.Picture_Information.Picture_FullPath = fileName4;
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = iSEM.GetMagnification();
- Thread.Sleep(1000);
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.SEM, fileName4))
- {
- arg.State = false;
- arg.Message = "SEM拍照失败";
- SendMsg("1-25");
- return false;
- }
- arg.State = true;
- arg.Message = "SEM拍照成功";
- SendMsg("1-25");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //4.将照片传给客户,获取偏移坐标,以及偏移角度
- //5.根据坐标控制SEM移动到切孔位置,居中
- LogManager.AddHardwareLog("准备移动样品台", true);
- LogManager.AddHardwareLog("文件名=" + fileName4, true);
- wr.Img_Trapezoid_Top_Center_Position(fileName4,out x2, out y2, out state);
- LogManager.AddHardwareLog("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
- LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
- if (state == 1)
- {
- //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
- if (!MoveToPix(x2, y2))
- {
- arg.State = false;
- arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
- SendMsg("1-26");
- return false;
- }
- //判断是否移动完成
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- arg.State = true;
- arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
- SendMsg("1-26");
- if (hand_intervene == 1)
- {
- MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
- }
- }
- else
- {
- arg.Message = "图像接口参数state返回值为零";
- arg.State = false;
- SendMsg("1-26");
- if (hand_intervene == 1)
- {
- if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 17.自动控制SEM拍截面照
- /// </summary>
- /// <returns></returns>
- public bool ShotSection(ref String image18)
- {
- float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
- int state = 0;
- //1、放大6000倍,放大倍数参数photograph_
- if (!iSEM.SetSEMVoltage(m_MsParam.Photograph_Voltage))
- {
- arg.Message = "电压设置" + m_MsParam.Photograph_Voltage.ToString("0.0") + "失败";
- arg.State = false;
- SendMsg("1-27");
- return false;
- }
- if (!iSEM.SetMagnification(m_MsParam.Photograph_Magnification))
- {
- arg.Message = "放大倍数调整失败";
- arg.State = false;
- SendMsg("1-27");
- return false;
- }
- arg.Message = "放大倍数调整成功";
- arg.State = true;
- SendMsg("1-27");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //2.控制SEM自动对焦、亮度、对比度-接口
- if (ImageFocus("1-28"))
- {
- arg.Message = "自动对焦完成";
- arg.State = true;
- SendMsg("1-28");
- }
- else
- {
- arg.Message = "自动对焦失败";
- arg.State = false;
- SendMsg("1-28");
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //1.1大于10000倍进行消像散处理
- float dMag = iSEM.GetMagnification();
- if (dMag > 10000)//需要消像散
- {
- if (!ImageStig("1-28"))
- {
- LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
- arg.Message = "拉直操作自动消像散失败!";
- arg.State = false;
- SendMsg("1-28");
- return false;
- }
- arg.Message = "拉直操作自动消像散成功!";
- arg.State = true;
- SendMsg("1-28");
- }
- //3、设置SEM补偿角度
- if (m_MsParam.Is_Photograph == false)
- {
- if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
- {
- arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
- arg.State = false;
- SendMsg("1-29");
- return false;
- }
- arg.State = true;
- arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
- SendMsg("1-29");
- Thread.Sleep(2000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //4、拍照,5、保存照片
- String fileName5 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName5;
- arg.Picture_Information.Picture_FullPath = fileName5;
- arg.Picture_Information.Work_Status = "SEM";
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = iSEM.GetMagnification();
- Thread.Sleep(1000);
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.SEM, fileName5))
- {
- arg.Message = "SEM拍照失败";
- arg.State = false;
- SendMsg("1-30");
- return false;
- }
- arg.State = true;
- arg.Message = "SEM拍照成功";
- SendMsg("1-30");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- if (m_MsParam.Is_Photograph == false)
- {
- //8,计算切割面区域偏移角度及方向
- float degree = 0;
- int direction = 0;
- wr.Img_Center_Position_OffsetAngle_Direction(fileName5, out degree, out direction, out state);
- LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "计算切割面区域的角度=" + degree.ToString(), true);
- //接口返回像素,*pixelsize,得到坐标点。判断移动方式
- if (state == 1)
- {
- //梯形角度
- iSEM.SetScanRotationOn();
- Thread.Sleep(1000);
- iSEM.SetScanRotation(degree);
- Thread.Sleep(1000);
- arg.State = true;
- arg.Message = "图像接口返回角度为:" + degree.ToString();
- SendMsg("1-31");
- if (hand_intervene == 1)
- {
- MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
- }
- }
- else
- {
- arg.Message = "图像接口参数State返回值为零";
- arg.State = false;
- SendMsg("1-31");
- if(hand_intervene == 1)
- {
- if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //11、自动对焦。与之前操作相同
- if (ImageFocus("1-32"))
- {
- arg.Message = "自动对焦完成";
- arg.State = true;
- SendMsg("1-32");
- }
- else
- {
- arg.Message = "自动对焦失败";
- arg.State = false;
- SendMsg("1-32");
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //1.1大于10000倍进行消像散处理
- dMag = iSEM.GetMagnification();
- if (dMag > 10000)//需要消像散
- {
- if (!ImageStig("1-32"))
- {
- LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
- arg.Message = "拉直操作自动消像散失败!";
- arg.State = false;
- SendMsg("1-32");
- return false;
- }
- arg.Message = "拉直操作自动消像散成功!";
- arg.State = true;
- SendMsg("1-32");
- }
- //12拍照
- String fileName6 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName6;
- arg.Picture_Information.Picture_FullPath = fileName6;
- arg.Picture_Information.Work_Status = "SEM";
- arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
- Thread.Sleep(1000);
- arg.Picture_Information.Magnification = iSEM.GetMagnification();
- Thread.Sleep(1000);
- arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
- Thread.Sleep(1000);
- //拍照前改变速度,延时
- iSEM.CmdSaveRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- if (!GetImage(ImageMode.SEM, fileName6))
- {
- arg.Message = "SEM拍照失败";
- arg.State = false;
- SendMsg("1-33");
- return false;
- }
- arg.State = true;
- image18 = fileName6;
- arg.Message = "SEM拍照成功";
- SendMsg("1-33");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //华为程序还没有做出来
- }
- //14光束复位和Rotation关闭开关
- arg.Message = "光束复位成功";
- arg.State = true;
- SendMsg("1-36");
- iSEM.SetTiltAngleOff();
- Thread.Sleep(1000);
- iSEM.SetScanRotationOff();
- Thread.Sleep(1000);
- iSEM.SetBeamShiftX(0);
- Thread.Sleep(1000);
- iSEM.SetBeamShiftY(0);
- Thread.Sleep(3000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- return true;
- }
- //第一个孔的测试过程
- public bool FirstHole()
- {
- MeasureData.CutHole firstHole = m_cutHoles[0];
- //设置拉直的放大倍数
- if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
- {
- arg.Message = "拉直放大倍数设置失败!";
- arg.State = false;
- SendMsg("1-0");
- return false;
- }
- arg.Message = "拉直放大倍数设置成功!";
- arg.State = true;
- SendMsg("1-0");
- Thread.Sleep(1000);
- //自动化流程-每个点都需要补偿54度
- if (m_MsParam.Is_Photograph == false)
- {
- if (!TiltCorrection(54.0f))
- {
- arg.Message = "角度补偿54度失败!";
- arg.State = false;
- SendMsg("1-1");
- return false;
- }
- Thread.Sleep(2000);
- arg.Message = "角度补偿54度成功!";
- arg.State = true;
- SendMsg("1-1");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //2、拉直操作
- if (!Straighten_Handle())
- {
- LogManager.AddHardwareLog("拉直操作失败。", true);
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //13. 自动 定位功能
- if (!GetPoistion())
- {
- LogManager.AddHardwareLog("自动定位失败,程序退出。", true);
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //14.自动控制FIB切割
- if (m_MsParam.Is_Photograph == false)
- {
- if (!FIBCross())
- {
- return false;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //16.找到切割位置
- if (m_MsParam.Is_Photograph == false)
- {
- if (!FindCross())
- {
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //将过程17最后的拍照图片提出给18步进行调用
- String img18 = "";
- //17.自动控制SEM拍截面照
- if (!ShotSection(ref img18))
- {
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //18.自动层高分析
- if (m_MsParam.Is_Photograph == false)
- {
- float size = iSEM.GetPixelSize();
- float mag = iSEM.GetMagnification();
- int state = 1;
- //wr.Img_Measure_Size(img18, mag, size, out state);
- if (state == 0)
- {
- arg.Message = "测量尺寸失败";
- arg.State = false;
- SendMsg("1-40");
- return false;
- }
- arg.State = true;
- arg.Message = "测量尺寸成功";
- SendMsg("1-40");
- }
- #region 测试程序
- //最后保存测量数据-测量文件、测量状态,m_cutHoles[i].STATE!=MeasureData.CutHole.State.Success.
- //中间停止更新状态为Unmeasured,过程中return false时,更新状态为failed,保存测量文件
- //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. 能谱分析——面扫+线扫描
- //}
- #endregion
- return true;
- }
- //非第一个孔的测试过程
- public bool OtherHole()
- {
- //设置拉直的放大倍数
- if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
- {
- LogManager.AddHardwareLog("拉直放大倍数设置失败,程序退出。", true);
- arg.Message = "拉直放大倍数设置失败!";
- arg.State = false;
- SendMsg("1-0");
- return false;
- }
- arg.Message = "拉直放大倍数设置成功!";
- arg.State = true;
- SendMsg("1-0");
- Thread.Sleep(1000);
- //自动化流程-每个点都需要补偿54度
- if (m_MsParam.Is_Photograph == false)
- {
- if (!TiltCorrection(54.0f))
- {
- arg.Message = "角度补偿54度失败!";
- arg.State = false;
- SendMsg("1-1");
- return false;
- }
- arg.Message = "角度补偿54度成功!";
- arg.State = true;
- SendMsg("1-1");
- Thread.Sleep(2000);
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //拉直操作
- if (!Straighten_Handle())
- {
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //13. 自动 定位功能
- if (!GetPoistion())
- {
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //14.自动控制FIB切割
- if (m_MsParam.Is_Photograph == false)
- {
- if (!FIBCross())
- {
- return false;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- // 16.找到切割位置
- if (m_MsParam.Is_Photograph == false)
- {
- if (!FindCross())
- {
- return false;
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //将过程17最后的拍照图片提出给18步进行调用
- String img18 = "";
- //17.自动控制SEM拍截面照
- if (!ShotSection(ref img18))
- {
- return false;
- }
-
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //18.自动层高分析
- if (m_MsParam.Is_Photograph == false)
- {
- float size = iSEM.GetPixelSize();
- float mag = iSEM.GetMagnification();
- int state = 1;
- //wr.Img_Measure_Size(img18, mag, size, out state);
- if (state == 0)
- {
- arg.Message = "测量尺寸失败";
- SendMsg("1-40");
- return false;
- }
- arg.Message = "测量尺寸成功";
- SendMsg("1-40");
- }
- #region 测试程序
- //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("所有图结束");
- #endregion
- return true;
- }
- //测试完第一个孔后的样品台初始化操作。
- //再调用CommonWork执行非第一个孔的测试过程
- public bool OtherHole_Init()
- {
- CutHole currentHole = m_cutHoles[m_nWorkHoleNo];
- #region 初始化
- //1、不只拍照,且不是倾斜观测,则移动T轴
- if (m_MsParam.Is_Photograph == false && m_MsParam.Title == false)
- {
- //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
- if (!iSEM.SetStageGotoT(0))
- {
- return false;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //2、如果是倾斜观测,则移动Z轴
- if(m_MsParam.Title==true)
- {
- //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
- if (!iSEM.SetStageGotoZ(currentHole.Position.Z - m_MsParam.ZDistance/1000))
- {
- return false;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //3. 根据光镜坐标控制样品台移动
- if (!iSEM.SetStageGotoR(currentHole.Position.R))
- {
- //SendMsg("移动失败");
- return false;
- }
- LogManager.AddHardwareLog("移动R轴到="+ currentHole.Position.R.ToString(), true);
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- if(!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))
- {
- //SendMsg("移动失败");
- return false;
- }
- LogManager.AddHardwareLog("移动X轴Y轴=" + currentHole.Position.X.ToString() + " " + currentHole.Position.Y.ToString(), true);
- while (true)
- {
- Thread.Sleep(10000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //4、倾斜观测时恢复Z轴
- if (m_MsParam.Title == true)
- {
- //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
- if (!iSEM.SetStageGotoZ(currentHole.Position.Z))
- {
- return false;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- }
- //5. 控制样品台,调整T轴54度、M/Z/R轴不变
- if (m_MsParam.Is_Photograph == false)
- {
- if (!iSEM.SetStageGotoT(54))
- {
- return false;
- }
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- }
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
-
- #endregion
- return true;
- }
- //初始化拉直操作
- public bool Straighten_Handle()
- {
- //1、自动对焦
- if (!ImageFocus("1-2"))
- {
- LogManager.AddHardwareLog("拉直操作自动对焦失败,程序退出。", true);
- arg.Message = "拉直操作自动对焦失败!";
- arg.State = false;
- SendMsg("1-2");
- return false;
- }
- arg.Message = "拉直操作自动对焦成功!";
- arg.State = true;
- SendMsg("1-2");
- //判断是否停止进程
- if (key_stop)
- {
- return false;
- }
- //1.1大于10000倍进行消像散处理
- float dMag = iSEM.GetMagnification();
- if (dMag > 10000)//需要消像散
- {
- if (!ImageStig("1-2"))
- {
- LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
- arg.Message = "拉直操作自动消像散失败!";
- arg.State = false;
- SendMsg("1-2");
- return false;
- }
- arg.Message = "拉直操作自动消像散成功!";
- arg.State = true;
- SendMsg("1-2");
- }
- //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-3");
- return false;
- }
- arg.Message = "拉直拍照成功!";
- arg.State = true;
- SendMsg("1-3");
- iSEM.CmdFocusRate();
- cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
- //3、华为接口,获取旋转角度
- float degree = 0;
- int direction = 0;
- int state = 1;
- wr.Img_OffsetAngle_Direction(fileName0, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out degree, out direction, out state);
- LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "初始化拉直角度=" + degree.ToString(), true);
- if (state == 0)
- {
- arg.Message = "华为接口参数state返回为零";
- arg.State = false;
- SendMsg("1-4");
- if (hand_intervene == 1)
- {
- if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- if (direction == 2)
- {
- degree = -degree;
- }
- #region//暂时不用这个拉直
- //旋转R轴
- //float getr = iSEM.GetStageAtR();
- //getr = getr + degree;
- //if(getr>R_Max)
- //{
- // getr = getr - 360;
- //}
- //if(getr<R_Min)
- //{
- // getr = getr + 360;
- //}
- //iSEM.SetStageGotoR(getr);
- //while (true)
- //{
- // Thread.Sleep(5000);
- // if (iSEM.GetStageIs() == 0)
- // {
- // break;
- // }
- //}
- //MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
- //////3、拉直
- //float x0 = iSEM.GetStageAtX();
- //float y0 = iSEM.GetStageAtY();
- //float x1 = 0, y1 = 0;
- //Straightening(degree, x_center_point, y_center_point, x0, y0, ref x1, ref y1);
- //if (x1 < X_Min || x1 > X_Max || y1 < Y_Min || y1 > Y_Max)
- //{
- // return false;
- //}
- //iSEM.MoveStageXY(x1, y1);
- #endregion
- //4、拉直,旋转R轴
- iSEM.SetStageDeltaR(degree);
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- arg.Message = "拉直操作完成";
- arg.State = true;
- SendMsg("1-4");
- //华为接口,去掉人工干预
- //MessageBox.Show("拉直操作完成,如果不正确请手动进行拉直然后点击OK按钮。", "确认消息", MessageBoxButtons.OK);
- return true;
- }
- //角度补偿
- public bool TiltCorrection(float a_fAngle)
- {
- if (!iSEM.SetTiltAngleOn())
- {
- return false;
- }
- //恢复原始状态
- if (!iSEM.SetTiltAngle(a_fAngle))
- {
- return false;
- }
- return true;
- }
- //拍图
- public bool GetImage(ImageMode a_mode, String a_fileName)
- {
- //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;
- }
- return true;
- }
- //自动聚焦
- public bool AutoFocus(FocusParam a_param, out int a_nWd, String step_code)
- {
- a_nWd = 0;
- float wd = iSEM.GetWorkingDistance();
- a_nWd = (int)Math.Ceiling(wd * 100000000 + 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);
- iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
- 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);
- iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
- 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;
- }
- //自动消像散 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("FIB对焦参数设置有误,对焦类型错", 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 = "FIB自动对焦";
- 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 = "FIB自动对焦";
- 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)
- {
- //读入Img文件
- if (!File.Exists(a_strImgPath))
- {
- return 0;
- }
- Mat src, gray_src;
- int kernel_size = 3;
- src = Cv2.ImRead(a_strImgPath);
- gray_src = new Mat();
- src.CvtColor(ColorConversionCodes.BGR2GRAY);
- Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
- Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
- Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
- Cv2.Laplacian(src, src, MatType.CV_8UC3, kernel_size);
- Cv2.ConvertScaleAbs(src, src);
- //图像的平均灰度
- double meanValue = 0.0;
- meanValue = Cv2.Mean(src)[0];
- return meanValue;
- }
- //梯度计算
- private double Tenengrad(string a_strImgPath)
- {
- //读入Img文件
- if (!File.Exists(a_strImgPath))
- {
- return 0;
- }
- Mat src;
- src = Cv2.ImRead(a_strImgPath);
- src.CvtColor(ColorConversionCodes.BGR2GRAY);
- Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
- Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
- Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
- Cv2.Sobel(src, src, MatType.CV_8UC1, 1, 1);
- //图像的平均灰度
- double meanValue = 0.0;
- meanValue = Cv2.Mean(src)[0];
- return meanValue;
- }
- //梯度计算
- private double TTgrad(string a_strImgPath)
- {
- //读入Img文件
- if (!File.Exists(a_strImgPath))
- {
- return 0;
- }
- Mat src;
- src = Cv2.ImRead(a_strImgPath);
- src.CvtColor(ColorConversionCodes.BGR2GRAY);
- Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
- Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
- Mat scalex = new Mat();
- Mat scaley = new Mat();
- Cv2.Scharr(src, src, src.Depth(), 1, 0);
- Cv2.ConvertScaleAbs(src, scalex);
- Cv2.Scharr(src, src, src.Depth(), 0, 1);
- Cv2.ConvertScaleAbs(src, scaley);
- Cv2.AddWeighted(scalex, 0.5, scaley, 0.5, 0, src);
- //图像的平均灰度
- double meanValue = 0.0;
- meanValue = Cv2.Mean(src)[0];
- return meanValue;
- }
- //三选二算法
- private void ChooseBest(string a_strImgPath, out int a_nWd)
- {
- a_nWd = -1;
- var files = Directory.GetFiles(a_strImgPath, "*.tif");
- float[] values = new float[files.Length];
- double smax1 = LoGMean(files[0]);
- int wdmax1 = int.Parse(System.IO.Path.GetFileNameWithoutExtension(files[0]));
- double smax2 = Tenengrad(files[0]);
- int wdmax2 = wdmax1;
- double smax3 = TTgrad(files[0]);
- int wdmax3 = wdmax1;
- int x = 0;
- foreach (var file in files)
- {
- int wd = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file));
- double svalue1 = LoGMean(file);
- double svalue2 = Tenengrad(file);
- double svalue3 = TTgrad(file);
- if (smax1 < svalue1)
- {
- smax1 = svalue1;
- wdmax1 = wd;
- }
- if (smax2 < svalue2)
- {
- smax2 = svalue2;
- wdmax2 = wd;
- }
- if (smax3 < svalue3)
- {
- smax3 = svalue3;
- wdmax3 = wd;
- }
- x++;
- }
- //SendMsg("LoG = " + wdmax1.ToString() + ",梯度 = " + wdmax2.ToString() + ",滤波 = " + wdmax3.ToString());
- if (wdmax1 == wdmax2 || wdmax1 == wdmax3)
- {
- a_nWd = wdmax1;
- //SendMsg("焦距 = " + wdmax1.ToString());
- }
- else if (wdmax1 == wdmax2 || wdmax2 == wdmax3)
- {
- a_nWd = wdmax2;
- //SendMsg("焦距 = " + wdmax2.ToString());
- }
- else if (wdmax3 == wdmax2 || wdmax1 == wdmax3)
- {
- a_nWd = wdmax3;
- //SendMsg("焦距 = " + wdmax3.ToString());
- }
- else
- {
- //SendMsg("对焦失败。");
- }
- }
- //移动到像素位置
- bool MoveToPix(float xc, float yc)
- {
- float pixSize = iSEM.GetPixelSize();
- Thread.Sleep(500);
- //0:width, 1:height
- int[] imageSize = iSEM.GetImageStore();
- int width = imageSize[0]/2;
- int height = imageSize[1]/2;
- float deltX = (xc - (float)width) * pixSize;
- float deltY = (yc - (float)height) * pixSize;
- float xpCur = iSEM.GetStageAtX();
- float ypCur = iSEM.GetStageAtY();
- float xpNew = xpCur - deltX;
- float ypNew = ypCur - deltY;
- LogManager.AddHardwareLog("样品台移动信息:deltx=" + deltX.ToString() +
- ",delty=" + deltY.ToString() + ",xpNew=" + xpNew.ToString() + ",ypNew=" + ypNew.ToString(), true);
- if (deltX > 10)//使用移动样品台实现
- {
- if (!iSEM.SetStageGotoX(xpNew))
- {
- return false;
- }
- //判断是否移动完成
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
- //arg.State = true;
- //SendMsg("1-7");
- }
- else//使用移动光束实现
- {
- float beamX = deltX * (float)0.66;
- if (!iSEM.SetBeamShiftX(beamX))
- {
- return false;
- }
- }
- if (deltY > 10)//使用移动样品台实现
- {
- if (!iSEM.SetStageGotoY(ypNew))
- {
- return false;
- }
- //判断是否移动完成
- while (true)
- {
- Thread.Sleep(5000);
- if (iSEM.GetStageIs() == 0)
- {
- break;
- }
- }
- }
- else//使用移动光束实现
- {
- float beamY = deltY * (float)0.671;
- if (!iSEM.SetBeamShiftY(beamY))
- {
- return false;
- }
- }
- return true;
- }
- }
- }
|