Measure.cs 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741
  1. //时间:20200610
  2. //作者:郝爽
  3. //功能:测量线程
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.IO;
  12. using SmartSEMControl;
  13. using MeasureData;
  14. using FileManager;
  15. using WebManager;
  16. using OpenCvSharp;
  17. using Extender;
  18. using DBManager;
  19. namespace MeasureThread
  20. {
  21. //图片模式
  22. public enum ImageMode
  23. {
  24. FIB,
  25. SEM
  26. }
  27. public delegate void ThreadStatusHandler(object sender, ThreadStatusEventArgs e); //声明委托
  28. public delegate void CutHolesStatusHandler(object sender, CutHolesStatusEventArgs e);
  29. public class ThreadStatusEventArgs
  30. {
  31. //状态
  32. public Boolean State
  33. {
  34. get { return m_state; }
  35. set { m_state = value; }
  36. }
  37. private Boolean m_state;
  38. //时间
  39. public DateTime Time
  40. {
  41. get { return m_time; }
  42. set { m_time = value; }
  43. }
  44. private DateTime m_time;
  45. //步骤代码
  46. public String Step_Code
  47. {
  48. get { return step_Code; }
  49. set { step_Code = value; }
  50. }
  51. private String step_Code;
  52. //其他消息
  53. public String Message
  54. {
  55. get { return this.message; }
  56. set { this.message = value; }
  57. }
  58. private String message;
  59. //孔名
  60. public String HoleName
  61. {
  62. get { return this.holeName; }
  63. set { this.holeName = value; }
  64. }
  65. private String holeName;
  66. //图片信息
  67. public class PictureInformation
  68. {
  69. public String Picture_FullPath
  70. {
  71. get { return picture_FullPath; }
  72. set { picture_FullPath = value; }
  73. }
  74. private String picture_FullPath;
  75. public double Work_Voltage
  76. {
  77. get { return work_Voltage; }
  78. set { work_Voltage = value; }
  79. }
  80. private double work_Voltage;
  81. public double Magnification
  82. {
  83. get { return magnification; }
  84. set { magnification = value; }
  85. }
  86. private double magnification;
  87. public double Work_Distance
  88. {
  89. get { return work_Distance; }
  90. set { work_Distance = value; }
  91. }
  92. private double work_Distance;
  93. public String Work_Status
  94. {
  95. get { return work_Status; }
  96. set { work_Status = value; }
  97. }
  98. private String work_Status;
  99. }
  100. //图片信息实例类
  101. public PictureInformation Picture_Information
  102. {
  103. get { return picture_Information; }
  104. set { picture_Information = value; }
  105. }
  106. private PictureInformation picture_Information;
  107. //图像信息
  108. public class ImageInformation
  109. {
  110. public int Method_Name
  111. {
  112. get { return method_Name; }
  113. set { method_Name = value; }
  114. }
  115. private int method_Name;
  116. public Source_Img_Degree_Direction SIDD;
  117. public Cut_Position CP;
  118. public Cut_Success CS;
  119. public Trapezoid_Top_Center_Position TTCP;
  120. public Auto_Foucs AF;
  121. public Auto_Stigmatic AS;
  122. public Center_Position_OffsetAngle_Direction CPOD;
  123. public Measure_Size MS;
  124. public ImageInformation()
  125. {
  126. SIDD = new Source_Img_Degree_Direction();
  127. CP = new Cut_Position();
  128. CS = new Cut_Success();
  129. TTCP = new Trapezoid_Top_Center_Position();
  130. AF = new Auto_Foucs();
  131. AS = new Auto_Stigmatic();
  132. CPOD = new Center_Position_OffsetAngle_Direction();
  133. MS = new Measure_Size();
  134. }
  135. //1-计算原始图像偏移角度及方向
  136. public class Source_Img_Degree_Direction
  137. {
  138. public Boolean Is_Image = false;
  139. public double Degree
  140. {
  141. get { return degree; }
  142. set { degree = value; }
  143. }
  144. private double degree;
  145. public int Direction
  146. {
  147. get { return direction; }
  148. set { direction = value; }
  149. }
  150. private int direction;
  151. public int State
  152. {
  153. get { return state; }
  154. set { state = value; }
  155. }
  156. private int state;
  157. }
  158. //2-计算切割点位置
  159. public class Cut_Position
  160. {
  161. public Boolean Is_Image = false;
  162. public double Offsetx
  163. {
  164. get { return offsetx; }
  165. set { offsetx = value; }
  166. }
  167. private double offsetx;
  168. public double Offsety
  169. {
  170. get { return offsety; }
  171. set { offsety = value; }
  172. }
  173. private double offsety;
  174. public int State
  175. {
  176. get { return state; }
  177. set { state = value; }
  178. }
  179. private int state;
  180. }
  181. //3-是否切割成功
  182. public class Cut_Success
  183. {
  184. public Boolean Is_Image = false;
  185. public int State
  186. {
  187. get { return state; }
  188. set { state = value; }
  189. }
  190. private int state;
  191. }
  192. //4-计算切割后图像梯形区域上边中心点坐标
  193. public class Trapezoid_Top_Center_Position
  194. {
  195. public Boolean Is_Image = false;
  196. public double TopCenterX
  197. {
  198. get { return topCenterX; }
  199. set { topCenterX = value; }
  200. }
  201. private double topCenterX;
  202. public double TopCenterY
  203. {
  204. get { return topCenterY; }
  205. set { topCenterY = value; }
  206. }
  207. private double topCenterY;
  208. public int State
  209. {
  210. get { return state; }
  211. set { state = value; }
  212. }
  213. private int state;
  214. }
  215. //5-自动对焦
  216. public class Auto_Foucs
  217. {
  218. public Boolean Is_Image = true;
  219. public String Img_Path
  220. {
  221. get { return img_Path; }
  222. set { img_Path = value; }
  223. }
  224. private String img_Path;
  225. }
  226. //6-自动像闪
  227. public class Auto_Stigmatic
  228. {
  229. public Boolean Is_Image = true;
  230. public String Img_Path
  231. {
  232. get { return img_Path; }
  233. set { img_Path = value; }
  234. }
  235. private String img_Path;
  236. }
  237. //7-计算切割面区域中心坐标,以及偏移角度及方向
  238. public class Center_Position_OffsetAngle_Direction
  239. {
  240. public Boolean Is_Image = false;
  241. public double CenterX
  242. {
  243. get { return centerX; }
  244. set { centerX = value; }
  245. }
  246. private double centerX;
  247. public double CenterY
  248. {
  249. get { return centerY; }
  250. set { centerY = value; }
  251. }
  252. private double centerY;
  253. public double Degree
  254. {
  255. get { return degree; }
  256. set { degree = value; }
  257. }
  258. private double degree;
  259. public int Direction
  260. {
  261. get { return direction; }
  262. set { direction = value; }
  263. }
  264. private int direction;
  265. public int State
  266. {
  267. get { return state; }
  268. set { state = value; }
  269. }
  270. private int state;
  271. }
  272. //8-测量尺寸
  273. public class Measure_Size
  274. {
  275. public Boolean Is_Image = false;
  276. public int State
  277. {
  278. get { return state; }
  279. set { state = value; }
  280. }
  281. private int state;
  282. }
  283. }
  284. //图像信息实例类
  285. public ImageInformation Image_Information
  286. {
  287. get { return image_Information; }
  288. set { image_Information = value; }
  289. }
  290. private ImageInformation image_Information;
  291. public ThreadStatusEventArgs(string a_State)
  292. {
  293. picture_Information = new PictureInformation();
  294. image_Information = new ImageInformation();
  295. }
  296. }
  297. public class CutHolesStatusEventArgs
  298. {
  299. public string State
  300. {
  301. get { return m_state; }
  302. set { m_state = value; }
  303. }
  304. private string m_state;
  305. public string HoleName
  306. {
  307. get { return m_holeName; }
  308. set { m_holeName = value; }
  309. }
  310. private string m_holeName;
  311. public CutHolesStatusEventArgs(string a_state, string a_holeName)
  312. {
  313. this.m_state = a_state;
  314. this.m_holeName = a_holeName;
  315. }
  316. }
  317. public class Measure
  318. {
  319. /// 图像拉直算法
  320. /// </summary>
  321. /// <param name="Slope">倾斜角度</param>
  322. /// <param name="x0">圆心坐标x</param>
  323. /// <param name="y0">圆心坐标y</param>
  324. /// <param name="x1">倾斜情况下帧图的坐标x</param>
  325. /// <param name="y1">倾斜情况下帧图的坐标y</param>
  326. /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>
  327. /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>
  328. /// <returns></returns>
  329. public bool Straightening(float Slope, float x0, float y0, float x1, float y1, ref float Hx, ref float Hy)
  330. {
  331. try
  332. {
  333. float xr = x1 - x0;//倾斜图到中心的距离差x
  334. float yr = y1 - y0;//倾斜图到中心的距离差y
  335. float R = (float)Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
  336. //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
  337. float k = (float)(Math.Atan(yr / xr) / Math.PI * 180);//x1,y1的直角三角形圆心角度
  338. float k_S = k - Slope;//通过夹角差求x2,y2
  339. //int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);
  340. //int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);
  341. float y2 = (float)(Math.Sin(Math.PI / (180 / k_S)) * R);
  342. float x2 = (float)(Math.Cos(Math.PI / (180 / k_S)) * R);
  343. if (Slope > 0 || Slope < 0)
  344. {
  345. Hx = x0 + x2;
  346. Hy = y0 + y2;
  347. }
  348. else
  349. {
  350. Hx = 0;
  351. Hy = 0;
  352. }
  353. return true;
  354. }
  355. catch (Exception)
  356. {
  357. return false;
  358. }
  359. }
  360. //Web接口类
  361. public WebResult wr = null;
  362. //扫描周期
  363. private float cycle_time = 0;
  364. //人工干预
  365. public int hand_intervene = 2;
  366. //样品台保护值
  367. public float X_Min = 0;
  368. public float X_Max = 0.13f;
  369. public float Y_Min = 0;
  370. public float Y_Max = 0.13f;
  371. public float Z_Min = 0;
  372. public float Z_Max = 0.05f;
  373. public float T_Min = -4;
  374. public float T_Max = 70;
  375. public float R_Min = -380;
  376. public float R_Max = 380;
  377. public float M_Min = 0;
  378. public float M_Max = 0.012f;
  379. public float x_center_point = 65;
  380. public float y_center_point = 65;
  381. public event ThreadStatusHandler SendThreadStatus; // 声明事件
  382. public event CutHolesStatusHandler SendCutHolesStatus; // 声明事件
  383. //定义一个全局的消息类
  384. ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");
  385. //全局只有一个fatorySEM
  386. static FactoryHardware factorySEM = FactoryHardware.Instance;
  387. ISEMControl iSEM = factorySEM.ISEM;
  388. //全局只有一个Extender
  389. static ExtenderInterface factoryExtender = null;// ExtenderInterface.Instance;
  390. IExtenderControl iExtender = null;// factoryExtender.IExtender;
  391. MeasureDB m_MeasDB = null;
  392. //@的作用是不用转义字符\\只打一个就行
  393. const String ImageName0 = @"Straighten.tif"; //传给客户,原始图像,为拉直操作
  394. const String ImageName1 = @"FindCutPostion.tif"; //传给客户,作水平校正
  395. const String ImageName2 = @"FIBCutPostion.tif";//传给客户,找到切割点
  396. const String ImageName31 = @"FIBBefore.tif";
  397. const String ImageName32 = @"FIBAfter.tif";
  398. const String ImageName4 = @"SEMTrapCP.tif";//传给客户,找到已经切割点
  399. const String ImageName5 = @"SEMDegreeTrap.tif";//传给客户,水平校正
  400. const String ImageName6 = @"SEMMagEnd.tif";//传给客户,测量层高
  401. const String ImageName7 = @"EDSImage.tif";//计算感兴趣的区域
  402. const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针
  403. const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针
  404. const String MacoScanPic = "Scan picture.MLF";//一般质量抓图的宏
  405. const String MacoGoodPic = "Good picture.MLF";//高质量抓图的宏
  406. const String MacoExportTif = "Export TIFF.MLF";// 导出有标尺的图像,这个图像为使用工具SmartSEM工具的图像
  407. const String ElyDeposition = @"Deposition.ely"; //沉积
  408. const String ElyCrossSection = @"CrossSection.ely"; //切割
  409. const float fMin = (float)0.0000002; //单位是米
  410. public Boolean key_stop = false;
  411. String focus_path = "";
  412. String FIBfocus_path = "";
  413. String StigX_path = "";
  414. String StigY_path = "";
  415. String EDS_path = "";
  416. String data_path = "";
  417. int m_nWorkHoleNo = -1;
  418. int m_nXrayId = -1;
  419. //测量文件
  420. private MeasureFile m_measureFile;
  421. public MeasureFile MeasureFile
  422. {
  423. get { return this.m_measureFile; }
  424. set { this.m_measureFile = value; }
  425. }
  426. //测量的切割孔
  427. private List<MeasureData.CutHole> m_cutHoles;
  428. public List<MeasureData.CutHole> cutHoles
  429. {
  430. get { return this.m_cutHoles; }
  431. set { this.m_cutHoles = value; }
  432. }
  433. //工作文件夹
  434. private string m_WorkingFolder;
  435. public string WorkingFolder
  436. {
  437. get { return this.m_WorkingFolder; }
  438. set { this.m_WorkingFolder = value; }
  439. }
  440. //程序当前路径
  441. private string m_ProgramFolder = Directory.GetCurrentDirectory();
  442. //线程状态
  443. private ThreadStatus m_ThreadStatus;
  444. public ThreadStatus TStatus
  445. {
  446. get { return this.m_ThreadStatus; }
  447. set { this.m_ThreadStatus = value; }
  448. }
  449. //测量参数
  450. private MeasureParam m_MsParam;
  451. public MeasureParam MeasParam
  452. {
  453. get { return this.m_MsParam; }
  454. set { this.m_MsParam = value; }
  455. }
  456. //构造函数
  457. public Measure(String webServerIP, String webServerPort, String webServerUrl)
  458. {
  459. MeasParam = new MeasureParam();
  460. TStatus = new ThreadStatus();
  461. cutHoles = new List<MeasureData.CutHole>();
  462. //配置远程连接
  463. wr = new WebResult(webServerIP,webServerPort,webServerUrl);
  464. }
  465. //初始化测量业务, 读测量文件,判断是否有可测试的切孔
  466. public bool InitMeas(MeasureFile a_measureFile)
  467. {
  468. m_measureFile = a_measureFile;
  469. List<CutHole> listHoles = m_measureFile.ListCutHole;
  470. foreach (CutHole h in listHoles)
  471. {
  472. if (h.SWITCH == true)
  473. {
  474. m_cutHoles.Add(h);
  475. }
  476. }
  477. if (m_cutHoles.Count == 0)
  478. return false;
  479. this.m_MsParam = m_measureFile.MParam;
  480. if(m_measureFile.MParam.EDS == true)
  481. {
  482. factoryExtender = ExtenderInterface.Instance;
  483. iExtender = factoryExtender.IExtender;
  484. m_MeasDB = new MeasureDB(m_measureFile);
  485. }
  486. return true;
  487. }
  488. public void SendMsg(string step_code)
  489. {
  490. arg.Step_Code = step_code;
  491. arg.Time = DateTime.Now;
  492. SendThreadStatus(this, arg);
  493. }
  494. public void SendCutHoleMsg(string a_state, string a_holeName)
  495. {
  496. CutHolesStatusEventArgs arg = new CutHolesStatusEventArgs(a_state, a_holeName);
  497. arg.HoleName = a_holeName;
  498. arg.State = a_state;
  499. SendCutHolesStatus(this, arg);
  500. }
  501. public bool DoEDS(int a_PointNum, string PointsName)
  502. {
  503. //XrayID记录
  504. EDSParam param = m_measureFile.MParam.EDSP;
  505. double dDwellTime = param.DwellTime;
  506. int nImageType = param.ImageType;
  507. double dScanSizes = param.ScanSize;
  508. iExtender.SetImageAcquistionSetting(dDwellTime, nImageType, dScanSizes);
  509. string path = EDS_path;
  510. iExtender.GrabImage(path + "\\EDSImage.tif", 0, 0, 0, 0, 0);
  511. //送给客户,计算感兴趣的区域
  512. List<Point> listPoints = new List<Point>();
  513. List<List<Segment>> listFeature = new List<List<Segment>>();
  514. //向分析点数据库更新
  515. if (!m_MeasDB.InsetAPoint(a_PointNum, PointsName, EDS_path,listPoints.Count,listFeature.Count))
  516. {
  517. LogManager.AddHardwareLog("插入分析点失败", true);
  518. }
  519. int AreasNo = -1;
  520. if (param.PointMode == true)
  521. {
  522. //点采集
  523. foreach (Point pt in listPoints)
  524. {
  525. long[] XrayData = new long[2000];
  526. Dictionary<string, double> listElement = new Dictionary<string, double>();
  527. iExtender.XrayPointCollectiong(param.PointTime, pt.X, pt.Y, out XrayData, out listElement);
  528. //写入数据库
  529. m_nXrayId++;
  530. m_MeasDB.InsertAPointXay(a_PointNum, m_nXrayId, pt.X, pt.Y, XrayData, listElement);
  531. }
  532. }
  533. if (param.AreaMode == true)
  534. {
  535. //面采集
  536. long[] XrayData = new long[2000];
  537. Dictionary<string, double> listElement = new Dictionary<string, double>();
  538. foreach (List < Segment> listSeg in listFeature)
  539. {
  540. iExtender.XrayAreaCollectiong(param.AreaTime, listSeg, out XrayData, out listElement);
  541. //写入数据库
  542. m_nXrayId++;
  543. AreasNo++;
  544. m_MeasDB.InsertAAreaXay(a_PointNum, m_nXrayId, AreasNo, listSeg, XrayData, listElement);
  545. }
  546. }
  547. return true;
  548. }
  549. //测量流程
  550. public void DoMeasure()
  551. {
  552. //创建线程的测量状态的更新
  553. this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);
  554. if (SendThreadStatus != null)
  555. {
  556. //SendMsg("开始测量。");
  557. }
  558. LogManager.AddHardwareLog("开始测量",true);
  559. //检查硬件连接是否正常
  560. if (!ConnectHardware())
  561. {
  562. //SendMsg("连接硬件失败。");
  563. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  564. return;
  565. }
  566. //设置工作文件夹
  567. if (!SetWorkingFolderStr())
  568. {
  569. //SendMsg("设置工作文件夹失败");
  570. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  571. return;
  572. }
  573. //增加EDS控制
  574. //将停止键复位
  575. key_stop = false;
  576. //开始测量就将模式设置为SEM
  577. if (!iSEM.CmdFIBModeSEM())
  578. {
  579. LogManager.AddHardwareLog("开始切换到SEM模式失败,程序退出。", true);
  580. return;
  581. }
  582. arg.Picture_Information.Work_Status = "SEM";
  583. //自动亮度对比度
  584. if (!iSEM.SetAutoVideoBrightnessAndContrast())
  585. {
  586. LogManager.AddHardwareLog("开始设置自动亮度、对比度失败,程序退出。", true);
  587. return;
  588. }
  589. Thread.Sleep(5000);
  590. //设置扫描周期
  591. iSEM.CmdFocusRate();
  592. cycle_time = iSEM.GetCycleTime();
  593. if (cycle_time == 0)
  594. {
  595. LogManager.AddHardwareLog("获取扫描周期时间失败", true);
  596. return;
  597. }
  598. for (int i = 0; i < m_cutHoles.Count; i++)
  599. {
  600. //记录测量序号和孔名
  601. m_nWorkHoleNo = i;
  602. arg.HoleName = m_cutHoles[i].HoleName;
  603. //最终数据存放目录
  604. data_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName;
  605. //对焦数据存放目录
  606. focus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\Focus";
  607. m_MsParam.AutoFocus.Path = focus_path;
  608. if (!Directory.Exists(focus_path))
  609. {
  610. Directory.CreateDirectory(focus_path);
  611. }
  612. //FIB对焦数据存放目录
  613. FIBfocus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\FIBFocus";
  614. m_MsParam.FIBFocus.Path = FIBfocus_path;
  615. if (!Directory.Exists(FIBfocus_path))
  616. {
  617. Directory.CreateDirectory(FIBfocus_path);
  618. }
  619. //StigX数据存放目录
  620. StigX_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigX";
  621. m_MsParam.AutoStigX.Path = StigX_path;
  622. if (!Directory.Exists(StigX_path))
  623. {
  624. Directory.CreateDirectory(StigX_path);
  625. }
  626. //StigY数据存放目录
  627. StigY_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigY";
  628. m_MsParam.AutoStigY.Path = StigY_path;
  629. if (!Directory.Exists(StigY_path))
  630. {
  631. Directory.CreateDirectory(StigY_path);
  632. }
  633. //EDS数据存放路径
  634. if (m_measureFile.MParam.EDS == true)
  635. {
  636. EDS_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\EDS";
  637. m_MsParam.AutoStigY.Path = EDS_path;
  638. if (!Directory.Exists(EDS_path))
  639. {
  640. Directory.CreateDirectory(EDS_path);
  641. }
  642. }
  643. //判断孔状态
  644. if (m_cutHoles[i].STATE != State.Ready)
  645. {
  646. continue;
  647. }
  648. //开始循环工作
  649. if (i == 0)
  650. {
  651. m_cutHoles[i].START = DateTime.Now;
  652. //切孔操作-开始
  653. m_cutHoles[i].STATE = State.InProcess;
  654. //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  655. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  656. //1、移动样品台到第一个观测点,先移动R轴,再移动XY轴
  657. if (!iSEM.SetStageGotoR(m_cutHoles[0].Position.R))
  658. {
  659. LogManager.AddHardwareLog("样品台R轴移动失败。", true);
  660. return;
  661. }
  662. while (true)
  663. {
  664. Thread.Sleep(5000);
  665. if (iSEM.GetStageIs() == 0)
  666. {
  667. break;
  668. }
  669. }
  670. //判断是否停止进程
  671. if (key_stop)
  672. {
  673. return;
  674. }
  675. //移动XY轴
  676. if (!iSEM.MoveStageXY(m_cutHoles[0].Position.X, m_cutHoles[0].Position.Y))
  677. {
  678. LogManager.AddHardwareLog("样品台XY轴移动失败。", true);
  679. return;
  680. }
  681. while (true)
  682. {
  683. Thread.Sleep(5000);
  684. if (iSEM.GetStageIs() == 0)
  685. {
  686. break;
  687. }
  688. }
  689. //判断是否停止进程
  690. if (key_stop)
  691. {
  692. return;
  693. }
  694. //成功
  695. if (FirstHole())
  696. {
  697. //保存文件,将测量状态更改
  698. m_cutHoles[i].STATE = State.Success;
  699. m_cutHoles[i].END = DateTime.Now;
  700. m_measureFile.Save();
  701. }
  702. //失败
  703. else
  704. {
  705. m_cutHoles[i].STATE = State.Failed;
  706. m_cutHoles[i].END = DateTime.Now;
  707. m_measureFile.Save();
  708. }
  709. //切孔操作-完成
  710. //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  711. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  712. }
  713. else
  714. {
  715. //其他孔测量之前的初始化
  716. if (!OtherHole_Init())
  717. {
  718. arg.Message = "当前测量点位置初始失败!";
  719. arg.State = false;
  720. SendMsg("0-1");
  721. Thread.Sleep(5000);
  722. continue;
  723. }
  724. //其他孔的测量
  725. m_cutHoles[i].START = DateTime.Now;
  726. //非第一个孔的测试
  727. //SendMsg("第" + i.ToString() + "个切孔开始测量");
  728. //切孔操作-开始
  729. //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  730. m_cutHoles[i].STATE = State.InProcess;
  731. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  732. //其他孔的测试
  733. //成功
  734. if (OtherHole())
  735. {
  736. //保存文件,将测量状态更改
  737. m_cutHoles[i].STATE = State.Success;
  738. m_cutHoles[i].END = DateTime.Now;
  739. m_measureFile.Save();
  740. }
  741. //失败
  742. else
  743. {
  744. m_cutHoles[i].STATE = State.Failed;
  745. m_cutHoles[i].END = DateTime.Now;
  746. m_measureFile.Save();
  747. }
  748. //切孔操作-完成
  749. //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  750. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  751. }
  752. if(key_stop)
  753. {
  754. m_cutHoles[i].END = DateTime.Now;
  755. m_cutHoles[i].STATE = State.Ready;
  756. m_measureFile.Save();
  757. arg.Message = "用户停止测量";
  758. SendMsg("0-0");
  759. break;
  760. }
  761. }
  762. }
  763. //检查硬件连接是否正常
  764. public bool ConnectHardware()
  765. {
  766. //返回硬件的连接状态
  767. return iSEM.ConnectStatus();
  768. }
  769. //设置工作文件夹
  770. public bool SetWorkingFolderStr()
  771. {
  772. WorkingFolder = m_measureFile.FilePath;
  773. return true;
  774. }
  775. //插入PT针
  776. public bool InsertPT()
  777. {
  778. string fn = m_ProgramFolder + "\\Macro\\" + MacoInsertPt;
  779. //SendMsg("调用宏插入PT针宏文件" + fn);
  780. iSEM.CMDMCFFilename(fn);
  781. //延时1s??
  782. Thread.Sleep(1000);
  783. return true;
  784. }
  785. //撤出PT针
  786. public bool RetractPT()
  787. {
  788. string fn = m_ProgramFolder + "\\Macro\\" + MacoRetractPt;
  789. //SendMsg("调用宏撤出PT针宏文件" + fn);
  790. iSEM.CMDMCFFilename(fn);
  791. //延时1s??
  792. Thread.Sleep(1000);
  793. return true;
  794. }
  795. //PT沉积
  796. public bool PTWork()
  797. {
  798. //执行PT沉积的ELY文件
  799. //string fn = m_ProgramFolder + "\\Macro\\" + ElyDeposition;
  800. //SendMsg("执行PT沉积Ely文件:" + fn);
  801. if (!ExcuteEly(m_MsParam.PTTemp))
  802. {
  803. return false;
  804. }
  805. //等待沉积完成
  806. while (true)
  807. {
  808. Thread.Sleep(10000);
  809. if (iSEM.GetFIBMode() == 0)
  810. {
  811. break;
  812. }
  813. }
  814. return true;
  815. }
  816. //FIB切割
  817. public bool FIBWork()
  818. {
  819. //执行PT沉积的ELY文件
  820. //string fn = m_ProgramFolder + "\\Macro\\" + ElyCrossSection;
  821. //SendMsg("执行FIB切割Ely文件:" + fn);
  822. if (!ExcuteEly(m_MsParam.FIBTemp))
  823. {
  824. return false;
  825. }
  826. //等待切割完成
  827. while (true)
  828. {
  829. Thread.Sleep(10000);
  830. if (iSEM.GetFIBMode() == 0)
  831. {
  832. break;
  833. }
  834. }
  835. return true;
  836. }
  837. //执行ELY文件的步骤
  838. public bool ExcuteEly(string a_filename)
  839. {
  840. //执行ELy文件有三个动作
  841. //1. 选择ELY文件
  842. //SendMsg("选择ELY文件");
  843. if (!iSEM.CmdFIBLoadELY(a_filename))
  844. {
  845. //SendMsg("选择ELY文件失败");
  846. return false;
  847. }
  848. Thread.Sleep(1000);
  849. //2. 确认ELY文件
  850. //SendMsg("确认ELY文件");
  851. if (!iSEM.CmdFIBEXPOSUREELY())
  852. {
  853. //SendMsg("确认ELY文件失败");
  854. return false;
  855. }
  856. Thread.Sleep(1000);
  857. //3. 执行ELY文件
  858. //SendMsg("执行ELY文件");
  859. if (!iSEM.CmdFIBSTARTELY())
  860. {
  861. //SendMsg("执行ELY文件失败");
  862. return false;
  863. }
  864. Thread.Sleep(1000);
  865. return true;
  866. }
  867. //执行自动对焦
  868. public bool ImageFocus(String step_code)
  869. {
  870. if (m_measureFile.MParam.FocusMode == 1)//手动
  871. {
  872. if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  873. {
  874. }
  875. else
  876. {
  877. return false;
  878. }
  879. }
  880. else if(m_measureFile.MParam.FocusMode == 2)//自有自动
  881. {
  882. //郝工增加自动对焦算法
  883. //处理文件夹
  884. if (Directory.Exists(focus_path))
  885. {
  886. Directory.Delete(focus_path, true);
  887. }
  888. Thread.Sleep(3000);
  889. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  890. Thread.Sleep(1000);
  891. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  892. Thread.Sleep(1000);
  893. //再创建文件夹
  894. Directory.CreateDirectory(focus_path);
  895. //1、对焦参数类,2、输出工作距离
  896. int wd = 0;
  897. //20201015 根据当前的工作距离重新计算对焦位置
  898. float currentWd = iSEM.GetWorkingDistance();
  899. m_MsParam.AutoFocus.UP = currentWd * 1000000 - m_MsParam.AutoFocus.Step;
  900. m_MsParam.AutoFocus.Down = currentWd * 1000000 + m_MsParam.AutoFocus.Step;
  901. LogManager.AddHardwareLog("修改对焦参数", true);
  902. AutoFocus(m_MsParam.AutoFocus, out wd, step_code);
  903. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  904. //设置工作距离
  905. iSEM.SetWorkingDistance((float)(wd * 0.00000001));
  906. //设置完工作距离后必须延迟5秒
  907. Thread.Sleep(5000);
  908. //处理图片位置
  909. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  910. }
  911. else if(m_MsParam.FocusMode == 3) //客户自动
  912. {
  913. //后期和客户对接接口
  914. List<string> filenames = new List<string>();
  915. String retfilename = wr.Img_Auto_Focus(filenames);
  916. }
  917. else //蔡司自动对焦
  918. {
  919. iSEM.CmdAutoFocusCoarse();
  920. while(true)
  921. {
  922. Thread.Sleep(10000);
  923. if(0 == iSEM.GetAutoFunction())
  924. {
  925. break;
  926. }
  927. }
  928. iSEM.CmdAutoFocusFine();
  929. while (true)
  930. {
  931. Thread.Sleep(10000);
  932. if (0 == iSEM.GetAutoFunction())
  933. {
  934. break;
  935. }
  936. }
  937. }
  938. return true;
  939. }
  940. //执行自动消像散
  941. public bool ImageStig(String step_code)
  942. {
  943. if (m_measureFile.MParam.FocusMode == 1)//手动
  944. {
  945. if (DialogResult.Yes == MessageBox.Show("图像自动消像散已完成?", "确认消息", MessageBoxButtons.YesNo))
  946. {
  947. }
  948. else
  949. {
  950. return false;
  951. }
  952. }
  953. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  954. {
  955. //郝工增加自动对焦算法
  956. //处理文件夹
  957. if (Directory.Exists(StigX_path))
  958. {
  959. Directory.Delete(StigX_path, true);
  960. }
  961. Thread.Sleep(3000);
  962. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  963. Thread.Sleep(1000);
  964. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  965. Thread.Sleep(1000);
  966. //再创建文件夹
  967. Directory.CreateDirectory(StigX_path);
  968. //1、对焦参数类,2、输出像散值
  969. int stigX = 0;
  970. //根据当前的stigX重新计算像散值
  971. float currentStigX = iSEM.GetAstigmatismX();
  972. //m_MsParam.AutoStigX.Step = 10; //像散的步长为10
  973. m_MsParam.AutoStigX.UP = currentStigX - m_MsParam.AutoStigX.Step;
  974. m_MsParam.AutoStigX.Down = currentStigX + m_MsParam.AutoStigX.Step;
  975. LogManager.AddHardwareLog("修改消像散参数", true);
  976. AutoStig(m_MsParam.AutoStigX, out stigX, step_code);
  977. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  978. //设置工作距离
  979. iSEM.SetAstigmatismX((float)(stigX * 0.01));
  980. //设置完工作距离后必须延迟5秒
  981. Thread.Sleep(5000);
  982. //处理图片位置
  983. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  984. //处理文件夹
  985. if (Directory.Exists(StigY_path))
  986. {
  987. Directory.Delete(StigY_path, true);
  988. }
  989. Thread.Sleep(3000);
  990. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  991. Thread.Sleep(1000);
  992. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  993. Thread.Sleep(1000);
  994. //再创建文件夹
  995. Directory.CreateDirectory(StigY_path);
  996. //1、对焦参数类,2、输出像散值
  997. int stigY = 0;
  998. //根据当前的stigX重新计算像散值
  999. float currentStigY = iSEM.GetAstigmatismY();
  1000. //m_MsParam.AutoStigY.Step = 10; //像散的步长为10
  1001. m_MsParam.AutoStigY.UP = currentStigY - m_MsParam.AutoStigY.Step;
  1002. m_MsParam.AutoStigY.Down = currentStigY + m_MsParam.AutoStigY.Step;
  1003. LogManager.AddHardwareLog("修改消像散参数", true);
  1004. AutoStig(m_MsParam.AutoStigY, out stigY, step_code);
  1005. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  1006. //设置工作距离
  1007. iSEM.SetAstigmatismY((float)(stigY * 0.01));
  1008. //设置完工作距离后必须延迟5秒
  1009. Thread.Sleep(5000);
  1010. }
  1011. else if (m_MsParam.FocusMode == 3) //客户自动
  1012. {
  1013. //后期和客户对接接口
  1014. List<string> filenames = new List<string>();
  1015. String retfilename = wr.Img_Auto_Focus(filenames);
  1016. }
  1017. else //蔡司自动对焦
  1018. {
  1019. iSEM.CmdAutoFocusCoarse();
  1020. while (true)
  1021. {
  1022. Thread.Sleep(10000);
  1023. if (0 == iSEM.GetAutoFunction())
  1024. {
  1025. break;
  1026. }
  1027. }
  1028. iSEM.CmdAutoFocusFine();
  1029. while (true)
  1030. {
  1031. Thread.Sleep(10000);
  1032. if (0 == iSEM.GetAutoFunction())
  1033. {
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. return true;
  1039. }
  1040. //执行FIB自动对焦,FIBFocus
  1041. //执行自动消像散
  1042. public bool FIBFocus(String step_code)
  1043. {
  1044. if (m_measureFile.MParam.FocusMode == 1)//手动
  1045. {
  1046. if (DialogResult.Yes == MessageBox.Show("FIB图像对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  1047. {
  1048. }
  1049. else
  1050. {
  1051. return false;
  1052. }
  1053. }
  1054. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  1055. {
  1056. //郝工增加自动对焦算法
  1057. //处理文件夹
  1058. if (Directory.Exists(FIBfocus_path))
  1059. {
  1060. Directory.Delete(FIBfocus_path, true);
  1061. }
  1062. Thread.Sleep(3000);
  1063. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1064. Thread.Sleep(1000);
  1065. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1066. Thread.Sleep(1000);
  1067. //再创建文件夹
  1068. Directory.CreateDirectory(FIBfocus_path);
  1069. //1、对焦参数类,2、输出对焦值
  1070. int FIBFocus = 0;
  1071. //根据当前的stigX重新计算像散值
  1072. float currentFIBFocus = iSEM.GetFIBObjectivePotential();
  1073. //m_MsParam.FIBFocus.Step = 10; //像散的步长为10
  1074. m_MsParam.FIBFocus.UP = currentFIBFocus - m_MsParam.FIBFocus.Step;
  1075. m_MsParam.FIBFocus.Down = currentFIBFocus + m_MsParam.FIBFocus.Step;
  1076. LogManager.AddHardwareLog("修改FIB自动对焦参数", true);
  1077. AutoFIBFocus(m_MsParam.FIBFocus, out FIBFocus, step_code);
  1078. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  1079. //设置工作距离
  1080. iSEM.SetFIBObjectivePotential((float)(FIBFocus * 0.01));
  1081. //设置完工作距离后必须延迟5秒
  1082. Thread.Sleep(5000);
  1083. //处理图片位置
  1084. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  1085. }
  1086. else if (m_MsParam.FocusMode == 3) //客户自动
  1087. {
  1088. //后期和客户对接接口
  1089. List<string> filenames = new List<string>();
  1090. String retfilename = wr.Img_Auto_Focus(filenames);
  1091. }
  1092. else //蔡司自动对焦
  1093. {
  1094. iSEM.CmdAutoFocusCoarse();
  1095. while (true)
  1096. {
  1097. Thread.Sleep(10000);
  1098. if (0 == iSEM.GetAutoFunction())
  1099. {
  1100. break;
  1101. }
  1102. }
  1103. iSEM.CmdAutoFocusFine();
  1104. while (true)
  1105. {
  1106. Thread.Sleep(10000);
  1107. if (0 == iSEM.GetAutoFunction())
  1108. {
  1109. break;
  1110. }
  1111. }
  1112. }
  1113. return true;
  1114. }
  1115. /// <summary>
  1116. ///13. 自动 定位功能,沉积
  1117. /// </summary>
  1118. /// <returns></returns>
  1119. public bool GetPoistion()
  1120. {
  1121. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1122. int state = 1;
  1123. //1.控制SEM放大600X
  1124. if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
  1125. {
  1126. arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
  1127. arg.State = false;
  1128. SendMsg("1-5");
  1129. return false;
  1130. }
  1131. if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification))
  1132. {
  1133. arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍失败";
  1134. arg.State = false;
  1135. SendMsg("1-5");
  1136. return false;
  1137. }
  1138. arg.State = true;
  1139. arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍成功";
  1140. SendMsg("1-5");
  1141. //判断是否停止进程
  1142. if (key_stop)
  1143. {
  1144. return false;
  1145. }
  1146. //2.控制SEM自动对焦、亮度、对比度
  1147. if(ImageFocus("1-6"))
  1148. {
  1149. arg.Message = "自动对焦完成";
  1150. arg.State = true;
  1151. SendMsg("1-6");
  1152. }
  1153. else
  1154. {
  1155. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1156. arg.Message = "自动对焦失败";
  1157. arg.State = false;
  1158. SendMsg("1-6");
  1159. return false;
  1160. }
  1161. //判断是否停止进程
  1162. if (key_stop)
  1163. {
  1164. return false;
  1165. }
  1166. //1.1大于10000倍进行消像散处理
  1167. float dMag = iSEM.GetMagnification();
  1168. if (dMag > 10000)//需要消像散
  1169. {
  1170. if (!ImageStig("1-6"))
  1171. {
  1172. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1173. arg.Message = "拉直操作自动消像散失败!";
  1174. arg.State = false;
  1175. SendMsg("1-6");
  1176. return false;
  1177. }
  1178. arg.Message = "拉直操作自动消像散成功!";
  1179. arg.State = true;
  1180. SendMsg("1-6");
  1181. }
  1182. //3.控制SEM拍照,找到切割位置
  1183. String fileName1 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Location_Magnification.ToString("0") + "_" + ImageName1;
  1184. arg.Picture_Information.Picture_FullPath = fileName1;
  1185. arg.Picture_Information.Work_Voltage = m_MsParam.Location_Voltage;
  1186. arg.Picture_Information.Magnification = m_MsParam.Location_Magnification;
  1187. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1188. Thread.Sleep(1000);
  1189. //拍照前改变速度,延时
  1190. iSEM.CmdSaveRate();
  1191. cycle_time = iSEM.GetCycleTime();
  1192. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1193. if (!GetImage(ImageMode.SEM, fileName1))
  1194. {
  1195. arg.Message = "SEM拍照失败";
  1196. arg.State = false;
  1197. SendMsg("1-7");
  1198. return false;
  1199. }
  1200. arg.State = true;
  1201. arg.Message = "SEM拍照成功";
  1202. SendMsg("1-7");
  1203. iSEM.CmdFocusRate();
  1204. cycle_time = iSEM.GetCycleTime();
  1205. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1206. //判断是否停止进程
  1207. if (key_stop)
  1208. {
  1209. return false;
  1210. }
  1211. //判断是否为仅拍照,不是则执行FIB操作
  1212. if (!m_MsParam.Is_Photograph)
  1213. {
  1214. //6.设置FIB拍照参数——扫描时间、束流等
  1215. //7.控制FIB自动亮度、对比度
  1216. if (!iSEM.CmdFIBModeFIB())
  1217. {
  1218. arg.Message = "FIB模式切换失败";
  1219. arg.State = false;
  1220. SendMsg("1-8");
  1221. return false;
  1222. }
  1223. arg.State = true;
  1224. arg.Picture_Information.Work_Status = "FIB";
  1225. arg.Message = "FIB模式切换成功";
  1226. SendMsg("1-8");
  1227. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1228. //判断是否停止进程
  1229. if (key_stop)
  1230. {
  1231. return false;
  1232. }
  1233. //8.控制FIB拍照
  1234. //9.保存照片======更改路径
  1235. String fileName2 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString("0") + "_" + ImageName2;
  1236. arg.Picture_Information.Picture_FullPath = fileName2;
  1237. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1238. Thread.Sleep(1000);
  1239. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1240. Thread.Sleep(1000);
  1241. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1242. Thread.Sleep(1000);
  1243. //FIB的放大位数,将来会改
  1244. if(!iSEM.SetFIBMagnification(m_MsParam.FIB_Magnification))
  1245. {
  1246. arg.Message = "FIB放大倍数设置失败";
  1247. arg.State = false;
  1248. SendMsg("1-9");
  1249. return false;
  1250. }
  1251. arg.Message = "FIB放大倍数设置成功";
  1252. arg.State = true;
  1253. SendMsg("1-9");
  1254. Thread.Sleep(1000);
  1255. //增加FIB对焦
  1256. //2.控制SEM自动对焦、亮度、对比度
  1257. if (FIBFocus("1-10"))
  1258. {
  1259. arg.Message = "自动FIB对焦完成";
  1260. arg.State = true;
  1261. SendMsg("1-10");
  1262. }
  1263. else
  1264. {
  1265. LogManager.AddHardwareLog("设置观测点后,自动FIB对焦失败。", true);
  1266. arg.Message = "自动FIB对焦失败";
  1267. arg.State = false;
  1268. SendMsg("1-10");
  1269. return false;
  1270. }
  1271. //判断是否停止进程
  1272. if (key_stop)
  1273. {
  1274. return false;
  1275. }
  1276. //拍照前改变速度,延时
  1277. iSEM.CmdSaveRate();
  1278. cycle_time = iSEM.GetCycleTime();
  1279. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1280. if (!GetImage(ImageMode.FIB, fileName2))
  1281. {
  1282. arg.Message = "FIB拍照失败";
  1283. arg.State = false;
  1284. SendMsg("1-11");
  1285. return false;
  1286. }
  1287. arg.State = true;
  1288. arg.Message = "FIB拍照成功";
  1289. SendMsg("1-11");
  1290. iSEM.CmdFocusRate();
  1291. cycle_time = iSEM.GetCycleTime();
  1292. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1293. //判断是否停止进程
  1294. if (key_stop)
  1295. {
  1296. return false;
  1297. }
  1298. //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
  1299. LogManager.AddHardwareLog("准备移动样品台", true);
  1300. LogManager.AddHardwareLog("文件名="+fileName2, true);
  1301. LogManager.AddHardwareLog("样品类型="+m_MsParam.SampleName, true);
  1302. LogManager.AddHardwareLog("供应商名称="+m_MsParam.Firm, true);
  1303. wr.Img_Cut_Position(fileName2, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
  1304. LogManager.AddHardwareLog("FIB梯形左上角和右上角位置信息= " + x1.ToString() + ", " + y1.ToString() + ", " + x2.ToString() + ", " + y2.ToString(), true);
  1305. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1306. if (state == 1)
  1307. {
  1308. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1309. float xc = (x1 + x2) / 2;
  1310. float yc = (y1 + y2) / 2;
  1311. if (!MoveToPix(xc,yc))
  1312. {
  1313. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  1314. arg.State = false;
  1315. SendMsg("1-12");
  1316. return false;
  1317. }
  1318. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置成功";
  1319. arg.State = true;
  1320. SendMsg("1-12");
  1321. if (hand_intervene == 1)
  1322. {
  1323. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1324. }
  1325. }
  1326. else
  1327. {
  1328. arg.Message = "图像接口参数state返回值为零";
  1329. arg.State = false;
  1330. SendMsg("1-12");
  1331. if(hand_intervene==1)
  1332. {
  1333. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1334. {
  1335. return false;
  1336. }
  1337. }
  1338. else
  1339. {
  1340. return false;
  1341. }
  1342. }
  1343. //判断是否停止进程
  1344. if (key_stop)
  1345. {
  1346. return false;
  1347. }
  1348. //11.自动工具样品类型参数确定是否需要PT沉积
  1349. if (m_MsParam.PT)
  1350. {
  1351. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1352. //第10步已经移动好位置
  1353. //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确
  1354. //x0 = iSEM.GetStageAtX();
  1355. //y0 = iSEM.GetStageAtY();
  1356. //if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
  1357. //{
  1358. // arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败";
  1359. // arg.State = false;
  1360. // SendMsg("1-1");
  1361. // return false;
  1362. //}
  1363. //arg.State = true;
  1364. //arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动成功";
  1365. //SendMsg("1-8");
  1366. //判断是否停止进程
  1367. //if (key_stop)
  1368. //{
  1369. // return false;
  1370. //}
  1371. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  1372. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1373. {
  1374. if (!InsertPT())
  1375. {
  1376. arg.Message = "插入PT针失败";
  1377. arg.State = false;
  1378. SendMsg("1-13");
  1379. return false;
  1380. }
  1381. arg.State = true;
  1382. arg.Message = "插入PT针成功";
  1383. SendMsg("1-13");
  1384. }
  1385. //判断是否停止进程
  1386. if (key_stop)
  1387. {
  1388. return false;
  1389. }
  1390. //3. 根据坐标进行PT沉积
  1391. if (!PTWork())
  1392. {
  1393. arg.Message = "PT沉积失败";
  1394. arg.State = false;
  1395. SendMsg("1-14");
  1396. return false;
  1397. }
  1398. arg.State = true;
  1399. arg.Message = "PT沉积成功";
  1400. SendMsg("1-14");
  1401. //判断是否停止进程
  1402. if (key_stop)
  1403. {
  1404. return false;
  1405. }
  1406. //15.根据样品类型决定是否撤出PT针
  1407. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1408. {
  1409. if (!RetractPT())
  1410. {
  1411. arg.Message = "撤出PT针失败";
  1412. arg.State = false;
  1413. SendMsg("1-15");
  1414. return false;
  1415. }
  1416. arg.State = true;
  1417. arg.Message = "撤出PT针成功";
  1418. SendMsg("1-15");
  1419. }
  1420. //判断是否停止进程
  1421. if (key_stop)
  1422. {
  1423. return false;
  1424. }
  1425. }
  1426. }
  1427. //12.根据梯形坐标控制FIB调整到中心位置
  1428. //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确
  1429. //以上两步已经将程序移动到11内部去做
  1430. //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库
  1431. float[] firstPosition = iSEM.GetStagePosition();
  1432. m_cutHoles[0].Position.X = firstPosition[0];
  1433. m_cutHoles[0].Position.Y = firstPosition[1];
  1434. m_cutHoles[0].Position.Z = firstPosition[2];
  1435. m_cutHoles[0].Position.T = firstPosition[3];
  1436. m_cutHoles[0].Position.R = firstPosition[4];
  1437. m_cutHoles[0].Position.M = firstPosition[5];
  1438. //这里要调用文件保存功能
  1439. arg.Message = "坐标1(" + firstPosition[0].ToString() + ","
  1440. + firstPosition[1].ToString() + ","
  1441. + firstPosition[2].ToString() + ","
  1442. + firstPosition[3].ToString() + ","
  1443. + firstPosition[4].ToString() + ","
  1444. + firstPosition[5].ToString() + ")";
  1445. arg.State = true;
  1446. SendMsg("1-16");
  1447. //判断是否停止进程
  1448. if (key_stop)
  1449. {
  1450. return false;
  1451. }
  1452. return true;
  1453. }
  1454. /// <summary>
  1455. /// 14. FIB切割
  1456. /// </summary>
  1457. /// <returns></returns>
  1458. public bool FIBCross()
  1459. {
  1460. int state = 0;
  1461. //这里不知道PT沉积之后是否变回SEM,所以这里加一句切换到FIB命令
  1462. if (!iSEM.CmdFIBModeFIB())
  1463. {
  1464. return false;
  1465. }
  1466. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  1467. //增加FIB对焦
  1468. if (FIBFocus("1-17"))
  1469. {
  1470. arg.Message = "FIB自动对焦完成";
  1471. arg.State = true;
  1472. SendMsg("1-17");
  1473. }
  1474. else
  1475. {
  1476. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1477. arg.Message = "自动对焦失败";
  1478. arg.State = false;
  1479. SendMsg("1-17");
  1480. return false;
  1481. }
  1482. //判断是否停止进程
  1483. if (key_stop)
  1484. {
  1485. return false;
  1486. }
  1487. String fileName31 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName31;
  1488. arg.Picture_Information.Picture_FullPath = fileName31;
  1489. arg.Picture_Information.Work_Status = "FIB";
  1490. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1491. Thread.Sleep(1000);
  1492. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1493. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1494. Thread.Sleep(1000);
  1495. //拍照前改变速度,延时
  1496. iSEM.CmdSaveRate();
  1497. cycle_time = iSEM.GetCycleTime();
  1498. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1499. if (!GetImage(ImageMode.SEM, fileName31))
  1500. {
  1501. arg.Message = "FIB切割前拍照SEM模式照失败";
  1502. arg.State = false;
  1503. SendMsg("1-18");
  1504. return false;
  1505. }
  1506. arg.State = true;
  1507. arg.Message = "FIB切割前拍照SEM模式照成功";
  1508. SendMsg("1-18");
  1509. iSEM.CmdFocusRate();
  1510. cycle_time = iSEM.GetCycleTime();
  1511. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1512. //判断是否停止进程
  1513. if (key_stop)
  1514. {
  1515. return false;
  1516. }
  1517. //14.自动控制FIB切割
  1518. //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  1519. //2.控制FIB进行切割
  1520. //以上1、2步全部用ELY文件代替
  1521. if (!FIBWork())
  1522. {
  1523. arg.Message = "FIB切割失败";
  1524. arg.State = false;
  1525. SendMsg("1-19");
  1526. return false;
  1527. }
  1528. arg.State = true;
  1529. arg.Message = "FIB切割成功";
  1530. SendMsg("1-19");
  1531. Thread.Sleep(1000);
  1532. //判断是否停止进程
  1533. if (key_stop)
  1534. {
  1535. return false;
  1536. }
  1537. //切割后会切换到SEM,所以需要再切换回FIB模式
  1538. if (!iSEM.CmdFIBModeFIB())
  1539. {
  1540. return false;
  1541. }
  1542. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1543. //3.控制FIB拍照600X
  1544. //底层没有控制方法。
  1545. //4.保存图片
  1546. String fileName32 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName32;
  1547. arg.Picture_Information.Picture_FullPath = fileName32;
  1548. arg.Picture_Information.Work_Status = "FIB";
  1549. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1550. Thread.Sleep(1000);
  1551. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1552. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1553. Thread.Sleep(1000);
  1554. //增加FIB对焦
  1555. if (FIBFocus("1-20"))
  1556. {
  1557. arg.Message = "FIB自动对焦完成";
  1558. arg.State = true;
  1559. SendMsg("1-20");
  1560. }
  1561. else
  1562. {
  1563. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1564. arg.Message = "自动对焦失败";
  1565. arg.State = false;
  1566. SendMsg("1-20");
  1567. return false;
  1568. }
  1569. //拍照前改变速度,延时
  1570. iSEM.CmdSaveRate();
  1571. cycle_time = iSEM.GetCycleTime();
  1572. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1573. if (!GetImage(ImageMode.FIB, fileName32))
  1574. {
  1575. arg.Message = "FIB切割后拍照失败";
  1576. arg.State = false;
  1577. SendMsg("1-21");
  1578. return false;
  1579. }
  1580. arg.State = true;
  1581. arg.Message = "FIB切割后拍照成功";
  1582. SendMsg("1-21");
  1583. iSEM.CmdFocusRate();
  1584. cycle_time = iSEM.GetCycleTime();
  1585. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1586. //判断是否停止进程
  1587. if (key_stop)
  1588. {
  1589. return false;
  1590. }
  1591. //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
  1592. wr.Img_Cut_Success(fileName31, fileName32, out state);
  1593. if(state == 0)
  1594. {
  1595. arg.Message = "图像接口参数state返回值为零";
  1596. arg.State = false;
  1597. SendMsg("1-22");
  1598. if (hand_intervene == 1)
  1599. {
  1600. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1601. {
  1602. return false;
  1603. }
  1604. }
  1605. else
  1606. {
  1607. return false;
  1608. }
  1609. }
  1610. arg.State = true;
  1611. arg.Message = "FIB切割校验成功";
  1612. SendMsg("1-22");
  1613. //判断是否停止进程
  1614. if (key_stop)
  1615. {
  1616. return false;
  1617. }
  1618. return true;
  1619. }
  1620. /// <summary>
  1621. /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  1622. /// </summary>
  1623. /// <returns></returns>
  1624. public bool FindCross()
  1625. {
  1626. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1627. int state = 0;
  1628. //切换到SEM模式
  1629. if (!iSEM.CmdFIBModeSEM())
  1630. {
  1631. arg.Message = "SEM模式切换失败";
  1632. arg.State = false;
  1633. SendMsg("1-23");
  1634. return false;
  1635. }
  1636. arg.State = true;
  1637. arg.Message = "SEM模式切换成功";
  1638. SendMsg("1-23");
  1639. arg.Picture_Information.Work_Status = "SEM";
  1640. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1641. //判断是否停止进程
  1642. if (key_stop)
  1643. {
  1644. return false;
  1645. }
  1646. //1.控制SEM放大到300倍
  1647. if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
  1648. {
  1649. arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
  1650. arg.State = false;
  1651. SendMsg("1-24");
  1652. return false;
  1653. }
  1654. if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification/3))
  1655. {
  1656. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification / 3).ToString("0.0") + "倍失败";
  1657. arg.State = false;
  1658. SendMsg("1-24");
  1659. return false;
  1660. }
  1661. arg.State = true;
  1662. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification/3).ToString("0.0") + "倍成功";
  1663. SendMsg("1-24");
  1664. //判断是否停止进程
  1665. if (key_stop)
  1666. {
  1667. return false;
  1668. }
  1669. //3.控制SEM拍照
  1670. String fileName4 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + (m_MsParam.Location_Magnification/3).ToString("0") + "_" + ImageName4;
  1671. arg.Picture_Information.Picture_FullPath = fileName4;
  1672. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1673. Thread.Sleep(1000);
  1674. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1675. Thread.Sleep(1000);
  1676. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1677. Thread.Sleep(1000);
  1678. //拍照前改变速度,延时
  1679. iSEM.CmdSaveRate();
  1680. cycle_time = iSEM.GetCycleTime();
  1681. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1682. if (!GetImage(ImageMode.SEM, fileName4))
  1683. {
  1684. arg.State = false;
  1685. arg.Message = "SEM拍照失败";
  1686. SendMsg("1-25");
  1687. return false;
  1688. }
  1689. arg.State = true;
  1690. arg.Message = "SEM拍照成功";
  1691. SendMsg("1-25");
  1692. iSEM.CmdFocusRate();
  1693. cycle_time = iSEM.GetCycleTime();
  1694. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1695. //判断是否停止进程
  1696. if (key_stop)
  1697. {
  1698. return false;
  1699. }
  1700. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  1701. //5.根据坐标控制SEM移动到切孔位置,居中
  1702. LogManager.AddHardwareLog("准备移动样品台", true);
  1703. LogManager.AddHardwareLog("文件名=" + fileName4, true);
  1704. wr.Img_Trapezoid_Top_Center_Position(fileName4,out x2, out y2, out state);
  1705. LogManager.AddHardwareLog("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
  1706. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1707. if (state == 1)
  1708. {
  1709. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1710. if (!MoveToPix(x2, y2))
  1711. {
  1712. arg.State = false;
  1713. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1714. SendMsg("1-26");
  1715. return false;
  1716. }
  1717. //判断是否移动完成
  1718. while (true)
  1719. {
  1720. Thread.Sleep(5000);
  1721. if (iSEM.GetStageIs() == 0)
  1722. {
  1723. break;
  1724. }
  1725. }
  1726. arg.State = true;
  1727. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1728. SendMsg("1-26");
  1729. if (hand_intervene == 1)
  1730. {
  1731. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1732. }
  1733. }
  1734. else
  1735. {
  1736. arg.Message = "图像接口参数state返回值为零";
  1737. arg.State = false;
  1738. SendMsg("1-26");
  1739. if (hand_intervene == 1)
  1740. {
  1741. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1742. {
  1743. return false;
  1744. }
  1745. }
  1746. else
  1747. {
  1748. return false;
  1749. }
  1750. }
  1751. //判断是否停止进程
  1752. if (key_stop)
  1753. {
  1754. return false;
  1755. }
  1756. return true;
  1757. }
  1758. /// <summary>
  1759. /// 17.自动控制SEM拍截面照
  1760. /// </summary>
  1761. /// <returns></returns>
  1762. public bool ShotSection(ref String image18)
  1763. {
  1764. float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
  1765. int state = 0;
  1766. //1、放大6000倍,放大倍数参数photograph_
  1767. if (!iSEM.SetSEMVoltage(m_MsParam.Photograph_Voltage))
  1768. {
  1769. arg.Message = "电压设置" + m_MsParam.Photograph_Voltage.ToString("0.0") + "失败";
  1770. arg.State = false;
  1771. SendMsg("1-27");
  1772. return false;
  1773. }
  1774. if (!iSEM.SetMagnification(m_MsParam.Photograph_Magnification))
  1775. {
  1776. arg.Message = "放大倍数调整失败";
  1777. arg.State = false;
  1778. SendMsg("1-27");
  1779. return false;
  1780. }
  1781. arg.Message = "放大倍数调整成功";
  1782. arg.State = true;
  1783. SendMsg("1-27");
  1784. //判断是否停止进程
  1785. if (key_stop)
  1786. {
  1787. return false;
  1788. }
  1789. //2.控制SEM自动对焦、亮度、对比度-接口
  1790. if (ImageFocus("1-28"))
  1791. {
  1792. arg.Message = "自动对焦完成";
  1793. arg.State = true;
  1794. SendMsg("1-28");
  1795. }
  1796. else
  1797. {
  1798. arg.Message = "自动对焦失败";
  1799. arg.State = false;
  1800. SendMsg("1-28");
  1801. return false;
  1802. }
  1803. //判断是否停止进程
  1804. if (key_stop)
  1805. {
  1806. return false;
  1807. }
  1808. //1.1大于10000倍进行消像散处理
  1809. float dMag = iSEM.GetMagnification();
  1810. if (dMag > 10000)//需要消像散
  1811. {
  1812. if (!ImageStig("1-28"))
  1813. {
  1814. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1815. arg.Message = "拉直操作自动消像散失败!";
  1816. arg.State = false;
  1817. SendMsg("1-28");
  1818. return false;
  1819. }
  1820. arg.Message = "拉直操作自动消像散成功!";
  1821. arg.State = true;
  1822. SendMsg("1-28");
  1823. }
  1824. //3、设置SEM补偿角度
  1825. if (m_MsParam.Is_Photograph == false)
  1826. {
  1827. if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
  1828. {
  1829. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
  1830. arg.State = false;
  1831. SendMsg("1-29");
  1832. return false;
  1833. }
  1834. arg.State = true;
  1835. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
  1836. SendMsg("1-29");
  1837. Thread.Sleep(2000);
  1838. //判断是否停止进程
  1839. if (key_stop)
  1840. {
  1841. return false;
  1842. }
  1843. }
  1844. //4、拍照,5、保存照片
  1845. String fileName5 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName5;
  1846. arg.Picture_Information.Picture_FullPath = fileName5;
  1847. arg.Picture_Information.Work_Status = "SEM";
  1848. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1849. Thread.Sleep(1000);
  1850. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1851. Thread.Sleep(1000);
  1852. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1853. Thread.Sleep(1000);
  1854. //拍照前改变速度,延时
  1855. iSEM.CmdSaveRate();
  1856. cycle_time = iSEM.GetCycleTime();
  1857. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1858. if (!GetImage(ImageMode.SEM, fileName5))
  1859. {
  1860. arg.Message = "SEM拍照失败";
  1861. arg.State = false;
  1862. SendMsg("1-30");
  1863. return false;
  1864. }
  1865. arg.State = true;
  1866. arg.Message = "SEM拍照成功";
  1867. SendMsg("1-30");
  1868. iSEM.CmdFocusRate();
  1869. cycle_time = iSEM.GetCycleTime();
  1870. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1871. //判断是否停止进程
  1872. if (key_stop)
  1873. {
  1874. return false;
  1875. }
  1876. if (m_MsParam.Is_Photograph == false)
  1877. {
  1878. //8,计算切割面区域偏移角度及方向
  1879. float degree = 0;
  1880. int direction = 0;
  1881. wr.Img_Center_Position_OffsetAngle_Direction(fileName5, out degree, out direction, out state);
  1882. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "计算切割面区域的角度=" + degree.ToString(), true);
  1883. //接口返回像素,*pixelsize,得到坐标点。判断移动方式
  1884. if (state == 1)
  1885. {
  1886. //梯形角度
  1887. iSEM.SetScanRotationOn();
  1888. Thread.Sleep(1000);
  1889. iSEM.SetScanRotation(degree);
  1890. Thread.Sleep(1000);
  1891. arg.State = true;
  1892. arg.Message = "图像接口返回角度为:" + degree.ToString();
  1893. SendMsg("1-31");
  1894. if (hand_intervene == 1)
  1895. {
  1896. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1897. }
  1898. }
  1899. else
  1900. {
  1901. arg.Message = "图像接口参数State返回值为零";
  1902. arg.State = false;
  1903. SendMsg("1-31");
  1904. if(hand_intervene == 1)
  1905. {
  1906. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1907. {
  1908. return false;
  1909. }
  1910. }
  1911. else
  1912. {
  1913. return false;
  1914. }
  1915. }
  1916. //判断是否停止进程
  1917. if (key_stop)
  1918. {
  1919. return false;
  1920. }
  1921. //11、自动对焦。与之前操作相同
  1922. if (ImageFocus("1-32"))
  1923. {
  1924. arg.Message = "自动对焦完成";
  1925. arg.State = true;
  1926. SendMsg("1-32");
  1927. }
  1928. else
  1929. {
  1930. arg.Message = "自动对焦失败";
  1931. arg.State = false;
  1932. SendMsg("1-32");
  1933. return false;
  1934. }
  1935. //判断是否停止进程
  1936. if (key_stop)
  1937. {
  1938. return false;
  1939. }
  1940. //1.1大于10000倍进行消像散处理
  1941. dMag = iSEM.GetMagnification();
  1942. if (dMag > 10000)//需要消像散
  1943. {
  1944. if (!ImageStig("1-32"))
  1945. {
  1946. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1947. arg.Message = "拉直操作自动消像散失败!";
  1948. arg.State = false;
  1949. SendMsg("1-32");
  1950. return false;
  1951. }
  1952. arg.Message = "拉直操作自动消像散成功!";
  1953. arg.State = true;
  1954. SendMsg("1-32");
  1955. }
  1956. //12拍照
  1957. String fileName6 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName6;
  1958. arg.Picture_Information.Picture_FullPath = fileName6;
  1959. arg.Picture_Information.Work_Status = "SEM";
  1960. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1961. Thread.Sleep(1000);
  1962. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1963. Thread.Sleep(1000);
  1964. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1965. Thread.Sleep(1000);
  1966. //拍照前改变速度,延时
  1967. iSEM.CmdSaveRate();
  1968. cycle_time = iSEM.GetCycleTime();
  1969. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1970. if (!GetImage(ImageMode.SEM, fileName6))
  1971. {
  1972. arg.Message = "SEM拍照失败";
  1973. arg.State = false;
  1974. SendMsg("1-33");
  1975. return false;
  1976. }
  1977. arg.State = true;
  1978. image18 = fileName6;
  1979. arg.Message = "SEM拍照成功";
  1980. SendMsg("1-33");
  1981. iSEM.CmdFocusRate();
  1982. cycle_time = iSEM.GetCycleTime();
  1983. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1984. //判断是否停止进程
  1985. if (key_stop)
  1986. {
  1987. return false;
  1988. }
  1989. //华为程序还没有做出来
  1990. }
  1991. //14光束复位和Rotation关闭开关
  1992. arg.Message = "光束复位成功";
  1993. arg.State = true;
  1994. SendMsg("1-36");
  1995. iSEM.SetTiltAngleOff();
  1996. Thread.Sleep(1000);
  1997. iSEM.SetScanRotationOff();
  1998. Thread.Sleep(1000);
  1999. iSEM.SetBeamShiftX(0);
  2000. Thread.Sleep(1000);
  2001. iSEM.SetBeamShiftY(0);
  2002. Thread.Sleep(3000);
  2003. //判断是否停止进程
  2004. if (key_stop)
  2005. {
  2006. return false;
  2007. }
  2008. return true;
  2009. }
  2010. //第一个孔的测试过程
  2011. public bool FirstHole()
  2012. {
  2013. MeasureData.CutHole firstHole = m_cutHoles[0];
  2014. //设置拉直的放大倍数
  2015. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2016. {
  2017. arg.Message = "拉直放大倍数设置失败!";
  2018. arg.State = false;
  2019. SendMsg("1-0");
  2020. return false;
  2021. }
  2022. arg.Message = "拉直放大倍数设置成功!";
  2023. arg.State = true;
  2024. SendMsg("1-0");
  2025. Thread.Sleep(1000);
  2026. //自动化流程-每个点都需要补偿54度
  2027. if (m_MsParam.Is_Photograph == false)
  2028. {
  2029. if (!TiltCorrection(54.0f))
  2030. {
  2031. arg.Message = "角度补偿54度失败!";
  2032. arg.State = false;
  2033. SendMsg("1-1");
  2034. return false;
  2035. }
  2036. Thread.Sleep(2000);
  2037. arg.Message = "角度补偿54度成功!";
  2038. arg.State = true;
  2039. SendMsg("1-1");
  2040. //判断是否停止进程
  2041. if (key_stop)
  2042. {
  2043. return false;
  2044. }
  2045. }
  2046. //2、拉直操作
  2047. if (!Straighten_Handle())
  2048. {
  2049. LogManager.AddHardwareLog("拉直操作失败。", true);
  2050. return false;
  2051. }
  2052. //判断是否停止进程
  2053. if (key_stop)
  2054. {
  2055. return false;
  2056. }
  2057. //13. 自动 定位功能
  2058. if (!GetPoistion())
  2059. {
  2060. LogManager.AddHardwareLog("自动定位失败,程序退出。", true);
  2061. return false;
  2062. }
  2063. //判断是否停止进程
  2064. if (key_stop)
  2065. {
  2066. return false;
  2067. }
  2068. //14.自动控制FIB切割
  2069. if (m_MsParam.Is_Photograph == false)
  2070. {
  2071. if (!FIBCross())
  2072. {
  2073. return false;
  2074. }
  2075. }
  2076. //判断是否停止进程
  2077. if (key_stop)
  2078. {
  2079. return false;
  2080. }
  2081. //16.找到切割位置
  2082. if (m_MsParam.Is_Photograph == false)
  2083. {
  2084. if (!FindCross())
  2085. {
  2086. return false;
  2087. }
  2088. //判断是否停止进程
  2089. if (key_stop)
  2090. {
  2091. return false;
  2092. }
  2093. }
  2094. //将过程17最后的拍照图片提出给18步进行调用
  2095. String img18 = "";
  2096. //17.自动控制SEM拍截面照
  2097. if (!ShotSection(ref img18))
  2098. {
  2099. return false;
  2100. }
  2101. //判断是否停止进程
  2102. if (key_stop)
  2103. {
  2104. return false;
  2105. }
  2106. //18.自动层高分析
  2107. if (m_MsParam.Is_Photograph == false)
  2108. {
  2109. float size = iSEM.GetPixelSize();
  2110. float mag = iSEM.GetMagnification();
  2111. int state = 1;
  2112. //wr.Img_Measure_Size(img18, mag, size, out state);
  2113. if (state == 0)
  2114. {
  2115. arg.Message = "测量尺寸失败";
  2116. arg.State = false;
  2117. SendMsg("1-40");
  2118. return false;
  2119. }
  2120. arg.State = true;
  2121. arg.Message = "测量尺寸成功";
  2122. SendMsg("1-40");
  2123. }
  2124. #region 测试程序
  2125. //最后保存测量数据-测量文件、测量状态,m_cutHoles[i].STATE!=MeasureData.CutHole.State.Success.
  2126. //中间停止更新状态为Unmeasured,过程中return false时,更新状态为failed,保存测量文件
  2127. //if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))
  2128. //{
  2129. // SendMsg("拍摄照片完成");
  2130. // //return true;
  2131. //}
  2132. //else
  2133. //{
  2134. // SendMsg("拍摄照片失败");
  2135. // return false;
  2136. //}
  2137. //SendMsg("图像校正36度");
  2138. ////3.设置SEM角度补偿cos36度
  2139. //if (!TiltCorrection(36))
  2140. //{
  2141. // return false;
  2142. //}
  2143. //Thread.Sleep(3000);
  2144. //string fn;
  2145. //用宏抓一般图
  2146. //Thread.Sleep(5000);
  2147. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2148. //SendMsg("用宏抓一般图" + fn);
  2149. //iSEM.CMDMCFFilename(fn);
  2150. ////延时1s??
  2151. //Thread.Sleep(5000);
  2152. ////用宏抓好图
  2153. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2154. //SendMsg("用宏抓好图" + fn);
  2155. //iSEM.CMDMCFFilename(fn);
  2156. ////延时1s??
  2157. //Thread.Sleep(30000);
  2158. //Thread.Sleep(10000);
  2159. //WorkingFolder = m_measureFile.FilePath;
  2160. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2161. //SendMsg("SEM拍照存储到" + fileName6);
  2162. //if (!GetImage(ImageMode.SEM, fileName6))
  2163. //{
  2164. // SendMsg("SEM拍照失败");
  2165. // return false;
  2166. //}
  2167. ////用宏抓标志图
  2168. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2169. //SendMsg("用宏抓标志图" + fn);
  2170. //iSEM.CMDMCFFilename(fn);
  2171. ////延时1s??
  2172. //Thread.Sleep(30000);
  2173. //Thread.Sleep(5000);
  2174. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2175. //SendMsg("用宏抓一般图" + fn);
  2176. //iSEM.CMDMCFFilename(fn);
  2177. ////延时1s??
  2178. //Thread.Sleep(5000);
  2179. //SendMsg("所有图结束");
  2180. ////17.自动控制SEM拍截面照
  2181. //{
  2182. // //1.控制SEM放大到指定参数大小范围,6000x
  2183. // if (!iSEM.SetMagnification(6000))
  2184. // {
  2185. // return false;
  2186. // }
  2187. // //2.控制SEM自动对焦、消像散、亮度、对比度
  2188. // if (!MeasParam.FocusMode)
  2189. // {
  2190. // //弹出手动对焦的窗口
  2191. // }
  2192. // else
  2193. // {
  2194. // //调用自动对焦模块
  2195. // }
  2196. // //3.设置SEM角度补偿cos36度
  2197. // if (!TiltCorrection(36))
  2198. // {
  2199. // return false;
  2200. // }
  2201. // //4.控制SEM拍照
  2202. // //5.保存照片4
  2203. // String fileName5 = WorkingFolder + ImageName5;
  2204. // if (!GetImage(ImageMode.SEM, fileName5))
  2205. // {
  2206. // return false;
  2207. // }
  2208. // //6.将照片传给客户,获取偏移坐标
  2209. // float x6 = 0, y6 = 0;
  2210. // float angle1 = 0;
  2211. // float mage = 10000;
  2212. // //7.根据坐标控制SEM移动到分析位置
  2213. // if (!iSEM.MoveStageXY(x6, y6))
  2214. // {
  2215. // return false;
  2216. // }
  2217. // //8.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  2218. // float x7 = iSEM.GetStageAtX();
  2219. // float y7 = iSEM.GetStageAtY();
  2220. // if (Math.Abs(x6 - x7) > fMin && Math.Abs(y6 - y7) > fMin)
  2221. // {
  2222. // return false;
  2223. // }
  2224. // //9.控制SEM平行校正,并记录校正前初始值
  2225. // float foldAnagle = iSEM.GetScanRotation();
  2226. // if (foldAnagle == float.NaN)
  2227. // {
  2228. // return false;
  2229. // }
  2230. // if (!iSEM.SetScanRotation(angle1))
  2231. // {
  2232. // return false;
  2233. // }
  2234. // //10.控制SEM放大到指定参数大小范围
  2235. // if (!iSEM.SetMagnification(mage))
  2236. // {
  2237. // return false;
  2238. // }
  2239. // //11.控制SEM自动对焦、消像散、亮度、对比度
  2240. // if (!MeasParam.FocusMode)
  2241. // {
  2242. // //弹出手动对焦的窗口
  2243. // }
  2244. // else
  2245. // {
  2246. // //调用自动对焦模块
  2247. // }
  2248. // //12.控制SEM对分析位置拍照
  2249. // String fileName6 = WorkingFolder + ImageName6;
  2250. // if (!GetImage(ImageMode.SEM, fileName6))
  2251. // {
  2252. // return false;
  2253. // }
  2254. // //13.保存照片
  2255. // //14.控制SEM取消电子束校正,回到初始值
  2256. // if (!iSEM.SetScanRotation(foldAnagle))
  2257. // {
  2258. // return false;
  2259. // }
  2260. //}
  2261. ////18.自动层高分析
  2262. //{
  2263. // //1.获取SEM Pixel Size给客户传入参数
  2264. // if (iSEM.GetPixelSize() == float.NaN)
  2265. // {
  2266. // return false;
  2267. // }
  2268. // //2.将照片传给客户,客户进行层高分析(返回分析后的图像、相对坐标、分辨率、各层编号以及各层对应的层高数据),如果客户自行出分析报告则无需返回数据
  2269. //}
  2270. ////19.自动能谱分析
  2271. //{
  2272. // //1. 确定能谱位置
  2273. // //2. 控制牛津打能谱
  2274. // //3. 能谱分析——面扫+线扫描
  2275. //}
  2276. #endregion
  2277. return true;
  2278. }
  2279. //非第一个孔的测试过程
  2280. public bool OtherHole()
  2281. {
  2282. //设置拉直的放大倍数
  2283. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2284. {
  2285. LogManager.AddHardwareLog("拉直放大倍数设置失败,程序退出。", true);
  2286. arg.Message = "拉直放大倍数设置失败!";
  2287. arg.State = false;
  2288. SendMsg("1-0");
  2289. return false;
  2290. }
  2291. arg.Message = "拉直放大倍数设置成功!";
  2292. arg.State = true;
  2293. SendMsg("1-0");
  2294. Thread.Sleep(1000);
  2295. //自动化流程-每个点都需要补偿54度
  2296. if (m_MsParam.Is_Photograph == false)
  2297. {
  2298. if (!TiltCorrection(54.0f))
  2299. {
  2300. arg.Message = "角度补偿54度失败!";
  2301. arg.State = false;
  2302. SendMsg("1-1");
  2303. return false;
  2304. }
  2305. arg.Message = "角度补偿54度成功!";
  2306. arg.State = true;
  2307. SendMsg("1-1");
  2308. Thread.Sleep(2000);
  2309. //判断是否停止进程
  2310. if (key_stop)
  2311. {
  2312. return false;
  2313. }
  2314. }
  2315. //拉直操作
  2316. if (!Straighten_Handle())
  2317. {
  2318. return false;
  2319. }
  2320. //判断是否停止进程
  2321. if (key_stop)
  2322. {
  2323. return false;
  2324. }
  2325. //13. 自动 定位功能
  2326. if (!GetPoistion())
  2327. {
  2328. return false;
  2329. }
  2330. //判断是否停止进程
  2331. if (key_stop)
  2332. {
  2333. return false;
  2334. }
  2335. //14.自动控制FIB切割
  2336. if (m_MsParam.Is_Photograph == false)
  2337. {
  2338. if (!FIBCross())
  2339. {
  2340. return false;
  2341. }
  2342. }
  2343. //判断是否停止进程
  2344. if (key_stop)
  2345. {
  2346. return false;
  2347. }
  2348. // 16.找到切割位置
  2349. if (m_MsParam.Is_Photograph == false)
  2350. {
  2351. if (!FindCross())
  2352. {
  2353. return false;
  2354. }
  2355. //判断是否停止进程
  2356. if (key_stop)
  2357. {
  2358. return false;
  2359. }
  2360. }
  2361. //将过程17最后的拍照图片提出给18步进行调用
  2362. String img18 = "";
  2363. //17.自动控制SEM拍截面照
  2364. if (!ShotSection(ref img18))
  2365. {
  2366. return false;
  2367. }
  2368. //判断是否停止进程
  2369. if (key_stop)
  2370. {
  2371. return false;
  2372. }
  2373. //18.自动层高分析
  2374. if (m_MsParam.Is_Photograph == false)
  2375. {
  2376. float size = iSEM.GetPixelSize();
  2377. float mag = iSEM.GetMagnification();
  2378. int state = 1;
  2379. //wr.Img_Measure_Size(img18, mag, size, out state);
  2380. if (state == 0)
  2381. {
  2382. arg.Message = "测量尺寸失败";
  2383. SendMsg("1-40");
  2384. return false;
  2385. }
  2386. arg.Message = "测量尺寸成功";
  2387. SendMsg("1-40");
  2388. }
  2389. #region 测试程序
  2390. //string fn;
  2391. //用宏抓一般图
  2392. //Thread.Sleep(5000);
  2393. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2394. //SendMsg("用宏抓一般图" + fn);
  2395. //iSEM.CMDMCFFilename(fn);
  2396. ////延时1s??
  2397. //Thread.Sleep(5000);
  2398. ////用宏抓好图
  2399. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2400. //SendMsg("用宏抓好图" + fn);
  2401. //iSEM.CMDMCFFilename(fn);
  2402. ////延时1s??
  2403. //Thread.Sleep(30000);
  2404. //Thread.Sleep(10000);
  2405. //WorkingFolder = m_measureFile.FilePath;
  2406. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2407. //SendMsg("SEM拍照存储到" + fileName6);
  2408. //if (!GetImage(ImageMode.SEM, fileName6))
  2409. //{
  2410. // SendMsg("SEM拍照失败");
  2411. // return false;
  2412. //}
  2413. ////用宏抓标志图
  2414. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2415. //SendMsg("用宏抓标志图" + fn);
  2416. //iSEM.CMDMCFFilename(fn);
  2417. ////延时1s??
  2418. //Thread.Sleep(30000);
  2419. ////恢复简单抓图
  2420. //Thread.Sleep(5000);
  2421. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2422. //SendMsg("用宏抓一般图" + fn);
  2423. //iSEM.CMDMCFFilename(fn);
  2424. //SendMsg("所有图结束");
  2425. #endregion
  2426. return true;
  2427. }
  2428. //测试完第一个孔后的样品台初始化操作。
  2429. //再调用CommonWork执行非第一个孔的测试过程
  2430. public bool OtherHole_Init()
  2431. {
  2432. CutHole currentHole = m_cutHoles[m_nWorkHoleNo];
  2433. #region 初始化
  2434. //1、不只拍照,且不是倾斜观测,则移动T轴
  2435. if (m_MsParam.Is_Photograph == false && m_MsParam.Title == false)
  2436. {
  2437. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2438. if (!iSEM.SetStageGotoT(0))
  2439. {
  2440. return false;
  2441. }
  2442. while (true)
  2443. {
  2444. Thread.Sleep(5000);
  2445. if (iSEM.GetStageIs() == 0)
  2446. {
  2447. break;
  2448. }
  2449. }
  2450. //判断是否停止进程
  2451. if (key_stop)
  2452. {
  2453. return false;
  2454. }
  2455. }
  2456. //2、如果是倾斜观测,则移动Z轴
  2457. if(m_MsParam.Title==true)
  2458. {
  2459. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2460. if (!iSEM.SetStageGotoZ(currentHole.Position.Z - m_MsParam.ZDistance/1000))
  2461. {
  2462. return false;
  2463. }
  2464. while (true)
  2465. {
  2466. Thread.Sleep(5000);
  2467. if (iSEM.GetStageIs() == 0)
  2468. {
  2469. break;
  2470. }
  2471. }
  2472. //判断是否停止进程
  2473. if (key_stop)
  2474. {
  2475. return false;
  2476. }
  2477. }
  2478. //3. 根据光镜坐标控制样品台移动
  2479. if (!iSEM.SetStageGotoR(currentHole.Position.R))
  2480. {
  2481. //SendMsg("移动失败");
  2482. return false;
  2483. }
  2484. LogManager.AddHardwareLog("移动R轴到="+ currentHole.Position.R.ToString(), true);
  2485. while (true)
  2486. {
  2487. Thread.Sleep(5000);
  2488. if (iSEM.GetStageIs() == 0)
  2489. {
  2490. break;
  2491. }
  2492. }
  2493. //判断是否停止进程
  2494. if (key_stop)
  2495. {
  2496. return false;
  2497. }
  2498. if(!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))
  2499. {
  2500. //SendMsg("移动失败");
  2501. return false;
  2502. }
  2503. LogManager.AddHardwareLog("移动X轴Y轴=" + currentHole.Position.X.ToString() + " " + currentHole.Position.Y.ToString(), true);
  2504. while (true)
  2505. {
  2506. Thread.Sleep(10000);
  2507. if (iSEM.GetStageIs() == 0)
  2508. {
  2509. break;
  2510. }
  2511. }
  2512. //判断是否停止进程
  2513. if (key_stop)
  2514. {
  2515. return false;
  2516. }
  2517. //4、倾斜观测时恢复Z轴
  2518. if (m_MsParam.Title == true)
  2519. {
  2520. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2521. if (!iSEM.SetStageGotoZ(currentHole.Position.Z))
  2522. {
  2523. return false;
  2524. }
  2525. while (true)
  2526. {
  2527. Thread.Sleep(5000);
  2528. if (iSEM.GetStageIs() == 0)
  2529. {
  2530. break;
  2531. }
  2532. }
  2533. //判断是否停止进程
  2534. if (key_stop)
  2535. {
  2536. return false;
  2537. }
  2538. }
  2539. //5. 控制样品台,调整T轴54度、M/Z/R轴不变
  2540. if (m_MsParam.Is_Photograph == false)
  2541. {
  2542. if (!iSEM.SetStageGotoT(54))
  2543. {
  2544. return false;
  2545. }
  2546. while (true)
  2547. {
  2548. Thread.Sleep(5000);
  2549. if (iSEM.GetStageIs() == 0)
  2550. {
  2551. break;
  2552. }
  2553. }
  2554. }
  2555. //判断是否停止进程
  2556. if (key_stop)
  2557. {
  2558. return false;
  2559. }
  2560. #endregion
  2561. return true;
  2562. }
  2563. //初始化拉直操作
  2564. public bool Straighten_Handle()
  2565. {
  2566. //1、自动对焦
  2567. if (!ImageFocus("1-2"))
  2568. {
  2569. LogManager.AddHardwareLog("拉直操作自动对焦失败,程序退出。", true);
  2570. arg.Message = "拉直操作自动对焦失败!";
  2571. arg.State = false;
  2572. SendMsg("1-2");
  2573. return false;
  2574. }
  2575. arg.Message = "拉直操作自动对焦成功!";
  2576. arg.State = true;
  2577. SendMsg("1-2");
  2578. //判断是否停止进程
  2579. if (key_stop)
  2580. {
  2581. return false;
  2582. }
  2583. //1.1大于10000倍进行消像散处理
  2584. float dMag = iSEM.GetMagnification();
  2585. if (dMag > 10000)//需要消像散
  2586. {
  2587. if (!ImageStig("1-2"))
  2588. {
  2589. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  2590. arg.Message = "拉直操作自动消像散失败!";
  2591. arg.State = false;
  2592. SendMsg("1-2");
  2593. return false;
  2594. }
  2595. arg.Message = "拉直操作自动消像散成功!";
  2596. arg.State = true;
  2597. SendMsg("1-2");
  2598. }
  2599. //2、拍张照片
  2600. String fileName0 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Stretch_Magnification.ToString("0") + "_" + ImageName0;
  2601. //拍照前改变速度,延时
  2602. iSEM.CmdSaveRate();
  2603. cycle_time = iSEM.GetCycleTime();
  2604. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2605. if (!GetImage(ImageMode.SEM, fileName0))
  2606. {
  2607. arg.Message = "拉直拍照成功";
  2608. arg.State = false;
  2609. SendMsg("1-3");
  2610. return false;
  2611. }
  2612. arg.Message = "拉直拍照成功!";
  2613. arg.State = true;
  2614. SendMsg("1-3");
  2615. iSEM.CmdFocusRate();
  2616. cycle_time = iSEM.GetCycleTime();
  2617. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2618. //3、华为接口,获取旋转角度
  2619. float degree = 0;
  2620. int direction = 0;
  2621. int state = 1;
  2622. wr.Img_OffsetAngle_Direction(fileName0, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out degree, out direction, out state);
  2623. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "初始化拉直角度=" + degree.ToString(), true);
  2624. if (state == 0)
  2625. {
  2626. arg.Message = "华为接口参数state返回为零";
  2627. arg.State = false;
  2628. SendMsg("1-4");
  2629. if (hand_intervene == 1)
  2630. {
  2631. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  2632. {
  2633. return false;
  2634. }
  2635. }
  2636. else
  2637. {
  2638. return false;
  2639. }
  2640. }
  2641. if (direction == 2)
  2642. {
  2643. degree = -degree;
  2644. }
  2645. #region//暂时不用这个拉直
  2646. //旋转R轴
  2647. //float getr = iSEM.GetStageAtR();
  2648. //getr = getr + degree;
  2649. //if(getr>R_Max)
  2650. //{
  2651. // getr = getr - 360;
  2652. //}
  2653. //if(getr<R_Min)
  2654. //{
  2655. // getr = getr + 360;
  2656. //}
  2657. //iSEM.SetStageGotoR(getr);
  2658. //while (true)
  2659. //{
  2660. // Thread.Sleep(5000);
  2661. // if (iSEM.GetStageIs() == 0)
  2662. // {
  2663. // break;
  2664. // }
  2665. //}
  2666. //MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  2667. //////3、拉直
  2668. //float x0 = iSEM.GetStageAtX();
  2669. //float y0 = iSEM.GetStageAtY();
  2670. //float x1 = 0, y1 = 0;
  2671. //Straightening(degree, x_center_point, y_center_point, x0, y0, ref x1, ref y1);
  2672. //if (x1 < X_Min || x1 > X_Max || y1 < Y_Min || y1 > Y_Max)
  2673. //{
  2674. // return false;
  2675. //}
  2676. //iSEM.MoveStageXY(x1, y1);
  2677. #endregion
  2678. //4、拉直,旋转R轴
  2679. iSEM.SetStageDeltaR(degree);
  2680. while (true)
  2681. {
  2682. Thread.Sleep(5000);
  2683. if (iSEM.GetStageIs() == 0)
  2684. {
  2685. break;
  2686. }
  2687. }
  2688. arg.Message = "拉直操作完成";
  2689. arg.State = true;
  2690. SendMsg("1-4");
  2691. //华为接口,去掉人工干预
  2692. //MessageBox.Show("拉直操作完成,如果不正确请手动进行拉直然后点击OK按钮。", "确认消息", MessageBoxButtons.OK);
  2693. return true;
  2694. }
  2695. //角度补偿
  2696. public bool TiltCorrection(float a_fAngle)
  2697. {
  2698. if (!iSEM.SetTiltAngleOn())
  2699. {
  2700. return false;
  2701. }
  2702. //恢复原始状态
  2703. if (!iSEM.SetTiltAngle(a_fAngle))
  2704. {
  2705. return false;
  2706. }
  2707. return true;
  2708. }
  2709. //拍图
  2710. public bool GetImage(ImageMode a_mode, String a_fileName)
  2711. {
  2712. //3. 获取分辨率
  2713. int[] ImageSize = iSEM.GetImageStore();
  2714. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  2715. {
  2716. return false;
  2717. }
  2718. short width = (short)ImageSize[0];
  2719. short height = (short)ImageSize[1];
  2720. //4. 抓图
  2721. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  2722. {
  2723. return false;
  2724. }
  2725. return true;
  2726. }
  2727. //自动聚焦
  2728. public bool AutoFocus(FocusParam a_param, out int a_nWd, String step_code)
  2729. {
  2730. a_nWd = 0;
  2731. float wd = iSEM.GetWorkingDistance();
  2732. a_nWd = (int)Math.Ceiling(wd * 100000000 + 0.5);//获取当前的工作距离
  2733. if (a_param == null)
  2734. {
  2735. LogManager.AddHardwareLog("空参数", true);
  2736. return false;
  2737. }
  2738. string path = a_param.Path;
  2739. if (!Directory.Exists(path))
  2740. {
  2741. LogManager.AddHardwareLog("文件夹丢失", true);
  2742. return false;
  2743. }
  2744. string path_coarse = a_param.Path + "\\Coarse";
  2745. if (!Directory.Exists(path_coarse))
  2746. {
  2747. Directory.CreateDirectory(path_coarse);
  2748. }
  2749. string path_fine = a_param.Path + "\\Fine";
  2750. if (!Directory.Exists(path_fine))
  2751. {
  2752. Directory.CreateDirectory(path_fine);
  2753. }
  2754. //1. 拍照
  2755. //1.1, 粗拍照
  2756. //1.1.1, 根据参数计算拍照次数
  2757. double nUp = a_param.UP * 100.0 ;
  2758. double nDown = a_param.Down * 100.0;
  2759. double nStep = a_param.Step * 100.0;
  2760. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2761. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2762. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2763. //粗拍照
  2764. for (int i = 0; i < nTimes; i++)
  2765. {
  2766. int cWd =(int) Math.Ceiling(nUp + i * nStep + 0.5);
  2767. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2768. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2769. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2770. int swd = cWd / 100;
  2771. //SendMsg("wd = " + swd.ToString() +"um");
  2772. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2773. arg.Picture_Information.Picture_FullPath = fileName;
  2774. if (!GetImage(ImageMode.SEM, fileName))
  2775. {
  2776. return false;
  2777. }
  2778. arg.State = true;
  2779. arg.Message = "自动对焦";
  2780. SendMsg(step_code);
  2781. //判断是否停止进程
  2782. if (key_stop)
  2783. {
  2784. return false;
  2785. }
  2786. //Thread.Sleep(3000);
  2787. }
  2788. //1.2, 选定细拍照的工作距离
  2789. int CorWd;
  2790. ChooseBest(path_coarse,out CorWd);
  2791. a_nWd = CorWd;
  2792. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2793. //1.3, 细拍照
  2794. if ( (CorWd - a_param.Range * 100.0) <=0)
  2795. {
  2796. return false;
  2797. }
  2798. double nfUp = CorWd - a_param.Range * 100.0;
  2799. double nfStep = a_param.fStep * 100.0;
  2800. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2801. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2802. for (int i = 0; i < nfTimes; i++)
  2803. {
  2804. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2805. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2806. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2807. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  2808. int swd = cWd / 100;
  2809. //SendMsg("wd = " + swd.ToString() + "um");
  2810. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2811. arg.Picture_Information.Picture_FullPath = fileName;
  2812. if (!GetImage(ImageMode.SEM, fileName))
  2813. {
  2814. return false;
  2815. }
  2816. arg.State = true;
  2817. arg.Message = "自动对焦";
  2818. SendMsg(step_code);
  2819. //判断是否停止进程
  2820. if (key_stop)
  2821. {
  2822. return false;
  2823. }
  2824. //Thread.Sleep(2000);
  2825. }
  2826. int fineWd;
  2827. ChooseBest(path_fine, out fineWd);
  2828. //SendMsg("wd fine max = " + fineWd.ToString());
  2829. a_nWd = fineWd;
  2830. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2831. return true;
  2832. }
  2833. //自动消像散 AutoStig
  2834. public bool AutoStig(FocusParam a_param, out int a_nWd, String step_code)
  2835. {
  2836. a_nWd = 0;
  2837. float wd = 0;
  2838. if (a_param.TYPE == 2)
  2839. {
  2840. wd = iSEM.GetAstigmatismX();
  2841. }
  2842. else if (a_param.TYPE == 3)
  2843. {
  2844. wd = iSEM.GetAstigmatismY();
  2845. }
  2846. else
  2847. {
  2848. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2849. return false;
  2850. }
  2851. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2852. if (a_param == null)
  2853. {
  2854. LogManager.AddHardwareLog("空参数", true);
  2855. return false;
  2856. }
  2857. string path = a_param.Path;
  2858. if (!Directory.Exists(path))
  2859. {
  2860. LogManager.AddHardwareLog("文件夹丢失", true);
  2861. return false;
  2862. }
  2863. string path_coarse = a_param.Path + "\\Coarse";
  2864. if (!Directory.Exists(path_coarse))
  2865. {
  2866. Directory.CreateDirectory(path_coarse);
  2867. }
  2868. string path_fine = a_param.Path + "\\Fine";
  2869. if (!Directory.Exists(path_fine))
  2870. {
  2871. Directory.CreateDirectory(path_fine);
  2872. }
  2873. //1. 拍照
  2874. //1.1, 粗拍照
  2875. //1.1.1, 根据参数计算拍照次数
  2876. double nUp = a_param.UP * 100.0;
  2877. double nDown = a_param.Down * 100.0;
  2878. double nStep = a_param.Step * 100.0;
  2879. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2880. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2881. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2882. //粗拍照
  2883. for (int i = 0; i < nTimes; i++)
  2884. {
  2885. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  2886. if (a_param.TYPE == 2)
  2887. {
  2888. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2889. }
  2890. else if (a_param.TYPE == 3)
  2891. {
  2892. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2893. }
  2894. else
  2895. {
  2896. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2897. return false;
  2898. }
  2899. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2900. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2901. int swd = cWd / 100;
  2902. //SendMsg("wd = " + swd.ToString() +"um");
  2903. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2904. arg.Picture_Information.Picture_FullPath = fileName;
  2905. if (!GetImage(ImageMode.SEM, fileName))
  2906. {
  2907. return false;
  2908. }
  2909. arg.State = true;
  2910. arg.Message = "自动像散";
  2911. SendMsg(step_code);
  2912. //判断是否停止进程
  2913. if (key_stop)
  2914. {
  2915. return false;
  2916. }
  2917. //Thread.Sleep(3000);
  2918. }
  2919. //1.2, 选定细拍照的工作距离
  2920. int CorWd;
  2921. ChooseBest(path_coarse, out CorWd);
  2922. a_nWd = CorWd;
  2923. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2924. //1.3, 细拍照
  2925. if ((CorWd - a_param.Range * 100.0) <= -10000)
  2926. {
  2927. return false;
  2928. }
  2929. double nfUp = CorWd - a_param.Range * 100.0;
  2930. double nfStep = a_param.fStep * 100.0;
  2931. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2932. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2933. for (int i = 0; i < nfTimes; i++)
  2934. {
  2935. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2936. if (a_param.TYPE == 2)
  2937. {
  2938. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2939. }
  2940. else if (a_param.TYPE == 3)
  2941. {
  2942. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2943. }
  2944. else
  2945. {
  2946. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2947. return false;
  2948. }
  2949. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2950. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2951. int swd = cWd / 100;
  2952. //SendMsg("wd = " + swd.ToString() + "um");
  2953. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2954. arg.Picture_Information.Picture_FullPath = fileName;
  2955. if (!GetImage(ImageMode.SEM, fileName))
  2956. {
  2957. return false;
  2958. }
  2959. arg.State = true;
  2960. arg.Message = "自动像散";
  2961. SendMsg(step_code);
  2962. //判断是否停止进程
  2963. if (key_stop)
  2964. {
  2965. return false;
  2966. }
  2967. //Thread.Sleep(2000);
  2968. }
  2969. int fineWd;
  2970. ChooseBest(path_fine, out fineWd);
  2971. //SendMsg("wd fine max = " + fineWd.ToString());
  2972. a_nWd = fineWd;
  2973. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2974. return true;
  2975. }
  2976. //自动FIB对焦 AutoFIBFocus
  2977. public bool AutoFIBFocus(FocusParam a_param, out int a_nWd, String step_code)
  2978. {
  2979. a_nWd = 0;
  2980. float wd = 0;
  2981. if (a_param.TYPE == 4)
  2982. {
  2983. wd = iSEM.GetFIBObjectivePotential();
  2984. }
  2985. else
  2986. {
  2987. LogManager.AddHardwareLog("FIB自动聚焦参数设置有误", true);
  2988. return false;
  2989. }
  2990. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2991. if (a_param == null)
  2992. {
  2993. LogManager.AddHardwareLog("空参数", true);
  2994. return false;
  2995. }
  2996. string path = a_param.Path;
  2997. if (!Directory.Exists(path))
  2998. {
  2999. LogManager.AddHardwareLog("文件夹丢失", true);
  3000. return false;
  3001. }
  3002. string path_coarse = a_param.Path + "\\Coarse";
  3003. if (!Directory.Exists(path_coarse))
  3004. {
  3005. Directory.CreateDirectory(path_coarse);
  3006. }
  3007. string path_fine = a_param.Path + "\\Fine";
  3008. if (!Directory.Exists(path_fine))
  3009. {
  3010. Directory.CreateDirectory(path_fine);
  3011. }
  3012. //1. 拍照
  3013. //1.1, 粗拍照
  3014. //1.1.1, 根据参数计算拍照次数
  3015. double nUp = a_param.UP * 100.0;
  3016. double nDown = a_param.Down * 100.0;
  3017. double nStep = a_param.Step * 100.0;
  3018. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  3019. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  3020. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  3021. //粗拍照
  3022. for (int i = 0; i < nTimes; i++)
  3023. {
  3024. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  3025. if (a_param.TYPE == 4)
  3026. {
  3027. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3028. }
  3029. else
  3030. {
  3031. LogManager.AddHardwareLog("FIB对焦参数设置有误,对焦类型错", true);
  3032. return false;
  3033. }
  3034. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3035. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3036. int swd = cWd / 100;
  3037. //SendMsg("wd = " + swd.ToString() +"um");
  3038. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  3039. arg.Picture_Information.Picture_FullPath = fileName;
  3040. if (!GetImage(ImageMode.SEM, fileName))
  3041. {
  3042. return false;
  3043. }
  3044. arg.State = true;
  3045. arg.Message = "FIB自动对焦";
  3046. SendMsg(step_code);
  3047. //判断是否停止进程
  3048. if (key_stop)
  3049. {
  3050. return false;
  3051. }
  3052. //Thread.Sleep(3000);
  3053. }
  3054. //1.2, 选定细拍照的工作距离
  3055. int CorWd;
  3056. ChooseBest(path_coarse, out CorWd);
  3057. a_nWd = CorWd;
  3058. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  3059. //1.3, 细拍照
  3060. if ((CorWd - a_param.Range * 100.0) <0)
  3061. {
  3062. return false;
  3063. }
  3064. double nfUp = CorWd - a_param.Range * 100.0;
  3065. double nfStep = a_param.fStep * 100.0;
  3066. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  3067. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  3068. for (int i = 0; i < nfTimes; i++)
  3069. {
  3070. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  3071. if (a_param.TYPE == 4)
  3072. {
  3073. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3074. }
  3075. else
  3076. {
  3077. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  3078. return false;
  3079. }
  3080. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3081. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3082. int swd = cWd / 100;
  3083. //SendMsg("wd = " + swd.ToString() + "um");
  3084. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  3085. arg.Picture_Information.Picture_FullPath = fileName;
  3086. if (!GetImage(ImageMode.SEM, fileName))
  3087. {
  3088. return false;
  3089. }
  3090. arg.State = true;
  3091. arg.Message = "FIB自动对焦";
  3092. SendMsg(step_code);
  3093. //判断是否停止进程
  3094. if (key_stop)
  3095. {
  3096. return false;
  3097. }
  3098. //Thread.Sleep(2000);
  3099. }
  3100. int fineWd;
  3101. ChooseBest(path_fine, out fineWd);
  3102. //SendMsg("wd fine max = " + fineWd.ToString());
  3103. a_nWd = fineWd;
  3104. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  3105. return true;
  3106. }
  3107. //LoG算子计算
  3108. private double LoGMean(string a_strImgPath)
  3109. {
  3110. //读入Img文件
  3111. if (!File.Exists(a_strImgPath))
  3112. {
  3113. return 0;
  3114. }
  3115. Mat src, gray_src;
  3116. int kernel_size = 3;
  3117. src = Cv2.ImRead(a_strImgPath);
  3118. gray_src = new Mat();
  3119. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3120. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3121. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3122. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3123. Cv2.Laplacian(src, src, MatType.CV_8UC3, kernel_size);
  3124. Cv2.ConvertScaleAbs(src, src);
  3125. //图像的平均灰度
  3126. double meanValue = 0.0;
  3127. meanValue = Cv2.Mean(src)[0];
  3128. return meanValue;
  3129. }
  3130. //梯度计算
  3131. private double Tenengrad(string a_strImgPath)
  3132. {
  3133. //读入Img文件
  3134. if (!File.Exists(a_strImgPath))
  3135. {
  3136. return 0;
  3137. }
  3138. Mat src;
  3139. src = Cv2.ImRead(a_strImgPath);
  3140. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3141. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3142. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3143. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3144. Cv2.Sobel(src, src, MatType.CV_8UC1, 1, 1);
  3145. //图像的平均灰度
  3146. double meanValue = 0.0;
  3147. meanValue = Cv2.Mean(src)[0];
  3148. return meanValue;
  3149. }
  3150. //梯度计算
  3151. private double TTgrad(string a_strImgPath)
  3152. {
  3153. //读入Img文件
  3154. if (!File.Exists(a_strImgPath))
  3155. {
  3156. return 0;
  3157. }
  3158. Mat src;
  3159. src = Cv2.ImRead(a_strImgPath);
  3160. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3161. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3162. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3163. Mat scalex = new Mat();
  3164. Mat scaley = new Mat();
  3165. Cv2.Scharr(src, src, src.Depth(), 1, 0);
  3166. Cv2.ConvertScaleAbs(src, scalex);
  3167. Cv2.Scharr(src, src, src.Depth(), 0, 1);
  3168. Cv2.ConvertScaleAbs(src, scaley);
  3169. Cv2.AddWeighted(scalex, 0.5, scaley, 0.5, 0, src);
  3170. //图像的平均灰度
  3171. double meanValue = 0.0;
  3172. meanValue = Cv2.Mean(src)[0];
  3173. return meanValue;
  3174. }
  3175. //三选二算法
  3176. private void ChooseBest(string a_strImgPath, out int a_nWd)
  3177. {
  3178. a_nWd = -1;
  3179. var files = Directory.GetFiles(a_strImgPath, "*.tif");
  3180. float[] values = new float[files.Length];
  3181. double smax1 = LoGMean(files[0]);
  3182. int wdmax1 = int.Parse(System.IO.Path.GetFileNameWithoutExtension(files[0]));
  3183. double smax2 = Tenengrad(files[0]);
  3184. int wdmax2 = wdmax1;
  3185. double smax3 = TTgrad(files[0]);
  3186. int wdmax3 = wdmax1;
  3187. int x = 0;
  3188. foreach (var file in files)
  3189. {
  3190. int wd = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file));
  3191. double svalue1 = LoGMean(file);
  3192. double svalue2 = Tenengrad(file);
  3193. double svalue3 = TTgrad(file);
  3194. if (smax1 < svalue1)
  3195. {
  3196. smax1 = svalue1;
  3197. wdmax1 = wd;
  3198. }
  3199. if (smax2 < svalue2)
  3200. {
  3201. smax2 = svalue2;
  3202. wdmax2 = wd;
  3203. }
  3204. if (smax3 < svalue3)
  3205. {
  3206. smax3 = svalue3;
  3207. wdmax3 = wd;
  3208. }
  3209. x++;
  3210. }
  3211. //SendMsg("LoG = " + wdmax1.ToString() + ",梯度 = " + wdmax2.ToString() + ",滤波 = " + wdmax3.ToString());
  3212. if (wdmax1 == wdmax2 || wdmax1 == wdmax3)
  3213. {
  3214. a_nWd = wdmax1;
  3215. //SendMsg("焦距 = " + wdmax1.ToString());
  3216. }
  3217. else if (wdmax1 == wdmax2 || wdmax2 == wdmax3)
  3218. {
  3219. a_nWd = wdmax2;
  3220. //SendMsg("焦距 = " + wdmax2.ToString());
  3221. }
  3222. else if (wdmax3 == wdmax2 || wdmax1 == wdmax3)
  3223. {
  3224. a_nWd = wdmax3;
  3225. //SendMsg("焦距 = " + wdmax3.ToString());
  3226. }
  3227. else
  3228. {
  3229. //SendMsg("对焦失败。");
  3230. }
  3231. }
  3232. //移动到像素位置
  3233. bool MoveToPix(float xc, float yc)
  3234. {
  3235. float pixSize = iSEM.GetPixelSize();
  3236. Thread.Sleep(500);
  3237. //0:width, 1:height
  3238. int[] imageSize = iSEM.GetImageStore();
  3239. int width = imageSize[0]/2;
  3240. int height = imageSize[1]/2;
  3241. float deltX = (xc - (float)width) * pixSize;
  3242. float deltY = (yc - (float)height) * pixSize;
  3243. float xpCur = iSEM.GetStageAtX();
  3244. float ypCur = iSEM.GetStageAtY();
  3245. float xpNew = xpCur - deltX;
  3246. float ypNew = ypCur - deltY;
  3247. LogManager.AddHardwareLog("样品台移动信息:deltx=" + deltX.ToString() +
  3248. ",delty=" + deltY.ToString() + ",xpNew=" + xpNew.ToString() + ",ypNew=" + ypNew.ToString(), true);
  3249. if (deltX > 10)//使用移动样品台实现
  3250. {
  3251. if (!iSEM.SetStageGotoX(xpNew))
  3252. {
  3253. return false;
  3254. }
  3255. //判断是否移动完成
  3256. while (true)
  3257. {
  3258. Thread.Sleep(5000);
  3259. if (iSEM.GetStageIs() == 0)
  3260. {
  3261. break;
  3262. }
  3263. }
  3264. //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  3265. //arg.State = true;
  3266. //SendMsg("1-7");
  3267. }
  3268. else//使用移动光束实现
  3269. {
  3270. float beamX = deltX * (float)0.66;
  3271. if (!iSEM.SetBeamShiftX(beamX))
  3272. {
  3273. return false;
  3274. }
  3275. }
  3276. if (deltY > 10)//使用移动样品台实现
  3277. {
  3278. if (!iSEM.SetStageGotoY(ypNew))
  3279. {
  3280. return false;
  3281. }
  3282. //判断是否移动完成
  3283. while (true)
  3284. {
  3285. Thread.Sleep(5000);
  3286. if (iSEM.GetStageIs() == 0)
  3287. {
  3288. break;
  3289. }
  3290. }
  3291. }
  3292. else//使用移动光束实现
  3293. {
  3294. float beamY = deltY * (float)0.671;
  3295. if (!iSEM.SetBeamShiftY(beamY))
  3296. {
  3297. return false;
  3298. }
  3299. }
  3300. return true;
  3301. }
  3302. }
  3303. }