FormUnitControl.cs 19 KB

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