Measure.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  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. namespace MeasureThread
  17. {
  18. //图片模式
  19. public enum ImageMode
  20. {
  21. FIB,
  22. SEM
  23. }
  24. public delegate void ThreadStatusHandler(object sender, ThreadStatusEventArgs e); //声明委托
  25. public delegate void CutHolesStatusHandler(object sender, CutHolesStatusEventArgs e);
  26. public class ThreadStatusEventArgs
  27. {
  28. //状态
  29. public string State
  30. {
  31. get { return m_state; }
  32. set { m_state = value; }
  33. }
  34. private string m_state;
  35. //时间
  36. public DateTime Time
  37. {
  38. get { return m_time; }
  39. set { m_time = value; }
  40. }
  41. private DateTime m_time;
  42. //步骤代码
  43. public String Step_Code
  44. {
  45. get { return step_Code; }
  46. set { step_Code = value; }
  47. }
  48. private String step_Code;
  49. //其他消息
  50. public String Message
  51. {
  52. get { return this.message; }
  53. set { this.message = value; }
  54. }
  55. private String message;
  56. //孔名
  57. public String HoleName
  58. {
  59. get { return this.holeName; }
  60. set { this.holeName = value; }
  61. }
  62. private String holeName;
  63. //图片信息
  64. public class PictureInformation
  65. {
  66. public String Picture_FullPath
  67. {
  68. get { return picture_FullPath; }
  69. set { picture_FullPath = value; }
  70. }
  71. private String picture_FullPath;
  72. public double Work_Voltage
  73. {
  74. get { return work_Voltage; }
  75. set { work_Voltage = value; }
  76. }
  77. private double work_Voltage;
  78. public double Magnification
  79. {
  80. get { return magnification; }
  81. set { magnification = value; }
  82. }
  83. private double magnification;
  84. public double Work_Distance
  85. {
  86. get { return work_Distance; }
  87. set { work_Distance = value; }
  88. }
  89. private double work_Distance;
  90. public String Work_Status
  91. {
  92. get { return work_Status; }
  93. set { work_Status = value; }
  94. }
  95. private String work_Status;
  96. }
  97. //图片信息实例类
  98. public PictureInformation Picture_Information
  99. {
  100. get { return picture_Information; }
  101. set { picture_Information = value; }
  102. }
  103. private PictureInformation picture_Information;
  104. //图像信息
  105. public class ImageInformation
  106. {
  107. public int Method_Name
  108. {
  109. get { return method_Name; }
  110. set { method_Name = value; }
  111. }
  112. private int method_Name;
  113. public Source_Img_Degree_Direction SIDD;
  114. public Cut_Position CP;
  115. public Cut_Success CS;
  116. public Trapezoid_Top_Center_Position TTCP;
  117. public Auto_Foucs AF;
  118. public Auto_Stigmatic AS;
  119. public Center_Position_OffsetAngle_Direction CPOD;
  120. public Measure_Size MS;
  121. public ImageInformation()
  122. {
  123. SIDD = new Source_Img_Degree_Direction();
  124. CP = new Cut_Position();
  125. CS = new Cut_Success();
  126. TTCP = new Trapezoid_Top_Center_Position();
  127. AF = new Auto_Foucs();
  128. AS = new Auto_Stigmatic();
  129. CPOD = new Center_Position_OffsetAngle_Direction();
  130. MS = new Measure_Size();
  131. }
  132. //1-计算原始图像偏移角度及方向
  133. public class Source_Img_Degree_Direction
  134. {
  135. public Boolean Is_Image = false;
  136. public double Degree
  137. {
  138. get { return degree; }
  139. set { degree = value; }
  140. }
  141. private double degree;
  142. public int Direction
  143. {
  144. get { return direction; }
  145. set { direction = value; }
  146. }
  147. private int direction;
  148. public int State
  149. {
  150. get { return state; }
  151. set { state = value; }
  152. }
  153. private int state;
  154. }
  155. //2-计算切割点位置
  156. public class Cut_Position
  157. {
  158. public Boolean Is_Image = false;
  159. public double Offsetx
  160. {
  161. get { return offsetx; }
  162. set { offsetx = value; }
  163. }
  164. private double offsetx;
  165. public double Offsety
  166. {
  167. get { return offsety; }
  168. set { offsety = value; }
  169. }
  170. private double offsety;
  171. public int State
  172. {
  173. get { return state; }
  174. set { state = value; }
  175. }
  176. private int state;
  177. }
  178. //3-是否切割成功
  179. public class Cut_Success
  180. {
  181. public Boolean Is_Image = false;
  182. public int State
  183. {
  184. get { return state; }
  185. set { state = value; }
  186. }
  187. private int state;
  188. }
  189. //4-计算切割后图像梯形区域上边中心点坐标
  190. public class Trapezoid_Top_Center_Position
  191. {
  192. public Boolean Is_Image = false;
  193. public double TopCenterX
  194. {
  195. get { return topCenterX; }
  196. set { topCenterX = value; }
  197. }
  198. private double topCenterX;
  199. public double TopCenterY
  200. {
  201. get { return topCenterY; }
  202. set { topCenterY = value; }
  203. }
  204. private double topCenterY;
  205. public int State
  206. {
  207. get { return state; }
  208. set { state = value; }
  209. }
  210. private int state;
  211. }
  212. //5-自动对焦
  213. public class Auto_Foucs
  214. {
  215. public Boolean Is_Image = true;
  216. public String Img_Path
  217. {
  218. get { return img_Path; }
  219. set { img_Path = value; }
  220. }
  221. private String img_Path;
  222. }
  223. //6-自动像闪
  224. public class Auto_Stigmatic
  225. {
  226. public Boolean Is_Image = true;
  227. public String Img_Path
  228. {
  229. get { return img_Path; }
  230. set { img_Path = value; }
  231. }
  232. private String img_Path;
  233. }
  234. //7-计算切割面区域中心坐标,以及偏移角度及方向
  235. public class Center_Position_OffsetAngle_Direction
  236. {
  237. public Boolean Is_Image = false;
  238. public double CenterX
  239. {
  240. get { return centerX; }
  241. set { centerX = value; }
  242. }
  243. private double centerX;
  244. public double CenterY
  245. {
  246. get { return centerY; }
  247. set { centerY = value; }
  248. }
  249. private double centerY;
  250. public double Degree
  251. {
  252. get { return degree; }
  253. set { degree = value; }
  254. }
  255. private double degree;
  256. public int Direction
  257. {
  258. get { return direction; }
  259. set { direction = value; }
  260. }
  261. private int direction;
  262. public int State
  263. {
  264. get { return state; }
  265. set { state = value; }
  266. }
  267. private int state;
  268. }
  269. //8-测量尺寸
  270. public class Measure_Size
  271. {
  272. public Boolean Is_Image = false;
  273. public int State
  274. {
  275. get { return state; }
  276. set { state = value; }
  277. }
  278. private int state;
  279. }
  280. }
  281. //图像信息实例类
  282. public ImageInformation Image_Information
  283. {
  284. get { return image_Information; }
  285. set { image_Information = value; }
  286. }
  287. private ImageInformation image_Information;
  288. public ThreadStatusEventArgs(string a_State)
  289. {
  290. picture_Information = new PictureInformation();
  291. image_Information = new ImageInformation();
  292. }
  293. }
  294. public class CutHolesStatusEventArgs
  295. {
  296. public string State
  297. {
  298. get { return m_state; }
  299. set { m_state = value; }
  300. }
  301. private string m_state;
  302. public string HoleName
  303. {
  304. get { return m_holeName; }
  305. set { m_holeName = value; }
  306. }
  307. private string m_holeName;
  308. public CutHolesStatusEventArgs(string a_state, string a_holeName)
  309. {
  310. this.m_state = a_state;
  311. this.m_holeName = a_holeName;
  312. }
  313. }
  314. public class Measure
  315. {
  316. /// <summary>
  317. /// 图像拉直算法
  318. /// </summary>
  319. /// <param name="Slope">倾斜角度</param>
  320. /// <param name="x0">圆心坐标x</param>
  321. /// <param name="y0">圆心坐标y</param>
  322. /// <param name="x1">倾斜情况下帧图的坐标x</param>
  323. /// <param name="y1">倾斜情况下帧图的坐标y</param>
  324. /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>
  325. /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>
  326. /// <returns></returns>
  327. public bool Straightening(double Slope, int x0, int y0, int x1, int y1, ref int Hx, ref int Hy)
  328. {
  329. try
  330. {
  331. double xr = x1 - x0;//倾斜图到中心的距离差x
  332. double yr = y1 - y0;//倾斜图到中心的距离差y
  333. double R = Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
  334. //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
  335. double k = Math.Atan(y1 / x1) / Math.PI * 180;//x1,y1的直角三角形圆心角度
  336. double k_S = k - Slope;//通过夹角差求x2,y2
  337. int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);
  338. int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);
  339. if (Slope > 0 || Slope < 0)
  340. {
  341. Hx = x1 - x2;
  342. Hy = y1 - y2;
  343. }
  344. else
  345. {
  346. Hx = 0;
  347. Hy = 0;
  348. }
  349. return true;
  350. }
  351. catch (Exception)
  352. {
  353. return false;
  354. }
  355. }
  356. public WebResult wr = null;
  357. public event ThreadStatusHandler SendThreadStatus; // 声明事件
  358. public event CutHolesStatusHandler SendCutHolesStatus; // 声明事件
  359. //定义一个全局的消息类
  360. ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");
  361. //全局只有一个fatorySEM
  362. static FactoryHardware factorySEM = FactoryHardware.Instance;
  363. ISEMControl iSEM = factorySEM.ISEM;
  364. //@的作用是不用转义字符\\只打一个就行
  365. const String ImageName1 = @"ImageSEM600X.tif"; //传给客户,作水平校正
  366. const String ImageName2 = @"ImageFIB600X1.tif";//传给客户,找到切割点
  367. const String ImageName3 = @"ImageFIB600X2.tif";
  368. const String ImageName4 = @"ImageSEM300X.tif";//传给客户,找到已经切割点
  369. const String ImageName5 = @"ImageSEM6000X.tif";//传给客户,水平校正
  370. const String ImageName6 = @"ImageSEMMag.tif";//传给客户,测量层高
  371. const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针
  372. const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针
  373. const String MacoScanPic = "Scan picture.MLF";//一般质量抓图的宏
  374. const String MacoGoodPic = "Good picture.MLF";//高质量抓图的宏
  375. const String MacoExportTif = "Export TIFF.MLF";// 导出有标尺的图像,这个图像为使用工具SmartSEM工具的图像
  376. const String ElyDeposition = @"Deposition.ely"; //沉积
  377. const String ElyCrossSection = @"CrossSection.ely"; //切割
  378. const float fMin = (float)0.0000002; //单位是米
  379. int m_nWorkHoleNo = -1;
  380. //测量文件
  381. private MeasureFile m_measureFile;
  382. public MeasureFile MeasureFile
  383. {
  384. get { return this.m_measureFile; }
  385. set { this.m_measureFile = value; }
  386. }
  387. //测量的切割孔
  388. private List<MeasureData.CutHole> m_cutHoles;
  389. public List<MeasureData.CutHole> cutHoles
  390. {
  391. get { return this.m_cutHoles; }
  392. set { this.m_cutHoles = value; }
  393. }
  394. //工作文件夹
  395. private string m_WorkingFolder;
  396. public string WorkingFolder
  397. {
  398. get { return this.m_WorkingFolder; }
  399. set { this.m_WorkingFolder = value; }
  400. }
  401. //程序当前路径
  402. private string m_ProgramFolder = Directory.GetCurrentDirectory();
  403. //线程状态
  404. private ThreadStatus m_ThreadStatus;
  405. public ThreadStatus TStatus
  406. {
  407. get { return this.m_ThreadStatus; }
  408. set { this.m_ThreadStatus = value; }
  409. }
  410. //测量参数
  411. private MeasureParam m_MsParam;
  412. public MeasureParam MeasParam
  413. {
  414. get { return this.m_MsParam; }
  415. set { this.m_MsParam = value; }
  416. }
  417. //构造函数
  418. public Measure(String webServerIP, String webServerPort, String webServerUrl)
  419. {
  420. MeasParam = new MeasureParam();
  421. TStatus = new ThreadStatus();
  422. cutHoles = new List<MeasureData.CutHole>();
  423. //配置远程连接
  424. wr = new WebResult(webServerIP,webServerPort,webServerUrl);
  425. }
  426. //初始化测量业务, 读测量文件,判断是否有可测试的切孔
  427. public bool InitMeas(MeasureFile a_measureFile)
  428. {
  429. m_measureFile = a_measureFile;
  430. List<CutHole> listHoles = m_measureFile.ListCutHole;
  431. foreach (CutHole h in listHoles)
  432. {
  433. if (h.SWITCH == true)
  434. {
  435. m_cutHoles.Add(h);
  436. }
  437. }
  438. if (m_cutHoles.Count == 0)
  439. return false;
  440. this.m_MsParam = m_measureFile.MParam;
  441. return true;
  442. }
  443. public void SendMsg(string step_code)
  444. {
  445. arg.Step_Code = step_code;
  446. arg.Time = DateTime.Now;
  447. switch(step_code)
  448. {
  449. //拍照
  450. case "1-5":
  451. case "1-7":
  452. case "1-16":
  453. case "1-24":
  454. //电压、放大倍数、工作距离、位置信息、图片路径
  455. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  456. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  457. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  458. break;
  459. case "1-10":
  460. case "1-18":
  461. //获取偏移信息
  462. break;
  463. case "1-12":
  464. case "1-20":
  465. //验证移动准备性
  466. break;
  467. case "1-26":
  468. //取消电子束校正并初始化
  469. break;
  470. default:
  471. arg.State = "1";
  472. break;
  473. }
  474. SendThreadStatus(this, arg);
  475. }
  476. public void SendCutHoleMsg(string a_state, string a_holeName)
  477. {
  478. CutHolesStatusEventArgs arg = new CutHolesStatusEventArgs(a_state, a_holeName);
  479. arg.HoleName = a_holeName;
  480. arg.State = a_state;
  481. SendCutHolesStatus(this, arg);
  482. }
  483. //测量流程
  484. public void DoMeasure()
  485. {
  486. //创建线程的测量状态的更新
  487. this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);
  488. if (SendThreadStatus != null)
  489. {
  490. SendMsg("开始测量。");
  491. }
  492. //检查硬件连接是否正常
  493. if (!ConnectHardware())
  494. {
  495. SendMsg("连接硬件失败。");
  496. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  497. return;
  498. }
  499. SendMsg("硬件连接成功。");
  500. //设置工作文件夹
  501. if (!SetWorkingFolderStr())
  502. {
  503. SendMsg("设置工作文件夹失败");
  504. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  505. return;
  506. }
  507. SendMsg("创建工作文件路径为" + WorkingFolder);
  508. float[] firstPosition;
  509. for (int i = 0; i < m_cutHoles.Count; i++)
  510. {
  511. m_nWorkHoleNo = i;
  512. arg.HoleName = cutHoles[m_nWorkHoleNo].HoleName;
  513. if (i == 0)
  514. {
  515. SendMsg("第一个切孔开始测量");
  516. //切孔操作-开始
  517. SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  518. firstPosition = iSEM.GetStagePosition();
  519. //第一个孔的测试
  520. FirstHole();
  521. //切孔操作-完成
  522. SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  523. }
  524. else
  525. {
  526. //非第一个孔的测试
  527. SendMsg("第" + i.ToString() + "个切孔开始测量");
  528. //切孔操作-开始
  529. SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  530. OtherHole();
  531. //切孔操作-完成
  532. SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  533. }
  534. }
  535. }
  536. //检查硬件连接是否正常
  537. public bool ConnectHardware()
  538. {
  539. //返回硬件的连接状态
  540. return iSEM.ConnectStatus();
  541. }
  542. //设置工作文件夹
  543. public bool SetWorkingFolderStr()
  544. {
  545. WorkingFolder = m_measureFile.FilePath;
  546. return true;
  547. }
  548. //插入PT针
  549. public bool InsertPT()
  550. {
  551. string fn = m_ProgramFolder + "\\Macro\\" + MacoInsertPt;
  552. //SendMsg("调用宏插入PT针宏文件" + fn);
  553. iSEM.CMDMCFFilename(fn);
  554. //延时1s??
  555. Thread.Sleep(1000);
  556. return true;
  557. }
  558. //撤出PT针
  559. public bool RetractPT()
  560. {
  561. string fn = m_ProgramFolder + "\\Macro\\" + MacoRetractPt;
  562. //SendMsg("调用宏撤出PT针宏文件" + fn);
  563. iSEM.CMDMCFFilename(fn);
  564. //延时1s??
  565. Thread.Sleep(1000);
  566. return true;
  567. }
  568. //PT沉积
  569. public bool PTWork()
  570. {
  571. //执行PT沉积的ELY文件
  572. string fn = m_ProgramFolder + "\\Macro\\" + ElyDeposition;
  573. //SendMsg("执行PT沉积Ely文件:" + fn);
  574. if (!ExcuteEly(fn))
  575. {
  576. return false;
  577. }
  578. //等待沉积完成
  579. while (true)
  580. {
  581. Thread.Sleep(10000);
  582. if (iSEM.GetFIBMode() == 0)
  583. {
  584. break;
  585. }
  586. }
  587. return true;
  588. }
  589. //FIB切割
  590. public bool FIBWork()
  591. {
  592. //执行PT沉积的ELY文件
  593. string fn = m_ProgramFolder + "\\Macro\\" + ElyCrossSection;
  594. //SendMsg("执行FIB切割Ely文件:" + fn);
  595. if (!ExcuteEly(fn))
  596. {
  597. return false;
  598. }
  599. //等待切割完成
  600. while (true)
  601. {
  602. Thread.Sleep(10000);
  603. if (iSEM.GetFIBMode() == 0)
  604. {
  605. break;
  606. }
  607. }
  608. return true;
  609. }
  610. //执行ELY文件的步骤
  611. public bool ExcuteEly(string a_filename)
  612. {
  613. //执行ELy文件有三个动作
  614. //1. 选择ELY文件
  615. //SendMsg("选择ELY文件");
  616. if (!iSEM.CmdFIBLoadELY(a_filename))
  617. {
  618. //SendMsg("选择ELY文件失败");
  619. return false;
  620. }
  621. Thread.Sleep(1000);
  622. //2. 确认ELY文件
  623. //SendMsg("确认ELY文件");
  624. if (!iSEM.CmdFIBEXPOSUREELY())
  625. {
  626. //SendMsg("确认ELY文件失败");
  627. return false;
  628. }
  629. Thread.Sleep(1000);
  630. //3. 执行ELY文件
  631. //SendMsg("执行ELY文件");
  632. if (!iSEM.CmdFIBSTARTELY())
  633. {
  634. //SendMsg("执行ELY文件失败");
  635. return false;
  636. }
  637. Thread.Sleep(1000);
  638. return true;
  639. }
  640. /// <summary>
  641. ///13. 自动 定位功能,沉积
  642. /// </summary>
  643. /// <returns></returns>
  644. public bool GetPoistion(Boolean isFirst)
  645. {
  646. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  647. int state = 0;
  648. //SendMsg("自动定位");
  649. //13.自动定位切割
  650. {
  651. //1.控制SEM放大600X
  652. arg.State = "SEM";
  653. if (!iSEM.SetMagnification(m_measureFile.MParam.Photograph_Magnification))
  654. {
  655. arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍失败";
  656. SendMsg("1-2");
  657. return false;
  658. }
  659. arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍成功";
  660. SendMsg("1-2");
  661. //2.控制SEM自动对焦、亮度、对比度
  662. if (m_measureFile.MParam.FocusMode==1)//手动
  663. {
  664. if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  665. {
  666. arg.Message = "自动对焦完成";
  667. SendMsg("1-3");
  668. //return true;
  669. }
  670. else
  671. {
  672. arg.Message = "自动对焦失败";
  673. SendMsg("1-3");
  674. return false;
  675. }
  676. }
  677. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  678. {
  679. //郝工增加自动对焦算法
  680. }
  681. else //客户自动
  682. {
  683. //后期和客户对接接口
  684. List<string> filenames = new List<string>();
  685. String retfilename = wr.Img_Auto_Focus(filenames);
  686. }
  687. //3.第一次不需要进行角度补偿,其他需要设置SEM进行角度补偿54度
  688. if (!isFirst)
  689. {
  690. if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
  691. {
  692. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
  693. SendMsg("1-4");
  694. return false;
  695. }
  696. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
  697. SendMsg("1-4");
  698. Thread.Sleep(5000);
  699. }
  700. //4.控制SEM拍照,5保存照片
  701. String fileName1 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName1;
  702. arg.Picture_Information.Picture_FullPath = fileName1;
  703. arg.Picture_Information.Work_Status = "SEM";
  704. if (!GetImage(ImageMode.SEM, fileName1))
  705. {
  706. arg.Message = "SEM拍照失败";
  707. SendMsg("1-5");
  708. return false;
  709. }
  710. arg.Message = "SEM拍照成功";
  711. SendMsg("1-5");
  712. Thread.Sleep(3000);
  713. //判断是否为仅拍照,不是则执行FIB操作
  714. if (!m_MsParam.Is_Photograph)
  715. {
  716. //6.设置FIB拍照参数——扫描时间、束流等
  717. //7.控制FIB自动亮度、对比度
  718. if (!iSEM.CmdFIBModeFIB())
  719. {
  720. arg.Message = "FIB模式切换失败";
  721. SendMsg("1-6");
  722. return false;
  723. }
  724. arg.Message = "FIB模式切换成功";
  725. SendMsg("1-6");
  726. Thread.Sleep(10000);
  727. //8.控制FIB拍照
  728. //9.保存照片
  729. String fileName2 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName2;
  730. arg.Picture_Information.Picture_FullPath = fileName1;
  731. arg.Picture_Information.Work_Status = "FIB";
  732. if (!GetImage(ImageMode.FIB, fileName2))
  733. {
  734. arg.Message = "FIB拍照失败";
  735. SendMsg("1-7");
  736. return false;
  737. }
  738. arg.Message = "FIB拍照成功";
  739. SendMsg("1-7");
  740. Thread.Sleep(3000);
  741. //这里需要确认是否对FIB的参数进行设置:电压和放大倍数等
  742. //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
  743. if (DialogResult.Yes == MessageBox.Show("是否手动移动样品台到指定位置?\n如果点击取消则会调用Web接口。", "确认消息", MessageBoxButtons.YesNo))
  744. {
  745. arg.Message = "样品台移动到指定位置";
  746. SendMsg("1-8");
  747. }
  748. else
  749. {
  750. wr.Img_Cut_Position(fileName2, m_MsParam.SampleName, m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
  751. if (state == 1)
  752. {
  753. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  754. if (!iSEM.MoveStageXY(x1, y1))
  755. {
  756. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  757. SendMsg("1-8");
  758. return false;
  759. }
  760. //判断是否移动完成
  761. while (true)
  762. {
  763. Thread.Sleep(5000);
  764. if (iSEM.GetStageIs() == 0)
  765. {
  766. break;
  767. }
  768. }
  769. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  770. SendMsg("1-8");
  771. }
  772. else
  773. {
  774. arg.Message = "样品台移动失败";
  775. SendMsg("1-8");
  776. return false;
  777. }
  778. }
  779. //11.自动工具样品类型参数确定是否需要PT沉积
  780. if (m_MsParam.PT)
  781. {
  782. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  783. //第10步已经移动好位置
  784. //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确
  785. x0 = iSEM.GetStageAtX();
  786. y0 = iSEM.GetStageAtY();
  787. if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
  788. {
  789. arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败";
  790. SendMsg("1-9");
  791. return false;
  792. }
  793. arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动成功";
  794. SendMsg("1-9");
  795. //3. 根据坐标进行PT沉积
  796. if (!PTWork())
  797. {
  798. arg.Message = "PT沉积失败";
  799. SendMsg("1-10");
  800. return false;
  801. }
  802. arg.Message = "PT沉积成功";
  803. SendMsg("1-10");
  804. }
  805. }
  806. //12.根据梯形坐标控制FIB调整到中心位置
  807. //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确
  808. //以上两步已经将程序移动到11内部去做
  809. //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库
  810. float[] firstPosition = iSEM.GetStagePosition();
  811. //这里要调用文件保存功能
  812. arg.Message = "坐标1(" + firstPosition[0].ToString() + ","
  813. + firstPosition[1].ToString() + ","
  814. + firstPosition[2].ToString() + ","
  815. + firstPosition[3].ToString() + ","
  816. + firstPosition[4].ToString() + ","
  817. + firstPosition[5].ToString() + ")";
  818. SendMsg("1-11");
  819. }
  820. return true;
  821. }
  822. /// <summary>
  823. /// 14. FIB切割
  824. /// </summary>
  825. /// <returns></returns>
  826. public bool FIBCross()
  827. {
  828. //14.自动控制FIB切割
  829. //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  830. //2.控制FIB进行切割
  831. //以上1、2步全部用ELY文件代替
  832. if (!FIBWork())
  833. {
  834. arg.Message = "FIB切割失败";
  835. SendMsg("1-12");
  836. return false;
  837. }
  838. arg.Message = "FIB切割成功";
  839. SendMsg("1-12");
  840. Thread.Sleep(5000);
  841. //3.控制FIB拍照600X
  842. //这里如何控制
  843. //4.保存图片
  844. String fileName3 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName3;
  845. arg.Picture_Information.Picture_FullPath = fileName3;
  846. arg.Picture_Information.Work_Status = "FIB";
  847. if (!GetImage(ImageMode.FIB, fileName3))
  848. {
  849. arg.Message = "FIB拍照失败";
  850. SendMsg("1-14");
  851. return false;
  852. }
  853. arg.Message = "FIB拍照成功";
  854. SendMsg("1-14");
  855. Thread.Sleep(3000);
  856. //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
  857. //6.设置FIB解冻:先读取状态,如果冻结状态则进行解冻
  858. return true;
  859. }
  860. /// <summary>
  861. /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  862. /// </summary>
  863. /// <returns></returns>
  864. public bool FindCross()
  865. {
  866. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  867. float angle = 0;
  868. int direction = 0;
  869. int state = 0;
  870. //1.控制SEM放大到300倍
  871. arg.State = "SEM";
  872. if (!iSEM.SetMagnification(m_measureFile.MParam.Photograph_Magnification))
  873. {
  874. arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍失败";
  875. SendMsg("1-18");
  876. return false;
  877. }
  878. arg.Message = "放大" + m_measureFile.MParam.Photograph_Magnification.ToString("0.0") + "倍成功";
  879. SendMsg("1-18");
  880. //2.控制SEM自动对焦、亮度、对比度-接口
  881. if (m_measureFile.MParam.FocusMode == 1)//手动
  882. {
  883. if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  884. {
  885. arg.Message = "自动对焦完成";
  886. SendMsg("1-19");
  887. //return true;
  888. }
  889. else
  890. {
  891. arg.Message = "自动对焦失败";
  892. SendMsg("1-19");
  893. return false;
  894. }
  895. }
  896. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  897. {
  898. //郝工增加自动对焦算法
  899. }
  900. else //客户自动
  901. {
  902. //后期和客户对接接口
  903. List<string> filenames = new List<string>();
  904. String retfilename = wr.Img_Auto_Focus(filenames);
  905. }
  906. Thread.Sleep(5000);
  907. //原来这里有3是角度补偿
  908. //3.控制SEM拍照
  909. String fileName4 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName4;
  910. arg.Picture_Information.Picture_FullPath = fileName4;
  911. arg.Picture_Information.Work_Status = "SEM";
  912. if (!GetImage(ImageMode.SEM, fileName4))
  913. {
  914. arg.Message = "SEM拍照失败";
  915. SendMsg("1-20");
  916. return false;
  917. }
  918. arg.Message = "SEM拍照成功";
  919. SendMsg("1-20");
  920. Thread.Sleep(3000);
  921. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  922. //5.根据坐标控制SEM移动到切孔位置,居中
  923. //这里是否用到拉直操作,我没有加
  924. if (DialogResult.Yes == MessageBox.Show("是否手动移动样品台到指定位置?\n如果点击取消则会调用Web接口。", "确认消息", MessageBoxButtons.YesNo))
  925. {
  926. arg.Message = "样品台移动到指定位置";
  927. SendMsg("1-21");
  928. }
  929. else
  930. {
  931. wr.Img_Center_Position_OffsetAngle_Direction(fileName4, m_MsParam.SampleName, m_MsParam.Firm, out x1, out y1, out angle, out direction, out state);
  932. if (state == 1)
  933. {
  934. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  935. if (!iSEM.MoveStageXY(x1, y1))
  936. {
  937. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  938. SendMsg("1-21");
  939. return false;
  940. }
  941. //判断是否移动完成
  942. while (true)
  943. {
  944. Thread.Sleep(5000);
  945. if (iSEM.GetStageIs() == 0)
  946. {
  947. break;
  948. }
  949. }
  950. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  951. SendMsg("1-21");
  952. }
  953. else
  954. {
  955. arg.Message = "样品台移动失败";
  956. SendMsg("1-21");
  957. return false;
  958. }
  959. }
  960. if (!iSEM.SetScanRotation(angle))
  961. {
  962. arg.Message = "调整角度失败";
  963. SendMsg("1-22");
  964. return false;
  965. }
  966. arg.Message = "调整角度成功";
  967. SendMsg("1-22");
  968. ////6.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  969. //float x5 = iSEM.GetStageAtX();
  970. //float y5 = iSEM.GetStageAtY();
  971. //if (Math.Abs(x5 - x4) > fMin && Math.Abs(y5 - y4) > fMin)
  972. //{
  973. // return false;
  974. //}
  975. return true;
  976. }
  977. /// <summary>
  978. /// 17.自动控制SEM拍截面照
  979. /// </summary>
  980. /// <returns></returns>
  981. public bool ShotSection()
  982. {
  983. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  984. int state = 0;
  985. //切换到SEM模式
  986. if (!iSEM.CmdFIBModeSEM())
  987. {
  988. //SendMsg("SEM模式切换失败");
  989. return false;
  990. }
  991. arg.State = "SEM";
  992. Thread.Sleep(10000);
  993. //1、放大6000倍
  994. if (!iSEM.SetMagnification(6000))
  995. {
  996. arg.Message = "放大倍数调整失败";
  997. SendMsg("1-25");
  998. return false;
  999. }
  1000. arg.Message = "放大倍数调整成功";
  1001. SendMsg("1-25");
  1002. //2.控制SEM自动对焦、亮度、对比度-接口
  1003. if (m_measureFile.MParam.FocusMode == 1)//手动
  1004. {
  1005. if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  1006. {
  1007. arg.Message = "自动对焦完成";
  1008. SendMsg("1-26");
  1009. //return true;
  1010. }
  1011. else
  1012. {
  1013. arg.Message = "自动对焦失败";
  1014. SendMsg("1-26");
  1015. return false;
  1016. }
  1017. }
  1018. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  1019. {
  1020. //郝工增加自动对焦算法
  1021. }
  1022. else //客户自动
  1023. {
  1024. //后期和客户对接接口
  1025. List<string> filenames = new List<string>();
  1026. String retfilename = wr.Img_Auto_Focus(filenames);
  1027. }
  1028. //3、设置SEM补偿角度
  1029. if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
  1030. {
  1031. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
  1032. SendMsg("1-27");
  1033. return false;
  1034. }
  1035. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
  1036. SendMsg("1-27");
  1037. Thread.Sleep(5000);
  1038. //4、拍照,5、保存照片
  1039. String fileName5 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName5;
  1040. arg.Picture_Information.Picture_FullPath = fileName5;
  1041. arg.Picture_Information.Work_Status = "SEM";
  1042. if (!GetImage(ImageMode.SEM, fileName5))
  1043. {
  1044. arg.Message = "SEM拍照失败";
  1045. SendMsg("1-28");
  1046. return false;
  1047. }
  1048. arg.Message = "SEM拍照成功";
  1049. SendMsg("1-28");
  1050. Thread.Sleep(3000);
  1051. //6、获取偏移坐标,7、移动到位
  1052. if (DialogResult.Yes == MessageBox.Show("是否手动移动样品台到指定位置?\n如果点击取消则会调用Web接口。", "确认消息", MessageBoxButtons.YesNo))
  1053. {
  1054. arg.Message = "样品台移动到指定位置";
  1055. SendMsg("1-29");
  1056. }
  1057. else
  1058. {
  1059. // wr.Img_Cut_Position(fileName5, m_MsParam.SampleName, m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
  1060. if (state == 1)
  1061. {
  1062. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1063. if (!iSEM.MoveStageXY(x1, y1))
  1064. {
  1065. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  1066. SendMsg("1-29");
  1067. return false;
  1068. }
  1069. //判断是否移动完成
  1070. while (true)
  1071. {
  1072. Thread.Sleep(5000);
  1073. if (iSEM.GetStageIs() == 0)
  1074. {
  1075. break;
  1076. }
  1077. }
  1078. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  1079. SendMsg("1-29");
  1080. }
  1081. else
  1082. {
  1083. arg.Message = "样品台移动失败";
  1084. SendMsg("1-8");
  1085. return false;
  1086. }
  1087. }
  1088. //8、验证移动准确性
  1089. //9、
  1090. return true;
  1091. }
  1092. public bool CommonWork()
  1093. {
  1094. SendMsg("插入PT针");
  1095. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  1096. //if (firstHole.PT == true)
  1097. {
  1098. if (!InsertPT())
  1099. {
  1100. SendMsg("插入PT针失败");
  1101. return false;
  1102. }
  1103. }
  1104. //13. 自动 定位功能
  1105. SendMsg("自动定位切割位置");
  1106. if (!GetPoistion(false))
  1107. {
  1108. SendMsg("自动定位切割位置失败");
  1109. return false;
  1110. }
  1111. //14.自动控制FIB切割
  1112. SendMsg("FIB切割");
  1113. if (!FIBCross())
  1114. {
  1115. SendMsg("FIB切割失败");
  1116. return false;
  1117. }
  1118. //{
  1119. // //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  1120. // //2.控制FIB进行切割
  1121. // //3.控制FIB拍照600X
  1122. // //4.保存图片
  1123. // {
  1124. // //1.设置图片名称
  1125. // //2.保存图片3
  1126. // String fileName3 = WorkingFolder + ImageName3;
  1127. // if (!GetImage(ImageMode.FIB, fileName3))
  1128. // {
  1129. // return false;
  1130. // }
  1131. // }
  1132. // //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
  1133. // //6.设置FIB解冻:先读取状态,如果冻结状态则进行解冻
  1134. //}
  1135. //15.根据样品类型决定是否撤出PT针
  1136. SendMsg("撤出PT针");
  1137. //if (firstHole.PT == false)
  1138. //{
  1139. if (!RetractPT())
  1140. {
  1141. SendMsg("撤出PT针失败");
  1142. return false;
  1143. }
  1144. //}
  1145. // 16.找到切割位置
  1146. SendMsg("找到切割位置");
  1147. //17.自动控制SEM拍截面照
  1148. SendMsg("观测层高");
  1149. SendMsg("切换SEM控制");
  1150. if (!iSEM.CmdFIBModeSEM())
  1151. {
  1152. SendMsg("SEM模式切换失败");
  1153. return false;
  1154. }
  1155. Thread.Sleep(10000);
  1156. SendMsg("放大6000倍");
  1157. if (!iSEM.SetMagnification(6000))
  1158. {
  1159. SendMsg("放大倍数调整失败");
  1160. return false;
  1161. }
  1162. if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))
  1163. {
  1164. SendMsg("拍摄照片完成");
  1165. //return true;
  1166. }
  1167. else
  1168. {
  1169. SendMsg("拍摄照片失败");
  1170. return false;
  1171. }
  1172. SendMsg("图像校正36度");
  1173. //3.设置SEM角度补偿cos36度
  1174. if (!TiltCorrection(36))
  1175. {
  1176. return false;
  1177. }
  1178. Thread.Sleep(3000);
  1179. string fn;
  1180. //用宏抓一般图
  1181. Thread.Sleep(5000);
  1182. fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  1183. SendMsg("用宏抓一般图" + fn);
  1184. iSEM.CMDMCFFilename(fn);
  1185. //延时1s??
  1186. Thread.Sleep(5000);
  1187. //用宏抓好图
  1188. fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  1189. SendMsg("用宏抓好图" + fn);
  1190. iSEM.CMDMCFFilename(fn);
  1191. //延时1s??
  1192. Thread.Sleep(30000);
  1193. Thread.Sleep(10000);
  1194. WorkingFolder = m_measureFile.FilePath;
  1195. String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  1196. SendMsg("SEM拍照存储到" + fileName6);
  1197. if (!GetImage(ImageMode.SEM, fileName6))
  1198. {
  1199. SendMsg("SEM拍照失败");
  1200. return false;
  1201. }
  1202. //用宏抓标志图
  1203. fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  1204. SendMsg("用宏抓标志图" + fn);
  1205. iSEM.CMDMCFFilename(fn);
  1206. //延时1s??
  1207. Thread.Sleep(30000);
  1208. //恢复简单抓图
  1209. Thread.Sleep(5000);
  1210. fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  1211. SendMsg("用宏抓一般图" + fn);
  1212. iSEM.CMDMCFFilename(fn);
  1213. SendMsg("所有图结束");
  1214. return true;
  1215. }
  1216. //第一个孔的测试过程
  1217. public bool FirstHole()
  1218. {
  1219. MeasureData.CutHole firstHole = m_cutHoles[0];
  1220. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  1221. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1222. {
  1223. if (!InsertPT())
  1224. {
  1225. arg.Message = "插入PT针失败";
  1226. SendMsg("1-0");
  1227. return false;
  1228. }
  1229. arg.Message = "插入PT针成功";
  1230. SendMsg("1-0");
  1231. }
  1232. //13. 自动 定位功能
  1233. if (!GetPoistion(true))
  1234. {
  1235. arg.Message = "自动定位切割位置失败";
  1236. SendMsg("1-1");
  1237. return false;
  1238. }
  1239. arg.Message = "自动定位切割位置成功";
  1240. SendMsg("1-1");
  1241. //14.自动控制FIB切割
  1242. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1243. {
  1244. if (!FIBCross())
  1245. {
  1246. arg.Message = "FIB切割失败";
  1247. SendMsg("1-16");
  1248. return false;
  1249. }
  1250. arg.Message = "FIB切割成功";
  1251. SendMsg("1-16");
  1252. }
  1253. //15.根据样品类型决定是否撤出PT针
  1254. if(m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1255. {
  1256. if (!RetractPT())
  1257. {
  1258. arg.Message = "撤出PT针失败";
  1259. SendMsg("1-17");
  1260. return false;
  1261. }
  1262. arg.Message = "撤出PT针成功";
  1263. SendMsg("1-17");
  1264. }
  1265. // 16.找到切割位置
  1266. if(m_MsParam.Is_Photograph == false)
  1267. {
  1268. if (!FindCross())
  1269. {
  1270. arg.Message = "找到切割位置失败";
  1271. SendMsg("1-24");
  1272. return false;
  1273. }
  1274. arg.Message = "找到切割位置成功";
  1275. SendMsg("1-24");
  1276. }
  1277. //17.自动控制SEM拍截面照
  1278. if(m_MsParam.Is_Photograph == false)
  1279. {
  1280. if (!ShotSection())
  1281. {
  1282. arg.Message = "自动控制SEM拍截面照失败";
  1283. SendMsg("1-33");
  1284. return false;
  1285. }
  1286. arg.Message = "自动控制SEM拍截面照成功";
  1287. SendMsg("1-33");
  1288. }
  1289. //if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))
  1290. //{
  1291. // SendMsg("拍摄照片完成");
  1292. // //return true;
  1293. //}
  1294. //else
  1295. //{
  1296. // SendMsg("拍摄照片失败");
  1297. // return false;
  1298. //}
  1299. //SendMsg("图像校正36度");
  1300. ////3.设置SEM角度补偿cos36度
  1301. //if (!TiltCorrection(36))
  1302. //{
  1303. // return false;
  1304. //}
  1305. //Thread.Sleep(3000);
  1306. string fn;
  1307. //用宏抓一般图
  1308. Thread.Sleep(5000);
  1309. fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  1310. SendMsg("用宏抓一般图" + fn);
  1311. iSEM.CMDMCFFilename(fn);
  1312. //延时1s??
  1313. Thread.Sleep(5000);
  1314. //用宏抓好图
  1315. fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  1316. SendMsg("用宏抓好图" + fn);
  1317. iSEM.CMDMCFFilename(fn);
  1318. //延时1s??
  1319. Thread.Sleep(30000);
  1320. Thread.Sleep(10000);
  1321. WorkingFolder = m_measureFile.FilePath;
  1322. String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  1323. SendMsg("SEM拍照存储到" + fileName6);
  1324. if (!GetImage(ImageMode.SEM, fileName6))
  1325. {
  1326. SendMsg("SEM拍照失败");
  1327. return false;
  1328. }
  1329. //用宏抓标志图
  1330. fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  1331. SendMsg("用宏抓标志图" + fn);
  1332. iSEM.CMDMCFFilename(fn);
  1333. //延时1s??
  1334. Thread.Sleep(30000);
  1335. Thread.Sleep(5000);
  1336. fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  1337. SendMsg("用宏抓一般图" + fn);
  1338. iSEM.CMDMCFFilename(fn);
  1339. //延时1s??
  1340. Thread.Sleep(5000);
  1341. SendMsg("所有图结束");
  1342. ////17.自动控制SEM拍截面照
  1343. //{
  1344. // //1.控制SEM放大到指定参数大小范围,6000x
  1345. // if (!iSEM.SetMagnification(6000))
  1346. // {
  1347. // return false;
  1348. // }
  1349. // //2.控制SEM自动对焦、消像散、亮度、对比度
  1350. // if (!MeasParam.FocusMode)
  1351. // {
  1352. // //弹出手动对焦的窗口
  1353. // }
  1354. // else
  1355. // {
  1356. // //调用自动对焦模块
  1357. // }
  1358. // //3.设置SEM角度补偿cos36度
  1359. // if (!TiltCorrection(36))
  1360. // {
  1361. // return false;
  1362. // }
  1363. // //4.控制SEM拍照
  1364. // //5.保存照片4
  1365. // String fileName5 = WorkingFolder + ImageName5;
  1366. // if (!GetImage(ImageMode.SEM, fileName5))
  1367. // {
  1368. // return false;
  1369. // }
  1370. // //6.将照片传给客户,获取偏移坐标
  1371. // float x6 = 0, y6 = 0;
  1372. // float angle1 = 0;
  1373. // float mage = 10000;
  1374. // //7.根据坐标控制SEM移动到分析位置
  1375. // if (!iSEM.MoveStageXY(x6, y6))
  1376. // {
  1377. // return false;
  1378. // }
  1379. // //8.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  1380. // float x7 = iSEM.GetStageAtX();
  1381. // float y7 = iSEM.GetStageAtY();
  1382. // if (Math.Abs(x6 - x7) > fMin && Math.Abs(y6 - y7) > fMin)
  1383. // {
  1384. // return false;
  1385. // }
  1386. // //9.控制SEM平行校正,并记录校正前初始值
  1387. // float foldAnagle = iSEM.GetScanRotation();
  1388. // if (foldAnagle == float.NaN)
  1389. // {
  1390. // return false;
  1391. // }
  1392. // if (!iSEM.SetScanRotation(angle1))
  1393. // {
  1394. // return false;
  1395. // }
  1396. // //10.控制SEM放大到指定参数大小范围
  1397. // if (!iSEM.SetMagnification(mage))
  1398. // {
  1399. // return false;
  1400. // }
  1401. // //11.控制SEM自动对焦、消像散、亮度、对比度
  1402. // if (!MeasParam.FocusMode)
  1403. // {
  1404. // //弹出手动对焦的窗口
  1405. // }
  1406. // else
  1407. // {
  1408. // //调用自动对焦模块
  1409. // }
  1410. // //12.控制SEM对分析位置拍照
  1411. // String fileName6 = WorkingFolder + ImageName6;
  1412. // if (!GetImage(ImageMode.SEM, fileName6))
  1413. // {
  1414. // return false;
  1415. // }
  1416. // //13.保存照片
  1417. // //14.控制SEM取消电子束校正,回到初始值
  1418. // if (!iSEM.SetScanRotation(foldAnagle))
  1419. // {
  1420. // return false;
  1421. // }
  1422. //}
  1423. ////18.自动层高分析
  1424. //{
  1425. // //1.获取SEM Pixel Size给客户传入参数
  1426. // if (iSEM.GetPixelSize() == float.NaN)
  1427. // {
  1428. // return false;
  1429. // }
  1430. // //2.将照片传给客户,客户进行层高分析(返回分析后的图像、相对坐标、分辨率、各层编号以及各层对应的层高数据),如果客户自行出分析报告则无需返回数据
  1431. //}
  1432. ////19.自动能谱分析
  1433. //{
  1434. // //1. 确定能谱位置
  1435. // //2. 控制牛津打能谱
  1436. // //3. 能谱分析——面扫+线扫描
  1437. //}
  1438. return true;
  1439. }
  1440. //非第一个孔的测试过程
  1441. public void OtherHole()
  1442. {
  1443. //for (int i = 1; i < m_cutHoles.Count; i++)
  1444. //{
  1445. SendMsg("当前切孔号为"+ m_nWorkHoleNo.ToString());
  1446. CutHole currentHole = m_cutHoles[m_nWorkHoleNo];
  1447. //1. 初始化
  1448. {
  1449. //1. 设置FIB解冻:先读取状态,如果冻结则进行解冻
  1450. //读取图像冻结状态
  1451. float ffrozen = iSEM.GetImageFrozen();
  1452. if (ffrozen == float.NaN)
  1453. {
  1454. return;
  1455. }
  1456. if (DialogResult.Yes == MessageBox.Show("样品台可以旋转恢复到水平吗?", "确认消息", MessageBoxButtons.YesNo))
  1457. {
  1458. SendMsg("样品台恢复到水平");
  1459. //return true;
  1460. }
  1461. else
  1462. {
  1463. SendMsg("禁止样品台恢复到水平");
  1464. return;
  1465. }
  1466. //2. 调节样品1号孔的样品台6轴坐标
  1467. //3. 将样品1号孔坐标2存入数据库
  1468. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  1469. if (!iSEM.SetStageGotoT(0))
  1470. {
  1471. return;
  1472. }
  1473. while (true)
  1474. {
  1475. Thread.Sleep(10000);
  1476. if (iSEM.GetStageIs() == 0)
  1477. {
  1478. break;
  1479. }
  1480. }
  1481. //5. 获取光镜2号孔XY坐标
  1482. SendMsg("移动到"+m_nWorkHoleNo+"号孔位置:(" + currentHole.Position.X.ToString()+","+currentHole.Position.Y.ToString()+")");
  1483. //6. 根据光镜坐标控制样品台移动
  1484. if (!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))
  1485. {
  1486. SendMsg("移动失败");
  1487. }
  1488. while (true)
  1489. {
  1490. Thread.Sleep(10000);
  1491. if (iSEM.GetStageIs() == 0)
  1492. {
  1493. break;
  1494. }
  1495. }
  1496. //7. 控制样品台,调整T轴54度、M/Z/R轴不变
  1497. if (DialogResult.Yes == MessageBox.Show("样品台可以旋转吗?", "确认消息", MessageBoxButtons.YesNo))
  1498. {
  1499. SendMsg("样品台旋转");
  1500. //return true;
  1501. }
  1502. else
  1503. {
  1504. SendMsg("禁止样品台旋转");
  1505. return;
  1506. }
  1507. if (!iSEM.SetStageGotoT(54))
  1508. {
  1509. return;
  1510. }
  1511. while (true)
  1512. {
  1513. Thread.Sleep(10000);
  1514. if (iSEM.GetStageIs() == 0)
  1515. {
  1516. break;
  1517. }
  1518. }
  1519. }
  1520. SendMsg("拉直操作");
  1521. SendMsg("其他操作与1号孔操作一致");
  1522. if (!CommonWork())
  1523. {
  1524. return;
  1525. }
  1526. //2. 定位切割
  1527. {
  1528. //1. 拉直操作
  1529. {
  1530. //1.1 控制SEM进行拍照
  1531. //1.2 图片传给客户,返回偏移角度
  1532. //1.3 根据返回角度,控制样品台转动
  1533. }
  1534. //2. 与1号孔13步相同
  1535. }
  1536. //3. 以后步骤与1号孔以后步骤一致
  1537. //}
  1538. }
  1539. //角度补偿
  1540. public bool TiltCorrection(float a_fAngle)
  1541. {
  1542. //记录原来电镜的状态
  1543. // bool bTilt = false;
  1544. //float fOldTilt = iSEM.GetTiltCorrection();
  1545. //if (fOldTilt == float.NaN)
  1546. //{
  1547. // return false;
  1548. //}
  1549. //else if (fOldTilt == 1)
  1550. //{
  1551. // bTilt = true;
  1552. //}
  1553. //else if (fOldTilt == 0)
  1554. //{
  1555. // bTilt = false;
  1556. //}
  1557. //float fOldAngle = iSEM.GetTiltAngle();
  1558. //if (fOldAngle == float.NaN)
  1559. //{
  1560. // return false;
  1561. //}
  1562. //开启校正
  1563. SendMsg("开启校正");
  1564. if (!iSEM.SetTiltAngleOn())
  1565. {
  1566. return false;
  1567. }
  1568. //设置校正角度
  1569. //if (!iSEM.SetTiltAngle(fOldAngle))
  1570. //{
  1571. // return false;
  1572. //}
  1573. //恢复原始状态
  1574. SendMsg("校正角度"+ a_fAngle.ToString());
  1575. if (!iSEM.SetTiltAngle(a_fAngle))
  1576. {
  1577. return false;
  1578. }
  1579. //if (bTilt)
  1580. //{
  1581. // if (!iSEM.SetTiltCorrectionOn())
  1582. // {
  1583. // return false;
  1584. // }
  1585. //}
  1586. //else
  1587. //{
  1588. // if (!iSEM.SetTiltCorrectionOff())
  1589. // {
  1590. // return false;
  1591. // }
  1592. //}
  1593. return true;
  1594. }
  1595. //拍图
  1596. public bool GetImage(ImageMode a_mode, String a_fileName)
  1597. {
  1598. //1. 图像解冻
  1599. float foldFrozen = iSEM.GetImageFrozen();
  1600. if (foldFrozen == float.NaN)
  1601. {
  1602. return false;
  1603. }
  1604. if (!iSEM.ImageLive())
  1605. {
  1606. return false;
  1607. }
  1608. //2. 确认图像模式
  1609. if (ImageMode.SEM == a_mode)
  1610. {
  1611. if (!iSEM.CmdFIBModeSEM())
  1612. {
  1613. return false;
  1614. }
  1615. }
  1616. else if (ImageMode.FIB == a_mode)
  1617. {
  1618. if (!iSEM.CmdFIBModeFIB())
  1619. {
  1620. return false;
  1621. }
  1622. }
  1623. else
  1624. {
  1625. return false;
  1626. }
  1627. //3. 获取分辨率
  1628. int[] ImageSize = iSEM.GetImageStore();
  1629. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  1630. {
  1631. return false;
  1632. }
  1633. short width = (short)ImageSize[0];
  1634. short height = (short)ImageSize[1];
  1635. //4. 抓图
  1636. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  1637. {
  1638. return false;
  1639. }
  1640. //5. 恢复初始状态
  1641. if (foldFrozen == 0)
  1642. {
  1643. if (!iSEM.ImageLive())
  1644. {
  1645. return false;
  1646. }
  1647. }
  1648. else if (foldFrozen == 1)
  1649. {
  1650. if (!iSEM.ImageFrozen())
  1651. {
  1652. return false;
  1653. }
  1654. }
  1655. return true;
  1656. }
  1657. //自动聚焦
  1658. public bool AutoFocus(string a_strPath, out int a_nWd)
  1659. {
  1660. a_nWd = 0;
  1661. a_nWd = (int)Math.Ceiling(iSEM.GetWorkingDistance() * 100000000 + 0.5);//获取当前的工作距离
  1662. return true;
  1663. }
  1664. }
  1665. }