FormUnitControl.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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. }