FormUnitControl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. namespace HOZProject
  18. {
  19. public partial class FormUnitControl : Form
  20. {
  21. #region 系统参数
  22. private String path = Directory.GetCurrentDirectory();
  23. private SmartSEM sem = new SmartSEM();
  24. #endregion
  25. #region 构造函数
  26. public FormUnitControl()
  27. {
  28. InitializeComponent();
  29. //Calling Notification for updated status
  30. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  31. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  32. //加载参数
  33. }
  34. #endregion
  35. #region 设备初始化按键
  36. private void btnInit_Click(object sender, EventArgs e)
  37. {
  38. if (sem.Init())
  39. {
  40. btnInit.BackColor = Color.Lime;
  41. }
  42. else
  43. {
  44. btnInit.BackColor = Color.Red;
  45. }
  46. }
  47. #endregion
  48. #region 设备关闭按键
  49. private void btnCloseCtrl_Click(object sender, EventArgs e)
  50. {
  51. if (sem.Dispose())
  52. {
  53. btnInit.BackColor = Control.DefaultBackColor;
  54. }
  55. }
  56. #endregion
  57. #region 设置参数更新通知
  58. private void btnSetNotify_Click(object sender, EventArgs e)
  59. {
  60. //if (m_bInitialised)
  61. //{
  62. // // Magnification
  63. // if (CZEMApi.SetNotify("AP_MAG", 1) != 0)
  64. // {
  65. // DisplayError("SetNotify", "AP_MAG");
  66. // return;
  67. // }
  68. // // Working distance
  69. // if (CZEMApi.SetNotify("AP_WD", 1) != 0)
  70. // {
  71. // DisplayError("SetNotify", "AP_WD");
  72. // return;
  73. // }
  74. // // BRIGHTNESS 亮度
  75. // if (CZEMApi.SetNotify("AP_BRIGHTNESS", 1) != 0)
  76. // {
  77. // DisplayError("SetNotify", "AP_BRIGHTNESS");
  78. // return;
  79. // }
  80. // // AP_CONTRAST,对比度
  81. // if (CZEMApi.SetNotify("AP_CONTRAST", 1) != 0)
  82. // {
  83. // DisplayError("SetNotify", "AP_CONTRAST");
  84. // return;
  85. // }
  86. // // Vacuum
  87. // if (CZEMApi.SetNotify("DP_VACSTATUS", 1) != 0)
  88. // {
  89. // DisplayError("SetNotify", "DP_VACSTATUS");
  90. // return;
  91. // }
  92. // // Gun / EHT state
  93. // if (CZEMApi.SetNotify("DP_RUNUPSTATE", 1) != 0)
  94. // {
  95. // DisplayError("SetNotify", "DP_RUNUPSTATE");
  96. // return;
  97. // }
  98. // // actual KV / EHT
  99. // if (CZEMApi.SetNotify("AP_ACTUALKV", 1) != 0)
  100. // {
  101. // DisplayError("SetNotify", "AP_ACTUALKV");
  102. // return;
  103. // }
  104. // // actual current
  105. // if (CZEMApi.SetNotify("AP_ACTUALCURRENT", 1) != 0)
  106. // {
  107. // DisplayError("SetNotify", "AP_ACTUALCURRENT");
  108. // return;
  109. // }
  110. // // column type
  111. // if (CZEMApi.SetNotify("DP_COLUMN_TYPE", 1) != 0)
  112. // {
  113. // DisplayError("SetNotify", "DP_COLUMN_TYPE");
  114. // return;
  115. // }
  116. // // mode
  117. // if (CZEMApi.SetNotify("DP_OPERATING_MODE", 1) != 0)
  118. // {
  119. // DisplayError("SetNotify", "DP_OPERATING_MODE");
  120. // return;
  121. // }
  122. // // scan rate
  123. // if (CZEMApi.SetNotify("DP_SCANRATE", 1) != 0)
  124. // {
  125. // DisplayError("SetNotify", "DP_SCANRATE");
  126. // return;
  127. // }
  128. // // auto function active
  129. // if (CZEMApi.SetNotify("DP_AUTO_FUNCTION", 1) != 0)
  130. // {
  131. // DisplayError("SetNotify", "DP_AUTO_FUNCTION");
  132. // return;
  133. // }
  134. // // probe current
  135. // if (CZEMApi.SetNotify("AP_IPROBE", 1) != 0)
  136. // {
  137. // DisplayError("SetNotify", "AP_IPROBE");
  138. // return;
  139. // }
  140. // // detector
  141. // if (CZEMApi.SetNotify("DP_DETECTOR_TYPE", 1) != 0)
  142. // {
  143. // DisplayError("SetNotify", "DP_DETECTOR_TYPE");
  144. // return;
  145. // }
  146. // // stage initialised
  147. // if (CZEMApi.SetNotify("DP_STAGE_INIT", 1) != 0)
  148. // {
  149. // DisplayError("SetNotify", "DP_STAGE_INIT");
  150. // return;
  151. // }
  152. // // stage busy?
  153. // if (CZEMApi.SetNotify("DP_STAGE_IS", 1) != 0)
  154. // {
  155. // DisplayError("SetNotify", "DP_STAGE_IS");
  156. // return;
  157. // }
  158. // // fib mode
  159. // if (CZEMApi.SetNotify("DP_FIB_MODE", 1) != 0)
  160. // {
  161. // DisplayError("SetNotify", "DP_FIB_MODE");
  162. // return;
  163. // }
  164. // // fib gun state
  165. // if (CZEMApi.SetNotify("DP_FIB_GUN_STATE", 1) != 0)
  166. // {
  167. // DisplayError("SetNotify", "DP_FIB_GUN_STATE");
  168. // return;
  169. // }
  170. //listmsg.Items.Add("Notification enabled");
  171. // }
  172. }
  173. #endregion
  174. #region 缩放Get
  175. private void btnenlargeGet_Click(object sender, EventArgs e)
  176. {
  177. float ret = sem.GetMagnification();
  178. if (float.IsNaN(ret))
  179. {
  180. lblenlargeGet.Text = "NaN";
  181. txtenlargeSet.Enabled = false;
  182. btnenlargeSet.Enabled = false;
  183. }
  184. else
  185. {
  186. lblenlargeGet.Text = ret.ToString();
  187. txtenlargeSet.Text = ret.ToString();
  188. btnenlargeSet.Enabled = true;
  189. }
  190. }
  191. #endregion
  192. #region 缩放Set
  193. private void btnenlargeSet_Click(object sender, EventArgs e)
  194. {
  195. float set = 0;
  196. if (float.TryParse(txtenlargeSet.Text, out set))
  197. {
  198. sem.SetMagnification(set);
  199. }
  200. }
  201. #endregion
  202. #region 焦距Get
  203. private void btnWDGet_Click(object sender, EventArgs e)
  204. {
  205. float ret = sem.GetWorkingDistance();
  206. if (float.IsNaN(ret))
  207. {
  208. lblWDGet.Text = "NaN";
  209. txtWDSet.Enabled = false;
  210. btnWDSet.Enabled = false;
  211. }
  212. else
  213. {
  214. lblWDGet.Text = ret.ToString();
  215. txtWDSet.Text = ret.ToString();
  216. btnWDSet.Enabled = true;
  217. }
  218. }
  219. #endregion
  220. #region 焦距Set
  221. private void btnWDSet_Click(object sender, EventArgs e)
  222. {
  223. float set = 0;
  224. if (float.TryParse(txtWDSet.Text, out set))
  225. {
  226. sem.SetWorkingDistance(set);
  227. }
  228. }
  229. #endregion
  230. #region 亮度Get
  231. private void btnBrightnessGet_Click(object sender, EventArgs e)
  232. {
  233. float ret = sem.GetBrightness();
  234. if (float.IsNaN(ret))
  235. {
  236. lblBrightnessGet.Text = "NaN";
  237. txtBrightnessSet.Enabled = false;
  238. btnBrightnessSet.Enabled = false;
  239. }
  240. else
  241. {
  242. lblBrightnessGet.Text = ret.ToString();
  243. txtBrightnessSet.Text = ret.ToString();
  244. btnBrightnessSet.Enabled = true;
  245. }
  246. }
  247. #endregion
  248. #region 亮度Set
  249. private void btnBrightnessSet_Click(object sender, EventArgs e)
  250. {
  251. float set = 0;
  252. if (float.TryParse(txtBrightnessSet.Text, out set))
  253. {
  254. sem.SetBrightness(set);
  255. }
  256. }
  257. #endregion
  258. #region 对比度Get
  259. private void btnContrastGet_Click(object sender, EventArgs e)
  260. {
  261. float ret = sem.GetContrast();
  262. if (float.IsNaN(ret))
  263. {
  264. lblContrastGet.Text = "NaN";
  265. txtContrastSet.Enabled = false;
  266. btnContrastSet.Enabled = false;
  267. }
  268. else
  269. {
  270. lblContrastGet.Text = ret.ToString();
  271. txtContrastSet.Text = ret.ToString();
  272. btnContrastSet.Enabled = true;
  273. }
  274. }
  275. #endregion
  276. #region 对比度Set
  277. private void btnContrastSet_Click(object sender, EventArgs e)
  278. {
  279. float set = 0;
  280. if (float.TryParse(txtContrastSet.Text, out set))
  281. {
  282. sem.SetContrast(set);
  283. }
  284. }
  285. #endregion
  286. #region 消像散X Get
  287. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  288. {
  289. float ret = sem.GetAstigmatismX();
  290. if (float.IsNaN(ret))
  291. {
  292. lblAstigmatismXGet.Text = "NaN";
  293. txtAstigmatismXSet.Enabled = false;
  294. btnAstigmatismXSet.Enabled = false;
  295. }
  296. else
  297. {
  298. lblAstigmatismXGet.Text = ret.ToString();
  299. txtAstigmatismXSet.Text = ret.ToString();
  300. btnAstigmatismXSet.Enabled = true;
  301. }
  302. }
  303. #endregion
  304. #region 消像散X Set
  305. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  306. {
  307. float set = 0;
  308. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  309. {
  310. sem.SetAstigmatismX(set);
  311. }
  312. }
  313. #endregion
  314. #region 消像散Y Get
  315. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  316. {
  317. float ret = sem.GetAstigmatismY();
  318. if (float.IsNaN(ret))
  319. {
  320. lblAstigmatismYGet.Text = "NaN";
  321. txtAstigmatismYSet.Enabled = false;
  322. btnAstigmatismYSet.Enabled = false;
  323. }
  324. else
  325. {
  326. lblAstigmatismYGet.Text = ret.ToString();
  327. txtAstigmatismYSet.Text = ret.ToString();
  328. btnAstigmatismYSet.Enabled = true;
  329. }
  330. }
  331. #endregion
  332. #region 消像散Y Set
  333. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  334. {
  335. float set = 0;
  336. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  337. {
  338. sem.SetAstigmatismY(set);
  339. }
  340. }
  341. #endregion
  342. #region 角度补偿Get
  343. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  344. {
  345. float ret = sem.GetTiltAngle();
  346. if (float.IsNaN(ret))
  347. {
  348. lblTiltAngleGet.Text = "NaN";
  349. txtTiltAngleSet.Enabled = false;
  350. btnTiltAngleSet.Enabled = false;
  351. }
  352. else
  353. {
  354. lblTiltAngleGet.Text = ret.ToString();
  355. txtTiltAngleSet.Text = ret.ToString();
  356. btnTiltAngleSet.Enabled = true;
  357. }
  358. }
  359. #endregion
  360. #region 角度补偿Set
  361. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  362. {
  363. float set = 0;
  364. if (float.TryParse(txtTiltAngleSet.Text, out set))
  365. {
  366. sem.SetTiltAngle(set);
  367. }
  368. }
  369. #endregion
  370. #region 抓取图像
  371. private void btnGrabImage_Click(object sender, EventArgs e)
  372. {
  373. SaveFileDialog sfd = new SaveFileDialog();
  374. sfd.Title = "图像保存位置:";
  375. sfd.FileName = "test.tif";
  376. sfd.Filter = "TIF文件|*.tif";
  377. if (sfd.ShowDialog() == DialogResult.OK)
  378. {
  379. string fn = sfd.FileName;
  380. sem.GrabImage(fn, 0);
  381. }
  382. }
  383. #endregion
  384. #region ScanRotate Get
  385. private void btnScanRotationGet_Click(object sender, EventArgs e)
  386. {
  387. float ret = sem.GetScanRotation();
  388. if (float.IsNaN(ret))
  389. {
  390. lblScanRotationGet.Text = "NaN";
  391. txtScanRotationSet.Enabled = false;
  392. btnScanRotationSet.Enabled = false;
  393. }
  394. else
  395. {
  396. lblScanRotationGet.Text = ret.ToString();
  397. txtScanRotationSet.Text = ret.ToString();
  398. btnScanRotationSet.Enabled = true;
  399. }
  400. }
  401. #endregion
  402. #region ScanRotate Set
  403. private void btnScanRotationSet_Click(object sender, EventArgs e)
  404. {
  405. float set = 0;
  406. if (float.TryParse(txtScanRotationSet.Text, out set))
  407. {
  408. sem.SetScanRotation(set);
  409. }
  410. }
  411. #endregion
  412. #region PixelSize Get
  413. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  414. {
  415. float ret = sem.GetPixelSize();
  416. if (float.IsNaN(ret))
  417. {
  418. lblPixelSizeGet.Text = "NaN";
  419. }
  420. else
  421. {
  422. lblPixelSizeGet.Text = ret.ToString();
  423. }
  424. }
  425. #endregion
  426. #region 开启电压
  427. private void btnOpenVoltage_Click(object sender, EventArgs e)
  428. {
  429. sem.CmdOpenVoltage();
  430. }
  431. #endregion
  432. #region 关闭电压
  433. private void btnCloseVoltage_Click(object sender, EventArgs e)
  434. {
  435. sem.CmdCloseVoltage();
  436. }
  437. #endregion
  438. #region 样品台位置获取
  439. private void btnStageGetX_Click(object sender, EventArgs e)
  440. {
  441. float ret = sem.GetStageAtX();
  442. if (float.IsNaN(ret))
  443. {
  444. lblStageX.Text = "NaN";
  445. }
  446. else
  447. {
  448. lblStageX.Text = ret.ToString();
  449. }
  450. }
  451. private void btnStageGetY_Click(object sender, EventArgs e)
  452. {
  453. float ret = sem.GetStageAtY();
  454. if (float.IsNaN(ret))
  455. {
  456. lblStageY.Text = "NaN";
  457. }
  458. else
  459. {
  460. lblStageY.Text = ret.ToString();
  461. }
  462. }
  463. private void btnStageGetZ_Click(object sender, EventArgs e)
  464. {
  465. float ret = sem.GetStageAtZ();
  466. if (float.IsNaN(ret))
  467. {
  468. lblStageZ.Text = "NaN";
  469. }
  470. else
  471. {
  472. lblStageZ.Text = ret.ToString();
  473. }
  474. }
  475. private void btnStageGetT_Click(object sender, EventArgs e)
  476. {
  477. float ret = sem.GetStageAtT();
  478. if (float.IsNaN(ret))
  479. {
  480. lblStageT.Text = "NaN";
  481. }
  482. else
  483. {
  484. lblStageT.Text = ret.ToString();
  485. }
  486. }
  487. private void btnStageGetR_Click(object sender, EventArgs e)
  488. {
  489. float ret = sem.GetStageAtR();
  490. if (float.IsNaN(ret))
  491. {
  492. lblStageR.Text = "NaN";
  493. }
  494. else
  495. {
  496. lblStageR.Text = ret.ToString();
  497. }
  498. }
  499. private void btnStageGetM_Click(object sender, EventArgs e)
  500. {
  501. float ret = sem.GetStageAtM();
  502. if (float.IsNaN(ret))
  503. {
  504. lblStageM.Text = "NaN";
  505. }
  506. else
  507. {
  508. lblStageM.Text = ret.ToString();
  509. }
  510. }
  511. #endregion
  512. #region 样品台位置设置
  513. private void btnStageSetX_Click(object sender, EventArgs e)
  514. {
  515. float set = 0;
  516. if (float.TryParse(txtStageX.Text, out set))
  517. {
  518. sem.SetStageGotoX(set);
  519. }
  520. }
  521. private void btnStageSetY_Click(object sender, EventArgs e)
  522. {
  523. float set = 0;
  524. if (float.TryParse(txtStageY.Text, out set))
  525. {
  526. sem.SetStageGotoY(set);
  527. }
  528. }
  529. private void btnStageSetZ_Click(object sender, EventArgs e)
  530. {
  531. float set = 0;
  532. if (float.TryParse(txtStageZ.Text, out set))
  533. {
  534. sem.SetStageGotoZ(set);
  535. }
  536. }
  537. private void btnStageSetT_Click(object sender, EventArgs e)
  538. {
  539. float set = 0;
  540. if (float.TryParse(txtStageT.Text, out set))
  541. {
  542. sem.SetStageGotoT(set);
  543. }
  544. }
  545. private void btnStageSetR_Click(object sender, EventArgs e)
  546. {
  547. float set = 0;
  548. if (float.TryParse(txtStageR.Text, out set))
  549. {
  550. sem.SetStageGotoR(set);
  551. }
  552. }
  553. private void btnStageSetM_Click(object sender, EventArgs e)
  554. {
  555. float set = 0;
  556. if (float.TryParse(txtStageM.Text, out set))
  557. {
  558. sem.SetStageGotoM(set);
  559. }
  560. }
  561. #endregion
  562. #region 获取样品台位置数组
  563. private void btnGetStagePosition_Click(object sender, EventArgs e)
  564. {
  565. float[] pt = sem.GetStagePosition();
  566. if (!float.IsNaN(pt[0]))
  567. {
  568. lblStageX.Text = pt[0].ToString();
  569. }
  570. if (!float.IsNaN(pt[1]))
  571. {
  572. lblStageY.Text = pt[1].ToString();
  573. }
  574. if (!float.IsNaN(pt[2]))
  575. {
  576. lblStageZ.Text = pt[2].ToString();
  577. }
  578. if (!float.IsNaN(pt[3]))
  579. {
  580. lblStageT.Text = pt[3].ToString();
  581. }
  582. if (!float.IsNaN(pt[4]))
  583. {
  584. lblStageR.Text = pt[4].ToString();
  585. }
  586. if (!float.IsNaN(pt[5]))
  587. {
  588. lblStageM.Text = pt[5].ToString();
  589. }
  590. }
  591. #endregion
  592. #region 获取光束BEAM坐标
  593. private void btnBeamShiftXGet_Click(object sender, EventArgs e)
  594. {
  595. float ret = sem.GetBeamShiftX();
  596. if (float.IsNaN(ret))
  597. {
  598. lblBeamShiftXGet.Text = "NaN";
  599. txtBeamShiftXSet.Enabled = false;
  600. btnBeamShiftXSet.Enabled = false;
  601. }
  602. else
  603. {
  604. lblBeamShiftXGet.Text = ret.ToString();
  605. txtBeamShiftXSet.Text = ret.ToString();
  606. btnBeamShiftXSet.Enabled = true;
  607. }
  608. }
  609. private void btnBeamShiftXSet_Click(object sender, EventArgs e)
  610. {
  611. float set = 0;
  612. if (float.TryParse(txtBeamShiftXSet.Text, out set))
  613. {
  614. sem.SetBeamShiftX(set);
  615. }
  616. }
  617. private void btnBeamShiftYGet_Click(object sender, EventArgs e)
  618. {
  619. float ret = sem.GetBeamShiftY();
  620. if (float.IsNaN(ret))
  621. {
  622. lblBeamShiftYGet.Text = "NaN";
  623. txtBeamShiftYSet.Enabled = false;
  624. btnBeamShiftYSet.Enabled = false;
  625. }
  626. else
  627. {
  628. lblBeamShiftYGet.Text = ret.ToString();
  629. txtBeamShiftYSet.Text = ret.ToString();
  630. btnBeamShiftYSet.Enabled = true;
  631. }
  632. }
  633. private void btnBeamShiftYSet_Click(object sender, EventArgs e)
  634. {
  635. float set = 0;
  636. if (float.TryParse(txtBeamShiftYSet.Text, out set))
  637. {
  638. sem.SetBeamShiftY(set);
  639. }
  640. }
  641. #endregion
  642. private void btnDoSemDriftCorrn_Click(object sender, EventArgs e)
  643. {
  644. //sem.CmdDoSemDriftCorrn();
  645. }
  646. }
  647. }