FormUnitControl.cs 39 KB

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