FormUnitControl.cs 20 KB

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