FormUnitControl.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. //时间:
  2. //作者:
  3. //功能:单元测试功能
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.IO;
  16. using SmartSEMControl;
  17. using FileManager;
  18. using System.Xml;
  19. using MeasureData;
  20. using WebManager;
  21. namespace HOZProject
  22. {
  23. public partial class FormUnitControl : Form
  24. {
  25. #region 系统参数
  26. //全局只有一个fatorySEM
  27. static FactoryHardware factorySEM = FactoryHardware.Instance;
  28. ISEMControl iSEM = factorySEM.ISEM;
  29. public XmlManager xmg = new XmlManager();
  30. private String path = Directory.GetCurrentDirectory();
  31. private int st_flag = 0;
  32. WebResult wr = new WebResult("127.0.0.1", "18080", "Huawei/WebServerTest");
  33. #endregion
  34. #region 构造函数
  35. public FormUnitControl()
  36. {
  37. InitializeComponent();
  38. Control.CheckForIllegalCrossThreadCalls = false;
  39. if(iSEM.ConnectStatus())
  40. {
  41. float ret = iSEM.GetFIBIMAGING();
  42. if(ret==0)
  43. {
  44. btnSEM.BackColor = Color.Lime;
  45. }
  46. else if(ret==1)
  47. {
  48. btnFIB.BackColor = Color.Lime;
  49. panelFIB.Visible = true;
  50. }
  51. else if(ret==2)
  52. {
  53. btnMILL.BackColor = Color.Lime;
  54. }
  55. }
  56. //Calling Notification for updated status
  57. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  58. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  59. //加载参数
  60. }
  61. #endregion
  62. #region 缩放Get
  63. private void btnenlargeGet_Click(object sender, EventArgs e)
  64. {
  65. float ret = iSEM.GetMagnification();
  66. if (float.IsNaN(ret))
  67. {
  68. txtenlargeSet.Text = "NaN";
  69. txtenlargeSet.Enabled = false;
  70. btnenlargeSet.Enabled = false;
  71. }
  72. else
  73. {
  74. txtenlargeSet.Text = ret.ToString();
  75. btnenlargeSet.Enabled = true;
  76. }
  77. }
  78. #endregion
  79. #region 缩放Set
  80. private void btnenlargeSet_Click(object sender, EventArgs e)
  81. {
  82. float set = 0;
  83. if (float.TryParse(txtenlargeSet.Text, out set))
  84. {
  85. iSEM.SetMagnification(set);
  86. }
  87. }
  88. #endregion
  89. #region 焦距Get
  90. private void btnWDGet_Click(object sender, EventArgs e)
  91. {
  92. float ret = iSEM.GetWorkingDistance();
  93. if (float.IsNaN(ret))
  94. {
  95. txtWDSet.Text = "NaN";
  96. txtWDSet.Enabled = false;
  97. btnWDSet.Enabled = false;
  98. }
  99. else
  100. {
  101. txtWDSet.Text = ret.ToString();
  102. btnWDSet.Enabled = true;
  103. }
  104. }
  105. #endregion
  106. #region 焦距Set
  107. private void btnWDSet_Click(object sender, EventArgs e)
  108. {
  109. float set = 0;
  110. if (float.TryParse(txtWDSet.Text, out set))
  111. {
  112. iSEM.SetWorkingDistance(set);
  113. }
  114. }
  115. #endregion
  116. #region 亮度Get
  117. private void btnBrightnessGet_Click(object sender, EventArgs e)
  118. {
  119. float ret = iSEM.GetBrightness();
  120. if (float.IsNaN(ret))
  121. {
  122. txtBrightnessSet.Text = "NaN";
  123. txtBrightnessSet.Enabled = false;
  124. btnBrightnessSet.Enabled = false;
  125. }
  126. else
  127. {
  128. txtBrightnessSet.Text = ret.ToString();
  129. btnBrightnessSet.Enabled = true;
  130. }
  131. }
  132. #endregion
  133. #region 亮度Set
  134. private void btnBrightnessSet_Click(object sender, EventArgs e)
  135. {
  136. float set = 0;
  137. if (float.TryParse(txtBrightnessSet.Text, out set))
  138. {
  139. iSEM.SetBrightness(set);
  140. }
  141. }
  142. #endregion
  143. #region 对比度Get
  144. private void btnContrastGet_Click(object sender, EventArgs e)
  145. {
  146. float ret = iSEM.GetContrast();
  147. if (float.IsNaN(ret))
  148. {
  149. txtContrastSet.Text = "NaN";
  150. txtContrastSet.Enabled = false;
  151. btnContrastSet.Enabled = false;
  152. }
  153. else
  154. {
  155. txtContrastSet.Text = ret.ToString();
  156. btnContrastSet.Enabled = true;
  157. }
  158. }
  159. #endregion
  160. #region 对比度Set
  161. private void btnContrastSet_Click(object sender, EventArgs e)
  162. {
  163. float set = 0;
  164. if (float.TryParse(txtContrastSet.Text, out set))
  165. {
  166. iSEM.SetContrast(set);
  167. }
  168. }
  169. #endregion
  170. #region 消像散X Get
  171. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  172. {
  173. float ret = iSEM.GetAstigmatismX();
  174. if (float.IsNaN(ret))
  175. {
  176. txtAstigmatismXSet.Text = "NaN";
  177. txtAstigmatismXSet.Enabled = false;
  178. btnAstigmatismXSet.Enabled = false;
  179. }
  180. else
  181. {
  182. txtAstigmatismXSet.Text = ret.ToString();
  183. btnAstigmatismXSet.Enabled = true;
  184. }
  185. }
  186. #endregion
  187. #region 消像散X Set
  188. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  189. {
  190. float set = 0;
  191. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  192. {
  193. iSEM.SetAstigmatismX(set);
  194. }
  195. }
  196. #endregion
  197. #region 消像散Y Get
  198. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  199. {
  200. float ret = iSEM.GetAstigmatismY();
  201. if (float.IsNaN(ret))
  202. {
  203. txtAstigmatismYSet.Text = "NaN";
  204. txtAstigmatismYSet.Enabled = false;
  205. btnAstigmatismYSet.Enabled = false;
  206. }
  207. else
  208. {
  209. txtAstigmatismYSet.Text = ret.ToString();
  210. btnAstigmatismYSet.Enabled = true;
  211. }
  212. }
  213. #endregion
  214. #region 消像散Y Set
  215. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  216. {
  217. float set = 0;
  218. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  219. {
  220. iSEM.SetAstigmatismY(set);
  221. }
  222. }
  223. #endregion
  224. #region 角度补偿Get
  225. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  226. {
  227. float ret = iSEM.GetTiltAngle();
  228. if (float.IsNaN(ret))
  229. {
  230. txtTiltAngleSet.Text = "NaN";
  231. txtTiltAngleSet.Enabled = false;
  232. btnTiltAngleSet.Enabled = false;
  233. }
  234. else
  235. {
  236. txtTiltAngleSet.Text = ret.ToString();
  237. btnTiltAngleSet.Enabled = true;
  238. }
  239. }
  240. #endregion
  241. #region 角度补偿Set
  242. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  243. {
  244. float set = 0;
  245. if (float.TryParse(txtTiltAngleSet.Text, out set))
  246. {
  247. iSEM.SetTiltAngle(set);
  248. }
  249. }
  250. #endregion
  251. #region 抓取图像
  252. private void btnGrabImage_Click(object sender, EventArgs e)
  253. {
  254. SaveFileDialog sfd = new SaveFileDialog();
  255. sfd.Title = "图像保存位置:";
  256. sfd.FileName = "test.tif";
  257. sfd.Filter = "TIF文件|*.tif";
  258. if (sfd.ShowDialog() == DialogResult.OK)
  259. {
  260. string fn = sfd.FileName;
  261. iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
  262. }
  263. }
  264. #endregion
  265. #region ScanRotate Get
  266. private void btnScanRotationGet_Click(object sender, EventArgs e)
  267. {
  268. float ret = iSEM.GetScanRotation();
  269. if (float.IsNaN(ret))
  270. {
  271. txtScanRotationSet.Text = "NaN";
  272. txtScanRotationSet.Enabled = false;
  273. btnScanRotationSet.Enabled = false;
  274. }
  275. else
  276. {
  277. txtScanRotationSet.Text = ret.ToString();
  278. btnScanRotationSet.Enabled = true;
  279. }
  280. }
  281. #endregion
  282. #region ScanRotate Set
  283. private void btnScanRotationSet_Click(object sender, EventArgs e)
  284. {
  285. float set = 0;
  286. if (float.TryParse(txtScanRotationSet.Text, out set))
  287. {
  288. iSEM.SetScanRotation(set);
  289. }
  290. }
  291. #endregion
  292. #region PixelSize Get
  293. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  294. {
  295. float ret = iSEM.GetPixelSize();
  296. if (float.IsNaN(ret))
  297. {
  298. lblPixelSizeGet.Text = "NaN";
  299. }
  300. else
  301. {
  302. lblPixelSizeGet.Text = ret.ToString();
  303. }
  304. }
  305. #endregion
  306. #region 电子束
  307. private void btnTiltCorrXGet_Click(object sender, EventArgs e)
  308. {
  309. float ret = iSEM.GetBeamShiftX();
  310. if (float.IsNaN(ret))
  311. {
  312. txtTiltCorrX.Text = "NaN";
  313. txtTiltCorrX.Enabled = false;
  314. btnTiltCorrXSet.Enabled = false;
  315. }
  316. else
  317. {
  318. txtTiltCorrX.Text = ret.ToString();
  319. btnTiltCorrXSet.Enabled = true;
  320. }
  321. }
  322. private void btnTiltCorrXSet_Click(object sender, EventArgs e)
  323. {
  324. float set = 0;
  325. if (float.TryParse(txtTiltCorrX.Text, out set))
  326. {
  327. iSEM.SetBeamShiftX(set);
  328. }
  329. }
  330. private void btnTiltCorrYGet_Click(object sender, EventArgs e)
  331. {
  332. float ret = iSEM.GetBeamShiftY();
  333. if (float.IsNaN(ret))
  334. {
  335. txtTiltCorrY.Text = "NaN";
  336. txtTiltCorrY.Enabled = false;
  337. btnTiltCorrYSet.Enabled = false;
  338. }
  339. else
  340. {
  341. txtTiltCorrY.Text = ret.ToString();
  342. btnTiltCorrYSet.Enabled = true;
  343. }
  344. }
  345. private void btnTiltCorrYSet_Click(object sender, EventArgs e)
  346. {
  347. float set = 0;
  348. if (float.TryParse(txtTiltCorrY.Text, out set))
  349. {
  350. iSEM.SetBeamShiftY(set);
  351. }
  352. }
  353. #endregion
  354. #region 开启电压
  355. private void btnOpenVoltage_Click(object sender, EventArgs e)
  356. {
  357. iSEM.CmdOpenVoltage();
  358. }
  359. #endregion
  360. #region 关闭电压
  361. private void btnCloseVoltage_Click(object sender, EventArgs e)
  362. {
  363. iSEM.CmdCloseVoltage();
  364. }
  365. #endregion
  366. #region 电子束校正
  367. private void btnTiltCorr_Click(object sender, EventArgs e)
  368. {
  369. float ret = iSEM.GetTiltCorrection();
  370. if (float.IsNaN(ret))
  371. {
  372. btnTiltCorr.BackColor = Color.Red;
  373. }
  374. else
  375. {
  376. if(ret==0)
  377. {
  378. btnTiltCorr.BackColor = Color.Blue;
  379. iSEM.SetTiltCorrectionOn();
  380. btnTiltCorr.Text = "电子束状态:On";
  381. }
  382. else
  383. {
  384. btnTiltCorr.BackColor = Color.Lime;
  385. iSEM.SetTiltCorrectionOff();
  386. btnTiltCorr.Text = "电子束状态:Off";
  387. }
  388. }
  389. }
  390. #endregion
  391. #region 样品台位置获取
  392. private void btnStageGetX_Click(object sender, EventArgs e)
  393. {
  394. float ret = iSEM.GetStageAtX();
  395. if (float.IsNaN(ret))
  396. {
  397. lblStageX.Text = "NaN";
  398. }
  399. else
  400. {
  401. lblStageX.Text = ret.ToString();
  402. }
  403. }
  404. private void btnStageGetY_Click(object sender, EventArgs e)
  405. {
  406. float ret = iSEM.GetStageAtY();
  407. if (float.IsNaN(ret))
  408. {
  409. lblStageY.Text = "NaN";
  410. }
  411. else
  412. {
  413. lblStageY.Text = ret.ToString();
  414. }
  415. }
  416. private void btnStageGetZ_Click(object sender, EventArgs e)
  417. {
  418. float ret = iSEM.GetStageAtZ();
  419. if (float.IsNaN(ret))
  420. {
  421. lblStageZ.Text = "NaN";
  422. }
  423. else
  424. {
  425. lblStageZ.Text = ret.ToString();
  426. }
  427. }
  428. private void btnStageGetT_Click(object sender, EventArgs e)
  429. {
  430. float ret = iSEM.GetStageAtT();
  431. if (float.IsNaN(ret))
  432. {
  433. lblStageT.Text = "NaN";
  434. }
  435. else
  436. {
  437. lblStageT.Text = ret.ToString();
  438. }
  439. }
  440. private void btnStageGetR_Click(object sender, EventArgs e)
  441. {
  442. float ret = iSEM.GetStageAtR();
  443. if (float.IsNaN(ret))
  444. {
  445. lblStageR.Text = "NaN";
  446. }
  447. else
  448. {
  449. lblStageR.Text = ret.ToString();
  450. }
  451. }
  452. private void btnStageGetM_Click(object sender, EventArgs e)
  453. {
  454. float ret = iSEM.GetStageAtM();
  455. if (float.IsNaN(ret))
  456. {
  457. lblStageM.Text = "NaN";
  458. }
  459. else
  460. {
  461. lblStageM.Text = ret.ToString();
  462. }
  463. }
  464. #endregion
  465. #region 样品台位置设置
  466. private void btnStageSetX_Click(object sender, EventArgs e)
  467. {
  468. float set = 0;
  469. if (float.TryParse(txtStageX.Text, out set))
  470. {
  471. iSEM.SetStageGotoX(set);
  472. }
  473. }
  474. private void btnStageSetY_Click(object sender, EventArgs e)
  475. {
  476. float set = 0;
  477. if (float.TryParse(txtStageY.Text, out set))
  478. {
  479. iSEM.SetStageGotoY(set);
  480. }
  481. }
  482. private void btnStageSetZ_Click(object sender, EventArgs e)
  483. {
  484. float set = 0;
  485. if (float.TryParse(txtStageZ.Text, out set))
  486. {
  487. iSEM.SetStageGotoZ(set);
  488. }
  489. }
  490. private void btnStageSetT_Click(object sender, EventArgs e)
  491. {
  492. float set = 0;
  493. if (float.TryParse(txtStageT.Text, out set))
  494. {
  495. iSEM.SetStageGotoT(set);
  496. }
  497. }
  498. private void btnStageSetR_Click(object sender, EventArgs e)
  499. {
  500. float set = 0;
  501. if (float.TryParse(txtStageR.Text, out set))
  502. {
  503. iSEM.SetStageGotoR(set);
  504. }
  505. }
  506. private void btnStageSetM_Click(object sender, EventArgs e)
  507. {
  508. float set = 0;
  509. if (float.TryParse(txtStageM.Text, out set))
  510. {
  511. iSEM.SetStageGotoM(set);
  512. }
  513. }
  514. #endregion
  515. #region 获取样品台位置数组
  516. private void btnGetStagePosition_Click(object sender, EventArgs e)
  517. {
  518. float[] pt = iSEM.GetStagePosition();
  519. if (!float.IsNaN(pt[0]))
  520. {
  521. lblStageX.Text = pt[0].ToString();
  522. }
  523. if (!float.IsNaN(pt[1]))
  524. {
  525. lblStageY.Text = pt[1].ToString();
  526. }
  527. if (!float.IsNaN(pt[2]))
  528. {
  529. lblStageZ.Text = pt[2].ToString();
  530. }
  531. if (!float.IsNaN(pt[3]))
  532. {
  533. lblStageT.Text = pt[3].ToString();
  534. }
  535. if (!float.IsNaN(pt[4]))
  536. {
  537. lblStageR.Text = pt[4].ToString();
  538. }
  539. if (!float.IsNaN(pt[5]))
  540. {
  541. lblStageM.Text = pt[5].ToString();
  542. }
  543. }
  544. #endregion
  545. #region 窗体关闭
  546. private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
  547. {
  548. if(iSEM!=null)
  549. {
  550. iSEM.Dispose();
  551. }
  552. }
  553. #endregion
  554. #region 宏文件
  555. private void btnCMDMCF_Click(object sender, EventArgs e)
  556. {
  557. iSEM.CMDMCFFilename("OPTON");
  558. }
  559. #endregion
  560. #region 读取Xml文件
  561. private void btnReadXml_Click(object sender, EventArgs e)
  562. {
  563. MeasureFile mf = new MeasureFile();
  564. XmlDocument doc = new XmlDocument();
  565. doc.Load("test_opton.msf");//载入xml文件
  566. XmlNode root = doc.SelectSingleNode("XMLData");
  567. mf.Serialize(false, doc, root);
  568. doc.Save("test_opton.msf");
  569. }
  570. #endregion
  571. #region 写入Xml文件
  572. private void btnWriteXml_Click(object sender, EventArgs e)
  573. {
  574. MeasureFile mf = new MeasureFile();
  575. mf.FileName = path + "\\test_opton.msf";
  576. mf.FilePath = path;
  577. CutHole ch = new CutHole();
  578. ch.OPT = Operation.Image;
  579. ch.START = System.DateTime.Now;
  580. ch.END = System.DateTime.Now.AddHours(2);
  581. ch.STATE = State.Success;
  582. ch.SWITCH = true;
  583. SemPosition sp = new SemPosition();
  584. sp.X = 11;
  585. sp.Y = 22;
  586. sp.Z = 33;
  587. sp.T = 44;
  588. sp.R = 55;
  589. sp.M = 66;
  590. ch.Position = sp;
  591. mf.ListCutHole.Add(ch);
  592. ch = new CutHole();
  593. ch.OPT = Operation.Image;
  594. ch.START = System.DateTime.Now;
  595. ch.END = System.DateTime.Now.AddHours(2);
  596. ch.STATE = State.Success;
  597. ch.SWITCH = true;
  598. sp = new SemPosition();
  599. sp.X = 12;
  600. sp.Y = 34;
  601. sp.Z = 56;
  602. sp.T = 78;
  603. sp.R = 90;
  604. sp.M = 55;
  605. ch.Position = sp;
  606. mf.ListCutHole.Add(ch);
  607. MeasureParam md = new MeasureParam();
  608. md.SampleName = "aaaaaa";
  609. md.PT = true;
  610. md.PTTemp = "bbbbb";
  611. md.FIBTemp = "cccc";
  612. md.FocusMode = false;
  613. mf.MParam = md;
  614. mf.New();
  615. //XmlDocument doc = new XmlDocument();
  616. //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
  617. //XmlNode root = doc.SelectSingleNode("XMLData");
  618. //mf.Serialize(true, doc, root);
  619. //doc.Save("test.aaa");
  620. }
  621. #endregion
  622. #region SEM模式
  623. private void btnSEM_Click(object sender, EventArgs e)
  624. {
  625. if(iSEM.CmdFIBModeSEM())
  626. {
  627. btnFIB.BackColor = SystemColors.Control;
  628. btnSEM.BackColor = Color.Lime;
  629. btnMILL.BackColor = SystemColors.Control;
  630. panelFIB.Visible = false;
  631. }
  632. }
  633. #endregion
  634. #region FIB模式
  635. private void btnFIB_Click(object sender, EventArgs e)
  636. {
  637. if(iSEM.CmdFIBModeFIB())
  638. {
  639. btnFIB.BackColor = Color.Lime;
  640. btnSEM.BackColor = SystemColors.Control;
  641. btnMILL.BackColor = SystemColors.Control;
  642. panelFIB.Visible = true;
  643. }
  644. }
  645. #endregion
  646. #region MILL模式
  647. private void btnMILL_Click(object sender, EventArgs e)
  648. {
  649. if(iSEM.CmdFIBModeMILL())
  650. {
  651. btnFIB.BackColor = SystemColors.Control;
  652. btnSEM.BackColor = SystemColors.Control;
  653. btnMILL.BackColor = Color.Lime;
  654. }
  655. }
  656. #endregion
  657. #region 自动对焦1
  658. private void btnAutoFocus1_Click(object sender, EventArgs e)
  659. {
  660. //抓图1
  661. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  662. if (File.Exists(path + "\\test1.tif"))
  663. {
  664. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  665. pictureBox1.Image = Image.FromStream(fileStream);
  666. fileStream.Close();
  667. fileStream.Dispose();
  668. }
  669. Thread.Sleep(1000);
  670. iSEM.CmdAutoFocusCoarse();
  671. btnAutoFocus1.BackColor = Color.Red;
  672. st_flag = 1;
  673. Thread.Sleep(1000);
  674. Thread thread = new Thread(AutoFunction);
  675. thread.Start();
  676. }
  677. #endregion
  678. #region 自动函数监测线程
  679. private void AutoFunction()
  680. {
  681. float ret = 111;
  682. Boolean state = false;
  683. while(true)
  684. {
  685. Thread.Sleep(1000);
  686. ret = iSEM.GetAutoFunction();
  687. if(ret==0)
  688. {
  689. if (st_flag == 1 && state == true)
  690. {
  691. btnAutoFocus1.BackColor = Color.Lime;
  692. Thread.Sleep(1000);
  693. //抓图1
  694. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  695. if (File.Exists(path + "\\test2.tif"))
  696. {
  697. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  698. pictureBox2.Image = Image.FromStream(fileStream);
  699. fileStream.Close();
  700. fileStream.Dispose();
  701. }
  702. break;
  703. }
  704. else if(st_flag==2 && state)
  705. {
  706. btnAutoFocus2.BackColor = Color.Lime;
  707. Thread.Sleep(1000);
  708. //抓图1
  709. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  710. if (File.Exists(path + "\\test2.tif"))
  711. {
  712. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  713. pictureBox2.Image = Image.FromStream(fileStream);
  714. fileStream.Close();
  715. fileStream.Dispose();
  716. }
  717. break;
  718. }
  719. else if (st_flag == 3)
  720. {
  721. btnAutoBrightness.BackColor = Color.Lime;
  722. Thread.Sleep(1000);
  723. //抓图1
  724. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  725. if (File.Exists(path + "\\test2.tif"))
  726. {
  727. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  728. pictureBox2.Image = Image.FromStream(fileStream);
  729. fileStream.Close();
  730. fileStream.Dispose();
  731. }
  732. break;
  733. }
  734. else if (st_flag == 4)
  735. {
  736. btnAutoContrast.BackColor = Color.Lime;
  737. Thread.Sleep(1000);
  738. //抓图1
  739. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  740. if (File.Exists(path + "\\test2.tif"))
  741. {
  742. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  743. pictureBox2.Image = Image.FromStream(fileStream);
  744. fileStream.Close();
  745. fileStream.Dispose();
  746. }
  747. break;
  748. }
  749. else if (st_flag == 5)
  750. {
  751. btnAutoBrightness.BackColor = Color.Lime;
  752. btnAutoContrast.BackColor = Color.Lime;
  753. btnAutoBC.BackColor = Color.Lime;
  754. Thread.Sleep(1000);
  755. //抓图1
  756. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  757. if (File.Exists(path + "\\test2.tif"))
  758. {
  759. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  760. pictureBox2.Image = Image.FromStream(fileStream);
  761. fileStream.Close();
  762. fileStream.Dispose();
  763. }
  764. break;
  765. }
  766. else if (st_flag == 6 && state)
  767. {
  768. btnAutoBCCancle.BackColor = Color.Lime;
  769. Thread.Sleep(1000);
  770. //抓图1
  771. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  772. if (File.Exists(path + "\\test2.tif"))
  773. {
  774. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  775. pictureBox2.Image = Image.FromStream(fileStream);
  776. fileStream.Close();
  777. fileStream.Dispose();
  778. }
  779. break;
  780. }
  781. else if (st_flag == 7 && state)
  782. {
  783. btnAutoStig.BackColor = Color.Lime;
  784. Thread.Sleep(1000);
  785. //抓图1
  786. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  787. if (File.Exists(path + "\\test2.tif"))
  788. {
  789. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  790. pictureBox2.Image = Image.FromStream(fileStream);
  791. fileStream.Close();
  792. fileStream.Dispose();
  793. }
  794. break;
  795. }
  796. ////抓图1
  797. //iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  798. //if (File.Exists(path + "\\test2.tif"))
  799. //{
  800. // FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  801. // pictureBox2.Image = Image.FromStream(fileStream);
  802. // fileStream.Close();
  803. // fileStream.Dispose();
  804. //}
  805. }
  806. else if(ret>0 && ret<12)
  807. {
  808. state = true;
  809. }
  810. }
  811. }
  812. #endregion
  813. #region 自动对焦2
  814. private void btnAutoFocus2_Click(object sender, EventArgs e)
  815. {
  816. //抓图1
  817. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  818. if (File.Exists(path + "\\test1.tif"))
  819. {
  820. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  821. pictureBox1.Image = Image.FromStream(fileStream);
  822. fileStream.Close();
  823. fileStream.Dispose();
  824. }
  825. Thread.Sleep(1000);
  826. iSEM.CmdAutoFocusFine();
  827. btnAutoFocus2.BackColor = Color.Red;
  828. st_flag = 2;
  829. Thread.Sleep(1000);
  830. Thread thread = new Thread(AutoFunction);
  831. thread.Start();
  832. }
  833. #endregion
  834. #region 自动亮度、对比度
  835. private void btnAutoBrightness_Click(object sender, EventArgs e)
  836. {
  837. //抓图1
  838. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  839. if (File.Exists(path + "\\test1.tif"))
  840. {
  841. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  842. pictureBox1.Image = Image.FromStream(fileStream);
  843. fileStream.Close();
  844. fileStream.Dispose();
  845. }
  846. Thread.Sleep(1000);
  847. iSEM.SetAutoVideoBrightness();
  848. btnAutoBrightness.BackColor = Color.Red;
  849. st_flag = 3;
  850. Thread.Sleep(1000);
  851. Thread thread = new Thread(AutoFunction);
  852. thread.Start();
  853. }
  854. private void btnAutoContrast_Click(object sender, EventArgs e)
  855. {
  856. //抓图1
  857. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  858. if (File.Exists(path + "\\test1.tif"))
  859. {
  860. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  861. pictureBox1.Image = Image.FromStream(fileStream);
  862. fileStream.Close();
  863. fileStream.Dispose();
  864. }
  865. Thread.Sleep(1000);
  866. iSEM.SetAutoVideoBrightness();
  867. btnAutoContrast.BackColor = Color.Red;
  868. st_flag = 4;
  869. Thread.Sleep(1000);
  870. Thread thread = new Thread(AutoFunction);
  871. thread.Start();
  872. }
  873. private void btnAutoBC_Click(object sender, EventArgs e)
  874. {
  875. //抓图1
  876. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  877. if (File.Exists(path + "\\test1.tif"))
  878. {
  879. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  880. pictureBox1.Image = Image.FromStream(fileStream);
  881. fileStream.Close();
  882. fileStream.Dispose();
  883. }
  884. Thread.Sleep(1000);
  885. iSEM.SetAutoVideoBrightness();
  886. btnAutoBrightness.BackColor = Color.Red;
  887. btnAutoContrast.BackColor = Color.Red;
  888. btnAutoBC.BackColor = Color.Red;
  889. st_flag = 5;
  890. Thread.Sleep(1000);
  891. Thread thread = new Thread(AutoFunction);
  892. thread.Start();
  893. }
  894. private void btnAutoBCCancle_Click(object sender, EventArgs e)
  895. {
  896. iSEM.SetAutoVideoOff();
  897. btnAutoBCCancle.BackColor = Color.Red;
  898. st_flag = 6;
  899. Thread.Sleep(1000);
  900. Thread thread = new Thread(AutoFunction);
  901. thread.Start();
  902. }
  903. #endregion
  904. #region 自动消像散
  905. private void btnAutoStig_Click(object sender, EventArgs e)
  906. {
  907. //抓图1
  908. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  909. if (File.Exists(path + "\\test1.tif"))
  910. {
  911. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  912. pictureBox1.Image = Image.FromStream(fileStream);
  913. fileStream.Close();
  914. fileStream.Dispose();
  915. }
  916. Thread.Sleep(1000);
  917. iSEM.CmdAutoStig();
  918. btnAutoStig.BackColor = Color.Red;
  919. st_flag = 7;
  920. Thread.Sleep(1000);
  921. Thread thread = new Thread(AutoFunction);
  922. thread.Start();
  923. }
  924. #endregion
  925. #region FIB缩放Get
  926. private void btnFIBMagGet_Click(object sender, EventArgs e)
  927. {
  928. float ret = iSEM.GetFIBMagnification();
  929. if (float.IsNaN(ret))
  930. {
  931. txtFIBMag.Text = "NaN";
  932. txtFIBMag.Enabled = false;
  933. btnFIBMagSet.Enabled = false;
  934. }
  935. else
  936. {
  937. txtFIBMag.Text = ret.ToString();
  938. btnFIBMagSet.Enabled = true;
  939. }
  940. }
  941. #endregion
  942. #region FIB缩放Set
  943. private void btnFIBMagSet_Click(object sender, EventArgs e)
  944. {
  945. float set = 0;
  946. if (float.TryParse(txtFIBMag.Text, out set))
  947. {
  948. iSEM.SetFIBMagnification(set);
  949. }
  950. }
  951. #endregion
  952. #region FIB焦距Get
  953. private void btnFIBWDGet_Click(object sender, EventArgs e)
  954. {
  955. float ret = iSEM.GetFIBObjectivePotential();
  956. if (float.IsNaN(ret))
  957. {
  958. txtFIBWD.Text = "NaN";
  959. txtFIBWD.Enabled = false;
  960. btnFIBWDSet.Enabled = false;
  961. }
  962. else
  963. {
  964. txtFIBWD.Text = ret.ToString();
  965. btnFIBWDSet.Enabled = true;
  966. }
  967. }
  968. #endregion
  969. #region FIB焦距Set
  970. private void btnFIBWDSet_Click(object sender, EventArgs e)
  971. {
  972. float set = 0;
  973. if (float.TryParse(txtFIBWD.Text, out set))
  974. {
  975. iSEM.SetFIBObjectivePotential(set);
  976. }
  977. }
  978. #endregion
  979. #region FIB电子束移动
  980. private void btnFIBBeamShiftXGet_Click(object sender, EventArgs e)
  981. {
  982. float ret = iSEM.GetFIBBeamShiftX();
  983. if (float.IsNaN(ret))
  984. {
  985. txtFIBBeamShiftX.Text = "NaN";
  986. txtFIBBeamShiftX.Enabled = false;
  987. btnFIBBeamShiftXSet.Enabled = false;
  988. }
  989. else
  990. {
  991. txtFIBBeamShiftX.Text = ret.ToString();
  992. btnFIBBeamShiftXSet.Enabled = true;
  993. }
  994. }
  995. private void btnFIBBeamShiftXSet_Click(object sender, EventArgs e)
  996. {
  997. float set = 0;
  998. if (float.TryParse(txtFIBBeamShiftX.Text, out set))
  999. {
  1000. iSEM.SetFIBBeamShiftX(set);
  1001. }
  1002. }
  1003. private void btnFIBBeamShiftYGet_Click(object sender, EventArgs e)
  1004. {
  1005. float ret = iSEM.GetFIBBeamShiftY();
  1006. if (float.IsNaN(ret))
  1007. {
  1008. txtFIBBeamShiftY.Text = "NaN";
  1009. txtFIBBeamShiftY.Enabled = false;
  1010. btnFIBBeamShiftYSet.Enabled = false;
  1011. }
  1012. else
  1013. {
  1014. txtFIBBeamShiftY.Text = ret.ToString();
  1015. btnFIBBeamShiftYSet.Enabled = true;
  1016. }
  1017. }
  1018. private void btnFIBBeamShiftYSet_Click(object sender, EventArgs e)
  1019. {
  1020. float set = 0;
  1021. if (float.TryParse(txtFIBBeamShiftY.Text, out set))
  1022. {
  1023. iSEM.SetFIBBeamShiftY(set);
  1024. }
  1025. }
  1026. #endregion
  1027. #region 执行宏文件
  1028. private void btnMCF_Click(object sender, EventArgs e)
  1029. {
  1030. OpenFileDialog sfd = new OpenFileDialog();
  1031. sfd.Title = "选择宏文件:";
  1032. sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1033. sfd.Filter = "MLF文件|*.MLF";
  1034. if (sfd.ShowDialog() == DialogResult.OK)
  1035. {
  1036. string fn = Path.GetFileNameWithoutExtension(sfd.FileName).ToUpper();
  1037. iSEM.CMDMCFFilename(fn);
  1038. }
  1039. }
  1040. #endregion
  1041. #region FIB消像散
  1042. private void btnFIBAstigmatismXGet_Click(object sender, EventArgs e)
  1043. {
  1044. float ret = iSEM.GetFIBAstigmatismX();
  1045. if (float.IsNaN(ret))
  1046. {
  1047. txtFIBAstigmatismX.Text = "NaN";
  1048. txtFIBAstigmatismX.Enabled = false;
  1049. btnFIBAstigmatismXSet.Enabled = false;
  1050. }
  1051. else
  1052. {
  1053. txtFIBAstigmatismX.Text = ret.ToString();
  1054. btnFIBAstigmatismXSet.Enabled = true;
  1055. }
  1056. }
  1057. private void btnFIBAstigmatismXSet_Click(object sender, EventArgs e)
  1058. {
  1059. float set = 0;
  1060. if (float.TryParse(txtFIBAstigmatismX.Text, out set))
  1061. {
  1062. iSEM.SetFIBAstigmatismX(set);
  1063. }
  1064. }
  1065. private void btnFIBAstigmatismYGet_Click(object sender, EventArgs e)
  1066. {
  1067. float ret = iSEM.GetFIBAstigmatismY();
  1068. if (float.IsNaN(ret))
  1069. {
  1070. txtFIBAstigmatismY.Text = "NaN";
  1071. txtFIBAstigmatismY.Enabled = false;
  1072. btnFIBAstigmatismYSet.Enabled = false;
  1073. }
  1074. else
  1075. {
  1076. txtFIBAstigmatismY.Text = ret.ToString();
  1077. btnFIBAstigmatismYSet.Enabled = true;
  1078. }
  1079. }
  1080. private void btnFIBAstigmatismYSet_Click(object sender, EventArgs e)
  1081. {
  1082. float set = 0;
  1083. if (float.TryParse(txtFIBAstigmatismY.Text, out set))
  1084. {
  1085. iSEM.SetFIBAstigmatismY(set);
  1086. }
  1087. }
  1088. #endregion
  1089. #region 移动样品台XY
  1090. private void btnMoveXY_Click(object sender, EventArgs e)
  1091. {
  1092. float setx = 0;
  1093. float sety = 0;
  1094. if (!float.TryParse(txtStageX.Text, out setx))
  1095. {
  1096. return;
  1097. }
  1098. if(!float.TryParse(txtStageY.Text,out sety))
  1099. {
  1100. return;
  1101. }
  1102. btnMoveXY.BackColor = Color.Red;
  1103. iSEM.MoveStageXY(setx, sety);
  1104. Thread.Sleep(500);
  1105. Thread th = new Thread(MoveStagexy);
  1106. th.Start();
  1107. }
  1108. private void MoveStagexy()
  1109. {
  1110. float ret = 111;
  1111. while(true)
  1112. {
  1113. ret = iSEM.GetStageIs();
  1114. if(ret==0)
  1115. {
  1116. btnMoveXY.BackColor = Color.Lime;
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. #endregion
  1122. #region 获取分辨率
  1123. private void btnImageStoreGet_Click(object sender, EventArgs e)
  1124. {
  1125. int[] ret = iSEM.GetImageStore();
  1126. lblImageStore.Text = ret[0].ToString() + "*" + ret[1].ToString();
  1127. }
  1128. #endregion
  1129. #region 设置分辨率
  1130. private void btnImageStoreSet_Click(object sender, EventArgs e)
  1131. {
  1132. if (cmbImageStore.SelectedIndex > -1 && cmbImageStore.SelectedIndex < 12)
  1133. {
  1134. iSEM.SetImageStore(cmbImageStore.SelectedIndex);
  1135. }
  1136. }
  1137. #endregion
  1138. #region 样品台急停
  1139. private void btnAbort_Click(object sender, EventArgs e)
  1140. {
  1141. iSEM.CmdStageAbort();
  1142. }
  1143. #endregion
  1144. private void btnLive_Click(object sender, EventArgs e)
  1145. {
  1146. iSEM.ImageLive();
  1147. }
  1148. private void btnFrozen_Click(object sender, EventArgs e)
  1149. {
  1150. iSEM.ImageFrozen();
  1151. }
  1152. private void btnExeEly_Click(object sender, EventArgs e)
  1153. {
  1154. iSEM.CmdFIBLoadELY(@"E:\HOZ\MillStep2.ely");
  1155. }
  1156. private void btnExeEly2_Click(object sender, EventArgs e)
  1157. {
  1158. iSEM.CmdFIBLoadELY(@"E:\HOZ\MillStep4.ely");
  1159. }
  1160. private void btnFIBStatus_Click(object sender, EventArgs e)
  1161. {
  1162. btnFIBStatus.Text = iSEM.GetFIBApiStatus().ToString();
  1163. }
  1164. //测量线程测试
  1165. private void button1_Click(object sender, EventArgs e)
  1166. {
  1167. FormMeasureTest Measure = new FormMeasureTest();
  1168. Measure.Show();
  1169. }
  1170. private void btnPost1_Click(object sender, EventArgs e)
  1171. {
  1172. double degree = 0;
  1173. int direction = 0;
  1174. int state = 0;
  1175. wr.Img_OffsetAngle_Direction("D:/aaaa.jpg", out degree, out direction, out state);
  1176. lbldegree1.Text = degree.ToString("0.0");
  1177. lbldirection1.Text = direction.ToString();
  1178. lblstate1.Text = state.ToString();
  1179. }
  1180. private void btnPost2_Click(object sender, EventArgs e)
  1181. {
  1182. double offsetx = 0;
  1183. double offsety = 0;
  1184. int state = 0;
  1185. wr.Img_Cut_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
  1186. lbllocationx.Text = offsetx.ToString("0.0");
  1187. lbllocationy.Text = offsety.ToString("0.0");
  1188. lblstate2.Text = state.ToString();
  1189. }
  1190. private void btnPost3_Click(object sender, EventArgs e)
  1191. {
  1192. int state = 0;
  1193. wr.Img_Cut_Success("D:/aaaa.jpg", "D:/bbbb.jpg", out state);
  1194. lblstate3.Text = state.ToString();
  1195. }
  1196. private void btnPost4_Click(object sender, EventArgs e)
  1197. {
  1198. double offsetx = 0;
  1199. double offsety = 0;
  1200. int state = 0;
  1201. wr.Img_Trapezoid_Top_Center_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
  1202. lbltopcx.Text = offsetx.ToString("0.0");
  1203. lbltopcy.Text = offsety.ToString("0.0");
  1204. lblstate4.Text = state.ToString();
  1205. }
  1206. private void btnPost5_Click(object sender, EventArgs e)
  1207. {
  1208. List<string> filenames = new List<string>();
  1209. filenames.Add("1111111");
  1210. filenames.Add("2222222");
  1211. filenames.Add("3333333");
  1212. lblfocuspath.Text = wr.Img_Auto_Focus(filenames);
  1213. }
  1214. private void btnPost6_Click(object sender, EventArgs e)
  1215. {
  1216. List<string> filenames = new List<string>();
  1217. filenames.Add("1111111");
  1218. filenames.Add("2222222");
  1219. filenames.Add("3333333");
  1220. lblstigpath.Text = wr.Img_Auto_Focus(filenames);
  1221. }
  1222. private void btnPost7_Click(object sender, EventArgs e)
  1223. {
  1224. double offsetx = 0;
  1225. double offsety = 0;
  1226. double degree = 0;
  1227. int direction = 0;
  1228. int state = 0;
  1229. wr.Img_Center_Position_OffsetAngle_Direction("D:/aaaa.jpg", out offsetx, out offsety, out degree, out direction, out state);
  1230. lblcenterx.Text = offsetx.ToString("0.0");
  1231. lblcentery.Text = offsety.ToString("0.0");
  1232. lbldegree2.Text = degree.ToString();
  1233. lbldirection2.Text = direction.ToString();
  1234. lblstate5.Text = state.ToString();
  1235. }
  1236. private void btnPost8_Click(object sender, EventArgs e)
  1237. {
  1238. int state = 0;
  1239. wr.Img_Measure_Size("D:/aaaa.jpg", "1000", "0.005", out state);
  1240. lblstate6.Text = state.ToString();
  1241. }
  1242. }
  1243. }