FormUnitControl.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  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.Configuration;
  16. using System.IO;
  17. using SmartSEMControl;
  18. using FileManager;
  19. using System.Xml;
  20. using MeasureData;
  21. using WebManager;
  22. namespace HOZProject
  23. {
  24. public partial class FormUnitControl : Form
  25. {
  26. #region 系统参数
  27. //全局只有一个fatorySEM
  28. static FactoryHardware factorySEM = FactoryHardware.Instance;
  29. ISEMControl iSEM = factorySEM.ISEM;
  30. public XmlManager xmg = new XmlManager();
  31. private String path = Directory.GetCurrentDirectory();
  32. private int st_flag = 0;
  33. WebResult wr = new WebResult("127.0.0.1", "18080","");
  34. String[] sT;
  35. String[] firms;
  36. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  37. #endregion
  38. #region 构造函数
  39. public FormUnitControl()
  40. {
  41. InitializeComponent();
  42. Control.CheckForIllegalCrossThreadCalls = false;
  43. if(iSEM.ConnectStatus())
  44. {
  45. float ret = iSEM.GetFIBIMAGING();
  46. if(ret==0)
  47. {
  48. btnSEM.BackColor = Color.Lime;
  49. }
  50. else if(ret==1)
  51. {
  52. btnFIB.BackColor = Color.Lime;
  53. panelFIB.Visible = true;
  54. }
  55. else if(ret==2)
  56. {
  57. btnMILL.BackColor = Color.Lime;
  58. }
  59. }
  60. //Calling Notification for updated status
  61. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  62. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  63. //加载参数
  64. }
  65. #endregion
  66. #region 缩放Get
  67. private void btnenlargeGet_Click(object sender, EventArgs e)
  68. {
  69. float ret = iSEM.GetMagnification();
  70. if (float.IsNaN(ret))
  71. {
  72. txtenlargeSet.Text = "NaN";
  73. txtenlargeSet.Enabled = false;
  74. btnenlargeSet.Enabled = false;
  75. }
  76. else
  77. {
  78. txtenlargeSet.Text = ret.ToString();
  79. btnenlargeSet.Enabled = true;
  80. }
  81. }
  82. #endregion
  83. #region 缩放Set
  84. private void btnenlargeSet_Click(object sender, EventArgs e)
  85. {
  86. float set = 0;
  87. if (float.TryParse(txtenlargeSet.Text, out set))
  88. {
  89. iSEM.SetMagnification(set);
  90. }
  91. }
  92. #endregion
  93. #region 焦距Get
  94. private void btnWDGet_Click(object sender, EventArgs e)
  95. {
  96. float ret = iSEM.GetWorkingDistance();
  97. if (float.IsNaN(ret))
  98. {
  99. txtWDSet.Text = "NaN";
  100. txtWDSet.Enabled = false;
  101. btnWDSet.Enabled = false;
  102. }
  103. else
  104. {
  105. txtWDSet.Text = ret.ToString();
  106. btnWDSet.Enabled = true;
  107. }
  108. }
  109. #endregion
  110. #region 焦距Set
  111. private void btnWDSet_Click(object sender, EventArgs e)
  112. {
  113. float set = 0;
  114. if (float.TryParse(txtWDSet.Text, out set))
  115. {
  116. iSEM.SetWorkingDistance(set);
  117. }
  118. }
  119. #endregion
  120. #region 亮度Get
  121. private void btnBrightnessGet_Click(object sender, EventArgs e)
  122. {
  123. float ret = iSEM.GetBrightness();
  124. if (float.IsNaN(ret))
  125. {
  126. txtBrightnessSet.Text = "NaN";
  127. txtBrightnessSet.Enabled = false;
  128. btnBrightnessSet.Enabled = false;
  129. }
  130. else
  131. {
  132. txtBrightnessSet.Text = ret.ToString();
  133. btnBrightnessSet.Enabled = true;
  134. }
  135. }
  136. #endregion
  137. #region 亮度Set
  138. private void btnBrightnessSet_Click(object sender, EventArgs e)
  139. {
  140. float set = 0;
  141. if (float.TryParse(txtBrightnessSet.Text, out set))
  142. {
  143. iSEM.SetBrightness(set);
  144. }
  145. }
  146. #endregion
  147. #region 对比度Get
  148. private void btnContrastGet_Click(object sender, EventArgs e)
  149. {
  150. float ret = iSEM.GetContrast();
  151. if (float.IsNaN(ret))
  152. {
  153. txtContrastSet.Text = "NaN";
  154. txtContrastSet.Enabled = false;
  155. btnContrastSet.Enabled = false;
  156. }
  157. else
  158. {
  159. txtContrastSet.Text = ret.ToString();
  160. btnContrastSet.Enabled = true;
  161. }
  162. }
  163. #endregion
  164. #region 对比度Set
  165. private void btnContrastSet_Click(object sender, EventArgs e)
  166. {
  167. float set = 0;
  168. if (float.TryParse(txtContrastSet.Text, out set))
  169. {
  170. iSEM.SetContrast(set);
  171. }
  172. }
  173. #endregion
  174. #region 消像散X Get
  175. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  176. {
  177. float ret = iSEM.GetAstigmatismX();
  178. if (float.IsNaN(ret))
  179. {
  180. txtAstigmatismXSet.Text = "NaN";
  181. txtAstigmatismXSet.Enabled = false;
  182. btnAstigmatismXSet.Enabled = false;
  183. }
  184. else
  185. {
  186. txtAstigmatismXSet.Text = ret.ToString();
  187. btnAstigmatismXSet.Enabled = true;
  188. }
  189. }
  190. #endregion
  191. #region 消像散X Set
  192. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  193. {
  194. float set = 0;
  195. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  196. {
  197. iSEM.SetAstigmatismX(set);
  198. }
  199. }
  200. #endregion
  201. #region 消像散Y Get
  202. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  203. {
  204. float ret = iSEM.GetAstigmatismY();
  205. if (float.IsNaN(ret))
  206. {
  207. txtAstigmatismYSet.Text = "NaN";
  208. txtAstigmatismYSet.Enabled = false;
  209. btnAstigmatismYSet.Enabled = false;
  210. }
  211. else
  212. {
  213. txtAstigmatismYSet.Text = ret.ToString();
  214. btnAstigmatismYSet.Enabled = true;
  215. }
  216. }
  217. #endregion
  218. #region 消像散Y Set
  219. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  220. {
  221. float set = 0;
  222. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  223. {
  224. iSEM.SetAstigmatismY(set);
  225. }
  226. }
  227. #endregion
  228. #region 角度补偿Get
  229. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  230. {
  231. float ret = iSEM.GetTiltAngle();
  232. if (float.IsNaN(ret))
  233. {
  234. txtTiltAngleSet.Text = "NaN";
  235. txtTiltAngleSet.Enabled = false;
  236. btnTiltAngleSet.Enabled = false;
  237. }
  238. else
  239. {
  240. txtTiltAngleSet.Text = ret.ToString();
  241. btnTiltAngleSet.Enabled = true;
  242. }
  243. }
  244. #endregion
  245. #region 角度补偿Set
  246. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  247. {
  248. float set = 0;
  249. if (float.TryParse(txtTiltAngleSet.Text, out set))
  250. {
  251. //iSEM.SetTiltAngleOn();
  252. iSEM.SetTiltAngle(set);
  253. }
  254. }
  255. #endregion
  256. #region 抓取图像
  257. private void btnGrabImage_Click(object sender, EventArgs e)
  258. {
  259. SaveFileDialog sfd = new SaveFileDialog();
  260. sfd.Title = "图像保存位置:";
  261. sfd.FileName = "test.tif";
  262. sfd.Filter = "TIF文件|*.tif";
  263. if (sfd.ShowDialog() == DialogResult.OK)
  264. {
  265. string fn = sfd.FileName;
  266. iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
  267. }
  268. }
  269. #endregion
  270. #region ScanRotate Get
  271. private void btnScanRotationGet_Click(object sender, EventArgs e)
  272. {
  273. float ret = iSEM.GetScanRotation();
  274. if (float.IsNaN(ret))
  275. {
  276. txtScanRotationSet.Text = "NaN";
  277. txtScanRotationSet.Enabled = false;
  278. btnScanRotationSet.Enabled = false;
  279. }
  280. else
  281. {
  282. txtScanRotationSet.Text = ret.ToString();
  283. btnScanRotationSet.Enabled = true;
  284. }
  285. }
  286. #endregion
  287. #region ScanRotate Set
  288. private void btnScanRotationSet_Click(object sender, EventArgs e)
  289. {
  290. float set = 0;
  291. if (float.TryParse(txtScanRotationSet.Text, out set))
  292. {
  293. //iSEM.SetScanRotationOn();
  294. iSEM.SetScanRotation(set);
  295. }
  296. }
  297. #endregion
  298. #region PixelSize Get
  299. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  300. {
  301. float ret = iSEM.GetPixelSize();
  302. if (float.IsNaN(ret))
  303. {
  304. lblPixelSizeGet.Text = "NaN";
  305. }
  306. else
  307. {
  308. lblPixelSizeGet.Text = ret.ToString();
  309. }
  310. }
  311. #endregion
  312. #region 电子束
  313. private void btnTiltCorrXGet_Click(object sender, EventArgs e)
  314. {
  315. float ret = iSEM.GetBeamShiftX();
  316. if (float.IsNaN(ret))
  317. {
  318. txtTiltCorrX.Text = "NaN";
  319. txtTiltCorrX.Enabled = false;
  320. btnTiltCorrXSet.Enabled = false;
  321. }
  322. else
  323. {
  324. txtTiltCorrX.Text = ret.ToString();
  325. btnTiltCorrXSet.Enabled = true;
  326. }
  327. }
  328. private void btnTiltCorrXSet_Click(object sender, EventArgs e)
  329. {
  330. float set = 0;
  331. if (float.TryParse(txtTiltCorrX.Text, out set))
  332. {
  333. iSEM.SetBeamShiftX(set);
  334. }
  335. }
  336. private void btnTiltCorrYGet_Click(object sender, EventArgs e)
  337. {
  338. float ret = iSEM.GetBeamShiftY();
  339. if (float.IsNaN(ret))
  340. {
  341. txtTiltCorrY.Text = "NaN";
  342. txtTiltCorrY.Enabled = false;
  343. btnTiltCorrYSet.Enabled = false;
  344. }
  345. else
  346. {
  347. txtTiltCorrY.Text = ret.ToString();
  348. btnTiltCorrYSet.Enabled = true;
  349. }
  350. }
  351. private void btnTiltCorrYSet_Click(object sender, EventArgs e)
  352. {
  353. float set = 0;
  354. if (float.TryParse(txtTiltCorrY.Text, out set))
  355. {
  356. iSEM.SetBeamShiftY(set);
  357. }
  358. }
  359. #endregion
  360. #region 开启电压
  361. private void btnOpenVoltage_Click(object sender, EventArgs e)
  362. {
  363. iSEM.CmdOpenVoltage();
  364. }
  365. #endregion
  366. #region 关闭电压
  367. private void btnCloseVoltage_Click(object sender, EventArgs e)
  368. {
  369. iSEM.CmdCloseVoltage();
  370. }
  371. #endregion
  372. #region 电子束校正
  373. private void btnTiltCorr_Click(object sender, EventArgs e)
  374. {
  375. float ret = iSEM.GetTiltCorrection();
  376. if (float.IsNaN(ret))
  377. {
  378. btnTiltCorr.BackColor = Color.Red;
  379. }
  380. else
  381. {
  382. if(ret==0)
  383. {
  384. btnTiltCorr.BackColor = Color.Blue;
  385. iSEM.SetTiltCorrectionOn();
  386. btnTiltCorr.Text = "电子束状态:On";
  387. }
  388. else
  389. {
  390. btnTiltCorr.BackColor = Color.Lime;
  391. iSEM.SetTiltCorrectionOff();
  392. btnTiltCorr.Text = "电子束状态:Off";
  393. }
  394. }
  395. }
  396. #endregion
  397. #region 样品台位置获取
  398. private void btnStageGetX_Click(object sender, EventArgs e)
  399. {
  400. float ret = iSEM.GetStageAtX();
  401. if (float.IsNaN(ret))
  402. {
  403. lblStageX.Text = "NaN";
  404. }
  405. else
  406. {
  407. lblStageX.Text = ret.ToString();
  408. }
  409. }
  410. private void btnStageGetY_Click(object sender, EventArgs e)
  411. {
  412. float ret = iSEM.GetStageAtY();
  413. if (float.IsNaN(ret))
  414. {
  415. lblStageY.Text = "NaN";
  416. }
  417. else
  418. {
  419. lblStageY.Text = ret.ToString();
  420. }
  421. }
  422. private void btnStageGetZ_Click(object sender, EventArgs e)
  423. {
  424. float ret = iSEM.GetStageAtZ();
  425. if (float.IsNaN(ret))
  426. {
  427. lblStageZ.Text = "NaN";
  428. }
  429. else
  430. {
  431. lblStageZ.Text = ret.ToString();
  432. }
  433. }
  434. private void btnStageGetT_Click(object sender, EventArgs e)
  435. {
  436. float ret = iSEM.GetStageAtT();
  437. if (float.IsNaN(ret))
  438. {
  439. lblStageT.Text = "NaN";
  440. }
  441. else
  442. {
  443. lblStageT.Text = ret.ToString();
  444. }
  445. }
  446. private void btnStageGetR_Click(object sender, EventArgs e)
  447. {
  448. float ret = iSEM.GetStageAtR();
  449. if (float.IsNaN(ret))
  450. {
  451. lblStageR.Text = "NaN";
  452. }
  453. else
  454. {
  455. lblStageR.Text = ret.ToString();
  456. }
  457. }
  458. private void btnStageGetM_Click(object sender, EventArgs e)
  459. {
  460. float ret = iSEM.GetStageAtM();
  461. if (float.IsNaN(ret))
  462. {
  463. lblStageM.Text = "NaN";
  464. }
  465. else
  466. {
  467. lblStageM.Text = ret.ToString();
  468. }
  469. }
  470. #endregion
  471. #region 样品台位置设置
  472. private void btnStageSetX_Click(object sender, EventArgs e)
  473. {
  474. float set = 0;
  475. if (float.TryParse(txtStageX.Text, out set))
  476. {
  477. iSEM.SetStageGotoX(set);
  478. }
  479. }
  480. private void btnStageSetY_Click(object sender, EventArgs e)
  481. {
  482. float set = 0;
  483. if (float.TryParse(txtStageY.Text, out set))
  484. {
  485. iSEM.SetStageGotoY(set);
  486. }
  487. }
  488. private void btnStageSetZ_Click(object sender, EventArgs e)
  489. {
  490. float set = 0;
  491. if (float.TryParse(txtStageZ.Text, out set))
  492. {
  493. iSEM.SetStageGotoZ(set);
  494. }
  495. }
  496. private void btnStageSetT_Click(object sender, EventArgs e)
  497. {
  498. float set = 0;
  499. if (float.TryParse(txtStageT.Text, out set))
  500. {
  501. iSEM.SetStageGotoT(set);
  502. }
  503. }
  504. private void btnStageSetR_Click(object sender, EventArgs e)
  505. {
  506. float set = 0;
  507. if (float.TryParse(txtStageR.Text, out set))
  508. {
  509. iSEM.SetStageGotoR(set);
  510. }
  511. }
  512. private void btnStageSetM_Click(object sender, EventArgs e)
  513. {
  514. float set = 0;
  515. if (float.TryParse(txtStageM.Text, out set))
  516. {
  517. iSEM.SetStageGotoM(set);
  518. }
  519. }
  520. #endregion
  521. #region 获取样品台位置数组
  522. private void btnGetStagePosition_Click(object sender, EventArgs e)
  523. {
  524. float[] pt = iSEM.GetStagePosition();
  525. if (!float.IsNaN(pt[0]))
  526. {
  527. lblStageX.Text = pt[0].ToString();
  528. }
  529. if (!float.IsNaN(pt[1]))
  530. {
  531. lblStageY.Text = pt[1].ToString();
  532. }
  533. if (!float.IsNaN(pt[2]))
  534. {
  535. lblStageZ.Text = pt[2].ToString();
  536. }
  537. if (!float.IsNaN(pt[3]))
  538. {
  539. lblStageT.Text = pt[3].ToString();
  540. }
  541. if (!float.IsNaN(pt[4]))
  542. {
  543. lblStageR.Text = pt[4].ToString();
  544. }
  545. if (!float.IsNaN(pt[5]))
  546. {
  547. lblStageM.Text = pt[5].ToString();
  548. }
  549. }
  550. #endregion
  551. #region 窗体关闭
  552. private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
  553. {
  554. if(iSEM!=null)
  555. {
  556. iSEM.Dispose();
  557. }
  558. }
  559. #endregion
  560. #region 宏文件
  561. private void btnCMDMCF_Click(object sender, EventArgs e)
  562. {
  563. iSEM.CMDMCFFilename("OPTON");
  564. }
  565. #endregion
  566. #region 读取Xml文件
  567. private void btnReadXml_Click(object sender, EventArgs e)
  568. {
  569. MeasureFile mf = new MeasureFile();
  570. XmlDocument doc = new XmlDocument();
  571. doc.Load("test_opton.msf");//载入xml文件
  572. XmlNode root = doc.SelectSingleNode("XMLData");
  573. mf.Serialize(false, doc, root);
  574. doc.Save("test_opton.msf");
  575. }
  576. #endregion
  577. #region 写入Xml文件
  578. private void btnWriteXml_Click(object sender, EventArgs e)
  579. {
  580. MeasureFile mf = new MeasureFile();
  581. mf.FileName = path + "\\test_opton.msf";
  582. mf.FilePath = path;
  583. CutHole ch = new CutHole();
  584. ch.OPT = Operation.Image;
  585. ch.START = System.DateTime.Now;
  586. ch.END = System.DateTime.Now.AddHours(2);
  587. ch.STATE = State.Success;
  588. ch.SWITCH = true;
  589. SemPosition sp = new SemPosition();
  590. sp.X = 11;
  591. sp.Y = 22;
  592. sp.Z = 33;
  593. sp.T = 44;
  594. sp.R = 55;
  595. sp.M = 66;
  596. ch.Position = sp;
  597. mf.ListCutHole.Add(ch);
  598. ch = new CutHole();
  599. ch.OPT = Operation.Image;
  600. ch.START = System.DateTime.Now;
  601. ch.END = System.DateTime.Now.AddHours(2);
  602. ch.STATE = State.Success;
  603. ch.SWITCH = true;
  604. sp = new SemPosition();
  605. sp.X = 12;
  606. sp.Y = 34;
  607. sp.Z = 56;
  608. sp.T = 78;
  609. sp.R = 90;
  610. sp.M = 55;
  611. ch.Position = sp;
  612. mf.ListCutHole.Add(ch);
  613. MeasureParam md = new MeasureParam();
  614. md.SampleName = "aaaaaa";
  615. md.PT = true;
  616. md.PTTemp = "bbbbb";
  617. md.FIBTemp = "cccc";
  618. md.FocusMode = 2;
  619. mf.MParam = md;
  620. mf.New();
  621. //XmlDocument doc = new XmlDocument();
  622. //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
  623. //XmlNode root = doc.SelectSingleNode("XMLData");
  624. //mf.Serialize(true, doc, root);
  625. //doc.Save("test.aaa");
  626. }
  627. #endregion
  628. #region SEM模式
  629. private void btnSEM_Click(object sender, EventArgs e)
  630. {
  631. if(iSEM.CmdFIBModeSEM())
  632. {
  633. btnFIB.BackColor = SystemColors.Control;
  634. btnSEM.BackColor = Color.Lime;
  635. btnMILL.BackColor = SystemColors.Control;
  636. panelFIB.Visible = false;
  637. }
  638. }
  639. #endregion
  640. #region FIB模式
  641. private void btnFIB_Click(object sender, EventArgs e)
  642. {
  643. if(iSEM.CmdFIBModeFIB())
  644. {
  645. btnFIB.BackColor = Color.Lime;
  646. btnSEM.BackColor = SystemColors.Control;
  647. btnMILL.BackColor = SystemColors.Control;
  648. panelFIB.Visible = true;
  649. }
  650. }
  651. #endregion
  652. #region MILL模式
  653. private void btnMILL_Click(object sender, EventArgs e)
  654. {
  655. if(iSEM.CmdFIBModeMILL())
  656. {
  657. btnFIB.BackColor = SystemColors.Control;
  658. btnSEM.BackColor = SystemColors.Control;
  659. btnMILL.BackColor = Color.Lime;
  660. }
  661. }
  662. #endregion
  663. #region 自动对焦1
  664. private void btnAutoFocus1_Click(object sender, EventArgs e)
  665. {
  666. //抓图1
  667. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  668. if (File.Exists(path + "\\test1.tif"))
  669. {
  670. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  671. pictureBox1.Image = Image.FromStream(fileStream);
  672. fileStream.Close();
  673. fileStream.Dispose();
  674. }
  675. Thread.Sleep(1000);
  676. iSEM.CmdAutoFocusCoarse();
  677. btnAutoFocus1.BackColor = Color.Red;
  678. st_flag = 1;
  679. Thread.Sleep(1000);
  680. Thread thread = new Thread(AutoFunction);
  681. thread.Start();
  682. }
  683. #endregion
  684. #region 自动函数监测线程
  685. private void AutoFunction()
  686. {
  687. float ret = 111;
  688. Boolean state = false;
  689. while(true)
  690. {
  691. Thread.Sleep(1000);
  692. ret = iSEM.GetAutoFunction();
  693. if(ret==0)
  694. {
  695. if (st_flag == 1 && state == true)
  696. {
  697. btnAutoFocus1.BackColor = Color.Lime;
  698. Thread.Sleep(1000);
  699. //抓图1
  700. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  701. if (File.Exists(path + "\\test2.tif"))
  702. {
  703. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  704. pictureBox2.Image = Image.FromStream(fileStream);
  705. fileStream.Close();
  706. fileStream.Dispose();
  707. }
  708. break;
  709. }
  710. else if(st_flag==2 && state)
  711. {
  712. btnAutoFocus2.BackColor = Color.Lime;
  713. Thread.Sleep(1000);
  714. //抓图1
  715. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  716. if (File.Exists(path + "\\test2.tif"))
  717. {
  718. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  719. pictureBox2.Image = Image.FromStream(fileStream);
  720. fileStream.Close();
  721. fileStream.Dispose();
  722. }
  723. break;
  724. }
  725. else if (st_flag == 3)
  726. {
  727. btnAutoBrightness.BackColor = Color.Lime;
  728. Thread.Sleep(1000);
  729. //抓图1
  730. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  731. if (File.Exists(path + "\\test2.tif"))
  732. {
  733. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  734. pictureBox2.Image = Image.FromStream(fileStream);
  735. fileStream.Close();
  736. fileStream.Dispose();
  737. }
  738. break;
  739. }
  740. else if (st_flag == 4)
  741. {
  742. btnAutoContrast.BackColor = Color.Lime;
  743. Thread.Sleep(1000);
  744. //抓图1
  745. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  746. if (File.Exists(path + "\\test2.tif"))
  747. {
  748. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  749. pictureBox2.Image = Image.FromStream(fileStream);
  750. fileStream.Close();
  751. fileStream.Dispose();
  752. }
  753. break;
  754. }
  755. else if (st_flag == 5)
  756. {
  757. btnAutoBrightness.BackColor = Color.Lime;
  758. btnAutoContrast.BackColor = Color.Lime;
  759. btnAutoBC.BackColor = Color.Lime;
  760. Thread.Sleep(1000);
  761. //抓图1
  762. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  763. if (File.Exists(path + "\\test2.tif"))
  764. {
  765. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  766. pictureBox2.Image = Image.FromStream(fileStream);
  767. fileStream.Close();
  768. fileStream.Dispose();
  769. }
  770. break;
  771. }
  772. else if (st_flag == 6 && state)
  773. {
  774. btnAutoBCCancle.BackColor = Color.Lime;
  775. Thread.Sleep(1000);
  776. //抓图1
  777. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  778. if (File.Exists(path + "\\test2.tif"))
  779. {
  780. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  781. pictureBox2.Image = Image.FromStream(fileStream);
  782. fileStream.Close();
  783. fileStream.Dispose();
  784. }
  785. break;
  786. }
  787. else if (st_flag == 7 && state)
  788. {
  789. btnAutoStig.BackColor = Color.Lime;
  790. Thread.Sleep(1000);
  791. //抓图1
  792. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  793. if (File.Exists(path + "\\test2.tif"))
  794. {
  795. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  796. pictureBox2.Image = Image.FromStream(fileStream);
  797. fileStream.Close();
  798. fileStream.Dispose();
  799. }
  800. break;
  801. }
  802. ////抓图1
  803. //iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  804. //if (File.Exists(path + "\\test2.tif"))
  805. //{
  806. // FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  807. // pictureBox2.Image = Image.FromStream(fileStream);
  808. // fileStream.Close();
  809. // fileStream.Dispose();
  810. //}
  811. }
  812. else if(ret>0 && ret<12)
  813. {
  814. state = true;
  815. }
  816. }
  817. }
  818. #endregion
  819. #region 自动对焦2
  820. private void btnAutoFocus2_Click(object sender, EventArgs e)
  821. {
  822. //抓图1
  823. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  824. if (File.Exists(path + "\\test1.tif"))
  825. {
  826. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  827. pictureBox1.Image = Image.FromStream(fileStream);
  828. fileStream.Close();
  829. fileStream.Dispose();
  830. }
  831. Thread.Sleep(1000);
  832. iSEM.CmdAutoFocusFine();
  833. btnAutoFocus2.BackColor = Color.Red;
  834. st_flag = 2;
  835. Thread.Sleep(1000);
  836. Thread thread = new Thread(AutoFunction);
  837. thread.Start();
  838. }
  839. #endregion
  840. #region 自动亮度、对比度
  841. private void btnAutoBrightness_Click(object sender, EventArgs e)
  842. {
  843. //抓图1
  844. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  845. if (File.Exists(path + "\\test1.tif"))
  846. {
  847. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  848. pictureBox1.Image = Image.FromStream(fileStream);
  849. fileStream.Close();
  850. fileStream.Dispose();
  851. }
  852. Thread.Sleep(1000);
  853. iSEM.SetAutoVideoBrightness();
  854. btnAutoBrightness.BackColor = Color.Red;
  855. st_flag = 3;
  856. Thread.Sleep(1000);
  857. Thread thread = new Thread(AutoFunction);
  858. thread.Start();
  859. }
  860. private void btnAutoContrast_Click(object sender, EventArgs e)
  861. {
  862. //抓图1
  863. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  864. if (File.Exists(path + "\\test1.tif"))
  865. {
  866. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  867. pictureBox1.Image = Image.FromStream(fileStream);
  868. fileStream.Close();
  869. fileStream.Dispose();
  870. }
  871. Thread.Sleep(1000);
  872. iSEM.SetAutoVideoContrast();
  873. btnAutoContrast.BackColor = Color.Red;
  874. st_flag = 4;
  875. Thread.Sleep(1000);
  876. Thread thread = new Thread(AutoFunction);
  877. thread.Start();
  878. }
  879. private void btnAutoBC_Click(object sender, EventArgs e)
  880. {
  881. //抓图1
  882. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  883. if (File.Exists(path + "\\test1.tif"))
  884. {
  885. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  886. pictureBox1.Image = Image.FromStream(fileStream);
  887. fileStream.Close();
  888. fileStream.Dispose();
  889. }
  890. Thread.Sleep(1000);
  891. iSEM.SetAutoVideoBrightnessAndContrast();
  892. btnAutoBrightness.BackColor = Color.Red;
  893. btnAutoContrast.BackColor = Color.Red;
  894. btnAutoBC.BackColor = Color.Red;
  895. st_flag = 5;
  896. Thread.Sleep(1000);
  897. Thread thread = new Thread(AutoFunction);
  898. thread.Start();
  899. }
  900. private void btnAutoBCCancle_Click(object sender, EventArgs e)
  901. {
  902. iSEM.SetAutoVideoOff();
  903. btnAutoBCCancle.BackColor = Color.Red;
  904. st_flag = 6;
  905. Thread.Sleep(1000);
  906. Thread thread = new Thread(AutoFunction);
  907. thread.Start();
  908. }
  909. #endregion
  910. #region 自动消像散
  911. private void btnAutoStig_Click(object sender, EventArgs e)
  912. {
  913. //抓图1
  914. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  915. if (File.Exists(path + "\\test1.tif"))
  916. {
  917. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  918. pictureBox1.Image = Image.FromStream(fileStream);
  919. fileStream.Close();
  920. fileStream.Dispose();
  921. }
  922. Thread.Sleep(1000);
  923. iSEM.CmdAutoStig();
  924. btnAutoStig.BackColor = Color.Red;
  925. st_flag = 7;
  926. Thread.Sleep(1000);
  927. Thread thread = new Thread(AutoFunction);
  928. thread.Start();
  929. }
  930. #endregion
  931. #region FIB缩放Get
  932. private void btnFIBMagGet_Click(object sender, EventArgs e)
  933. {
  934. float ret = iSEM.GetFIBMagnification();
  935. if (float.IsNaN(ret))
  936. {
  937. txtFIBMag.Text = "NaN";
  938. txtFIBMag.Enabled = false;
  939. btnFIBMagSet.Enabled = false;
  940. }
  941. else
  942. {
  943. txtFIBMag.Text = ret.ToString();
  944. btnFIBMagSet.Enabled = true;
  945. }
  946. }
  947. #endregion
  948. #region FIB缩放Set
  949. private void btnFIBMagSet_Click(object sender, EventArgs e)
  950. {
  951. float set = 0;
  952. if (float.TryParse(txtFIBMag.Text, out set))
  953. {
  954. iSEM.SetFIBMagnification(set);
  955. }
  956. }
  957. #endregion
  958. #region FIB焦距Get
  959. private void btnFIBWDGet_Click(object sender, EventArgs e)
  960. {
  961. float ret = iSEM.GetFIBObjectivePotential();
  962. if (float.IsNaN(ret))
  963. {
  964. txtFIBWD.Text = "NaN";
  965. txtFIBWD.Enabled = false;
  966. btnFIBWDSet.Enabled = false;
  967. }
  968. else
  969. {
  970. txtFIBWD.Text = ret.ToString();
  971. btnFIBWDSet.Enabled = true;
  972. }
  973. }
  974. #endregion
  975. #region FIB焦距Set
  976. private void btnFIBWDSet_Click(object sender, EventArgs e)
  977. {
  978. float set = 0;
  979. if (float.TryParse(txtFIBWD.Text, out set))
  980. {
  981. iSEM.SetFIBObjectivePotential(set);
  982. }
  983. }
  984. #endregion
  985. #region FIB电子束移动
  986. private void btnFIBBeamShiftXGet_Click(object sender, EventArgs e)
  987. {
  988. float ret = iSEM.GetFIBBeamShiftX();
  989. if (float.IsNaN(ret))
  990. {
  991. txtFIBBeamShiftX.Text = "NaN";
  992. txtFIBBeamShiftX.Enabled = false;
  993. btnFIBBeamShiftXSet.Enabled = false;
  994. }
  995. else
  996. {
  997. txtFIBBeamShiftX.Text = ret.ToString();
  998. btnFIBBeamShiftXSet.Enabled = true;
  999. }
  1000. }
  1001. private void btnFIBBeamShiftXSet_Click(object sender, EventArgs e)
  1002. {
  1003. float set = 0;
  1004. if (float.TryParse(txtFIBBeamShiftX.Text, out set))
  1005. {
  1006. iSEM.SetFIBBeamShiftX(set);
  1007. }
  1008. }
  1009. private void btnFIBBeamShiftYGet_Click(object sender, EventArgs e)
  1010. {
  1011. float ret = iSEM.GetFIBBeamShiftY();
  1012. if (float.IsNaN(ret))
  1013. {
  1014. txtFIBBeamShiftY.Text = "NaN";
  1015. txtFIBBeamShiftY.Enabled = false;
  1016. btnFIBBeamShiftYSet.Enabled = false;
  1017. }
  1018. else
  1019. {
  1020. txtFIBBeamShiftY.Text = ret.ToString();
  1021. btnFIBBeamShiftYSet.Enabled = true;
  1022. }
  1023. }
  1024. private void btnFIBBeamShiftYSet_Click(object sender, EventArgs e)
  1025. {
  1026. float set = 0;
  1027. if (float.TryParse(txtFIBBeamShiftY.Text, out set))
  1028. {
  1029. iSEM.SetFIBBeamShiftY(set);
  1030. }
  1031. }
  1032. #endregion
  1033. #region 执行宏文件
  1034. private void btnMCF_Click(object sender, EventArgs e)
  1035. {
  1036. OpenFileDialog sfd = new OpenFileDialog();
  1037. sfd.Title = "选择宏文件:";
  1038. sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1039. sfd.Filter = "MLF文件|*.MLF";
  1040. if (sfd.ShowDialog() == DialogResult.OK)
  1041. {
  1042. //string fn = Path.GetFileNameWithoutExtension(sfd.FileName).ToUpper();
  1043. iSEM.CMDMCFFilename(sfd.FileName);
  1044. }
  1045. }
  1046. #endregion
  1047. #region FIB消像散
  1048. private void btnFIBAstigmatismXGet_Click(object sender, EventArgs e)
  1049. {
  1050. float ret = iSEM.GetFIBAstigmatismX();
  1051. if (float.IsNaN(ret))
  1052. {
  1053. txtFIBAstigmatismX.Text = "NaN";
  1054. txtFIBAstigmatismX.Enabled = false;
  1055. btnFIBAstigmatismXSet.Enabled = false;
  1056. }
  1057. else
  1058. {
  1059. txtFIBAstigmatismX.Text = ret.ToString();
  1060. btnFIBAstigmatismXSet.Enabled = true;
  1061. }
  1062. }
  1063. private void btnFIBAstigmatismXSet_Click(object sender, EventArgs e)
  1064. {
  1065. float set = 0;
  1066. if (float.TryParse(txtFIBAstigmatismX.Text, out set))
  1067. {
  1068. iSEM.SetFIBAstigmatismX(set);
  1069. }
  1070. }
  1071. private void btnFIBAstigmatismYGet_Click(object sender, EventArgs e)
  1072. {
  1073. float ret = iSEM.GetFIBAstigmatismY();
  1074. if (float.IsNaN(ret))
  1075. {
  1076. txtFIBAstigmatismY.Text = "NaN";
  1077. txtFIBAstigmatismY.Enabled = false;
  1078. btnFIBAstigmatismYSet.Enabled = false;
  1079. }
  1080. else
  1081. {
  1082. txtFIBAstigmatismY.Text = ret.ToString();
  1083. btnFIBAstigmatismYSet.Enabled = true;
  1084. }
  1085. }
  1086. private void btnFIBAstigmatismYSet_Click(object sender, EventArgs e)
  1087. {
  1088. float set = 0;
  1089. if (float.TryParse(txtFIBAstigmatismY.Text, out set))
  1090. {
  1091. iSEM.SetFIBAstigmatismY(set);
  1092. }
  1093. }
  1094. #endregion
  1095. #region 移动样品台XY
  1096. private void btnMoveXY_Click(object sender, EventArgs e)
  1097. {
  1098. float setx = 0;
  1099. float sety = 0;
  1100. if (!float.TryParse(txtStageX.Text, out setx))
  1101. {
  1102. return;
  1103. }
  1104. if(!float.TryParse(txtStageY.Text,out sety))
  1105. {
  1106. return;
  1107. }
  1108. btnMoveXY.BackColor = Color.Red;
  1109. iSEM.MoveStageXY(setx, sety);
  1110. Thread.Sleep(500);
  1111. Thread th = new Thread(MoveStagexy);
  1112. th.Start();
  1113. }
  1114. private void MoveStagexy()
  1115. {
  1116. float ret = 111;
  1117. while(true)
  1118. {
  1119. ret = iSEM.GetStageIs();
  1120. if(ret==0)
  1121. {
  1122. btnMoveXY.BackColor = Color.Lime;
  1123. break;
  1124. }
  1125. }
  1126. }
  1127. #endregion
  1128. #region 获取分辨率
  1129. private void btnImageStoreGet_Click(object sender, EventArgs e)
  1130. {
  1131. int[] ret = iSEM.GetImageStore();
  1132. lblImageStore.Text = ret[0].ToString() + "*" + ret[1].ToString();
  1133. }
  1134. #endregion
  1135. #region 设置分辨率
  1136. private void btnImageStoreSet_Click(object sender, EventArgs e)
  1137. {
  1138. if (cmbImageStore.SelectedIndex > -1 && cmbImageStore.SelectedIndex < 12)
  1139. {
  1140. iSEM.SetImageStore(cmbImageStore.SelectedIndex);
  1141. }
  1142. }
  1143. #endregion
  1144. #region 样品台急停
  1145. private void btnAbort_Click(object sender, EventArgs e)
  1146. {
  1147. iSEM.CmdStageAbort();
  1148. }
  1149. #endregion
  1150. private void btnLive_Click(object sender, EventArgs e)
  1151. {
  1152. iSEM.ImageLive();
  1153. }
  1154. private void btnFrozen_Click(object sender, EventArgs e)
  1155. {
  1156. iSEM.ImageFrozen();
  1157. }
  1158. private void btnExeEly_Click(object sender, EventArgs e)
  1159. {
  1160. OpenFileDialog sfd = new OpenFileDialog();
  1161. sfd.Title = "选择ELY文件:";
  1162. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1163. sfd.Filter = "ELY文件|*.ELY";
  1164. if (sfd.ShowDialog() == DialogResult.OK)
  1165. {
  1166. iSEM.CmdFIBLoadELY(sfd.FileName);
  1167. }
  1168. }
  1169. private void btnExeEly2_Click(object sender, EventArgs e)
  1170. {
  1171. iSEM.CmdFIBEXPOSUREELY();
  1172. }
  1173. private void btnFIBStatus_Click(object sender, EventArgs e)
  1174. {
  1175. btnFIBStatus.Text = iSEM.GetFIBMode().ToString();
  1176. }
  1177. private void btnPost1_Click(object sender, EventArgs e)
  1178. {
  1179. double degree = 0;
  1180. int direction = 0;
  1181. int state = 0;
  1182. wr.Img_OffsetAngle_Direction("D:/aaaa.jpg",1,"LG", out degree, out direction, out state);
  1183. lbldegree1.Text = degree.ToString("0.0");
  1184. lbldirection1.Text = direction.ToString();
  1185. lblstate1.Text = state.ToString();
  1186. }
  1187. private void btnPost2_Click(object sender, EventArgs e)
  1188. {
  1189. double offsetx = 0;
  1190. double offsety = 0;
  1191. int state = 0;
  1192. //wr.Img_Cut_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
  1193. lbllocationx.Text = offsetx.ToString("0.0");
  1194. lbllocationy.Text = offsety.ToString("0.0");
  1195. lblstate2.Text = state.ToString();
  1196. }
  1197. private void btnPost3_Click(object sender, EventArgs e)
  1198. {
  1199. int state = 0;
  1200. wr.Img_Cut_Success("D:/aaaa.jpg", "D:/bbbb.jpg", out state);
  1201. lblstate3.Text = state.ToString();
  1202. }
  1203. private void btnPost4_Click(object sender, EventArgs e)
  1204. {
  1205. double offsetx = 0;
  1206. double offsety = 0;
  1207. int state = 0;
  1208. wr.Img_Trapezoid_Top_Center_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
  1209. lbltopcx.Text = offsetx.ToString("0.0");
  1210. lbltopcy.Text = offsety.ToString("0.0");
  1211. lblstate4.Text = state.ToString();
  1212. }
  1213. private void btnPost5_Click(object sender, EventArgs e)
  1214. {
  1215. List<string> filenames = new List<string>();
  1216. filenames.Add("1111111");
  1217. filenames.Add("2222222");
  1218. filenames.Add("3333333");
  1219. lblfocuspath.Text = wr.Img_Auto_Focus(filenames);
  1220. }
  1221. private void btnPost6_Click(object sender, EventArgs e)
  1222. {
  1223. List<string> filenames = new List<string>();
  1224. filenames.Add("1111111");
  1225. filenames.Add("2222222");
  1226. filenames.Add("3333333");
  1227. lblstigpath.Text = wr.Img_Auto_Focus(filenames);
  1228. }
  1229. private void btnPost7_Click(object sender, EventArgs e)
  1230. {
  1231. double offsetx = 0;
  1232. double offsety = 0;
  1233. double degree = 0;
  1234. int direction = 0;
  1235. int state = 0;
  1236. //wr.Img_Center_Position_OffsetAngle_Direction("D:/aaaa.jpg", out offsetx, out offsety, out degree, out direction, out state);
  1237. lblcenterx.Text = offsetx.ToString("0.0");
  1238. lblcentery.Text = offsety.ToString("0.0");
  1239. lbldegree2.Text = degree.ToString();
  1240. lbldirection2.Text = direction.ToString();
  1241. lblstate5.Text = state.ToString();
  1242. }
  1243. private void btnPost8_Click(object sender, EventArgs e)
  1244. {
  1245. int state = 0;
  1246. wr.Img_Measure_Size("D:/aaaa.jpg", "1000", "0.005", out state);
  1247. lblstate6.Text = state.ToString();
  1248. }
  1249. private void btnScanRotationSetLock_Click(object sender, EventArgs e)
  1250. {
  1251. iSEM.SetScanRotationOff();
  1252. }
  1253. private void button1_Click_1(object sender, EventArgs e)
  1254. {
  1255. iSEM.SetTiltAngleOff();
  1256. }
  1257. private void btnTiltAngleSetOn_Click(object sender, EventArgs e)
  1258. {
  1259. iSEM.SetTiltAngleOn();
  1260. }
  1261. private void btnScanRotationSetOn_Click(object sender, EventArgs e)
  1262. {
  1263. iSEM.SetScanRotationOn();
  1264. }
  1265. private void btnExeEly3_Click(object sender, EventArgs e)
  1266. {
  1267. iSEM.CmdFIBSTARTELY();
  1268. }
  1269. private void btnCreateConfig_Click(object sender, EventArgs e)
  1270. {
  1271. MeasureParam cfm = new MeasureParam();
  1272. cfm.Is_Photograph = chkWIsP.Checked;
  1273. cfm.PT = chkWPT.Checked;
  1274. cfm.PTTemp = txtWPTF.Text;
  1275. cfm.FIBTemp = txtWFIBF.Text;
  1276. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  1277. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  1278. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  1279. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  1280. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  1281. if(cbbWXZ.SelectedIndex==0)
  1282. {
  1283. cfm.Correction_Angle = 36;
  1284. }
  1285. else
  1286. {
  1287. cfm.Correction_Angle = 54;
  1288. }
  1289. cfm.SampleName = cbbWYP.Text;
  1290. cfm.Firm = cbbWCS.Text;
  1291. ConfigFile cf = new ConfigFile(cfm);
  1292. cf.Save(@"E:\test.cfg");
  1293. List<String> _sT = sT.ToList();
  1294. if(_sT.IndexOf(cbbWYP.Text)<0)
  1295. {
  1296. _sT.Add(cbbWYP.Text);
  1297. sT = _sT.ToArray();
  1298. string wsT = "";
  1299. for(int i=0;i<sT.Length;i++)
  1300. {
  1301. wsT += sT[i] + ",";
  1302. }
  1303. wsT = wsT.Substring(0, wsT.Length - 1);
  1304. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  1305. }
  1306. List<String> _firms = firms.ToList();
  1307. if (_firms.IndexOf(cbbWCS.Text) < 0)
  1308. {
  1309. _firms.Add(cbbWCS.Text);
  1310. firms = _firms.ToArray();
  1311. string wFirms = "";
  1312. for (int i = 0; i < firms.Length; i++)
  1313. {
  1314. wFirms += firms[i] + ",";
  1315. }
  1316. wFirms = wFirms.Substring(0, wFirms.Length - 1);
  1317. config.AppSettings.Settings["Firm"].Value = wFirms;
  1318. }
  1319. config.Save(ConfigurationSaveMode.Modified);
  1320. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  1321. reloadconfig();
  1322. }
  1323. private void btnReadConfig_Click(object sender, EventArgs e)
  1324. {
  1325. MeasureParam cfm = new MeasureParam();
  1326. ConfigFile cf = new ConfigFile(cfm);
  1327. cf.Read(@"E:\test.cfg");
  1328. chkRIsP.Checked = cfm.Is_Photograph;
  1329. chkRPT.Checked = cfm.PT;
  1330. txtRPTF.Text = cfm.PTTemp;
  1331. txtRFIBF.Text = cfm.FIBTemp;
  1332. txtRLZ.Text = cfm.Stretch_Magnification.ToString();
  1333. txtRQGF.Text = cfm.Location_Magnification.ToString();
  1334. txtRQGD.Text = cfm.Location_Voltage.ToString();
  1335. txtRPZF.Text = cfm.Photograph_Magnification.ToString();
  1336. txtRPZD.Text = cfm.Photograph_Voltage.ToString();
  1337. txtRXZ.Text = cfm.Correction_Angle.ToString();
  1338. txtRYP.Text = cfm.SampleName;
  1339. txtRCS.Text = cfm.Firm;
  1340. }
  1341. private void FormUnitControl_Load(object sender, EventArgs e)
  1342. {
  1343. reloadconfig();
  1344. cbbWYP.SelectedIndex = 0;
  1345. cbbWCS.SelectedIndex = 0;
  1346. cbbWXZ.SelectedIndex = 0;
  1347. this.chart1.Series[0].Points.Clear();
  1348. }
  1349. private void reloadconfig()
  1350. {
  1351. String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
  1352. String firm = ConfigurationManager.AppSettings["Firm"];
  1353. sT = sample_Type.Split(',');
  1354. cbbWYP.Items.Clear();
  1355. for (int i = 0; i < sT.Length; i++)
  1356. {
  1357. cbbWYP.Items.Add(sT[i]);
  1358. }
  1359. firms = firm.Split(',');
  1360. cbbWCS.Items.Clear();
  1361. for (int i = 0; i < firms.Length; i++)
  1362. {
  1363. cbbWCS.Items.Add(firms[i]);
  1364. }
  1365. }
  1366. private void btnPsFile_Click(object sender, EventArgs e)
  1367. {
  1368. OpenFileDialog sfd = new OpenFileDialog();
  1369. sfd.Title = "选择位置文件:";
  1370. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1371. sfd.Filter = "TXT文件|*.TXT";
  1372. if (sfd.ShowDialog() == DialogResult.OK)
  1373. {
  1374. //Console.WriteLine(sfd.FileName);
  1375. StreamReader sr = new StreamReader(sfd.FileName, Encoding.Default);
  1376. String line = "";
  1377. sr.ReadLine();
  1378. sr.ReadLine();
  1379. sr.ReadLine();
  1380. sr.ReadLine();
  1381. line = sr.ReadLine();
  1382. sr.Close();
  1383. sr.Dispose();
  1384. String[] lines = line.Split(',');
  1385. double x = Convert.ToDouble(lines[1]);
  1386. double y = Convert.ToDouble(lines[2]);
  1387. chart1.Series[0].Points.AddXY(x, y);
  1388. chart1.Series[0].Points[0].Label = x.ToString("0.000") + "," + y.ToString("0.000");
  1389. }
  1390. }
  1391. private void btnrect_Click(object sender, EventArgs e)
  1392. {
  1393. this.chart1.Series[0].Points.Clear();
  1394. List<double> xpoints = new List<double>();
  1395. List<double> ypoints = new List<double>();
  1396. //排列数
  1397. int rag = Convert.ToInt32(txtarray.Text);
  1398. //间距
  1399. double dist = Convert.ToDouble(txtdistance.Text);
  1400. //中心点x,y轴坐标
  1401. double cx = Convert.ToDouble(txtx.Text);
  1402. double cy = Convert.ToDouble(txty.Text);
  1403. //求样品1的水平角度
  1404. double angle = 0;
  1405. //xpoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1406. //ypoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1407. xpoints.Add(Convert.ToDouble(txtsample1x.Text));
  1408. ypoints.Add(Convert.ToDouble(txtsample1y.Text));
  1409. //计算第一个点与X轴的交角度数
  1410. angle = Math.Atan2(ypoints[0] - cy, cx - xpoints[0]) * 180 / Math.PI;
  1411. lblPs1.Text = angle.ToString("0.0");
  1412. //这里是求与第一个点横向排列的其他点的移动角度
  1413. //就是按45度向左向右移动的度
  1414. angle = 45 - angle;
  1415. angle = angle * Math.PI / 180;
  1416. txtsample1x.Text = xpoints[0].ToString("0.000");
  1417. txtsample1y.Text = ypoints[0].ToString("0.000");
  1418. chart1.Series[0].Points.AddXY(xpoints[0], ypoints[0]);
  1419. chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[0].ToString("0.000") + "," + ypoints[0].ToString("0.000");
  1420. double tx = 0;
  1421. double ty = 0;
  1422. for (int j = 0; j < rag; j++)
  1423. {
  1424. //计算每行第一个点的坐标
  1425. if(j>0)
  1426. {
  1427. tx = dist * j * Math.Sin(angle);
  1428. ty = dist * j * Math.Cos(angle);
  1429. xpoints.Add(tx + xpoints[0]);
  1430. ypoints.Add(ypoints[0] - ty);
  1431. chart1.Series[0].Points.AddXY(xpoints[xpoints.Count-1], ypoints[ypoints.Count-1]);
  1432. chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[xpoints.Count - 1].ToString("0.000") + "," + ypoints[ypoints.Count - 1].ToString("0.000");
  1433. }
  1434. //计算每行其他点的坐标
  1435. for (int i = 1; i < rag; i++)
  1436. {
  1437. tx = dist * i * Math.Cos(angle);
  1438. ty = dist * i * Math.Sin(angle);
  1439. xpoints.Add(tx + xpoints[j * rag]);
  1440. ypoints.Add(ty + ypoints[j * rag]);
  1441. chart1.Series[0].Points.AddXY(xpoints[xpoints.Count - 1], ypoints[ypoints.Count - 1]);
  1442. chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[xpoints.Count - 1].ToString("0.000") + "," + ypoints[ypoints.Count - 1].ToString("0.000");
  1443. }
  1444. }
  1445. }
  1446. public void AnalysisPosition(Double centerX,Double centerY,Double firstX,Double firstY,Double distance,int rag,ref List<Double> ptsx,ref List<Double> ptsy)
  1447. {
  1448. //求样品1的水平角度
  1449. double angle = 0;
  1450. //清空所有点信息
  1451. ptsx.Clear();
  1452. ptsy.Clear();
  1453. //将第一个点加入到点信息中
  1454. ptsx.Add(firstX);
  1455. ptsy.Add(firstY);
  1456. //计算第一个点与X轴的交角度数
  1457. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  1458. //这里是求与第一个点横向排列的其他点的移动角度
  1459. //就是按45度向左向右移动的度
  1460. angle = 45 - angle;
  1461. angle = angle * Math.PI / 180;
  1462. double tx = 0;
  1463. double ty = 0;
  1464. for (int j = 0; j < rag; j++)
  1465. {
  1466. //计算每行第一个点的坐标
  1467. if (j > 0)
  1468. {
  1469. tx = distance * j * Math.Sin(angle);
  1470. ty = distance * j * Math.Cos(angle);
  1471. ptsx.Add(tx + ptsx[0]);
  1472. ptsy.Add(ptsy[0] - ty);
  1473. }
  1474. //计算每行其他点的坐标
  1475. for (int i = 1; i < rag; i++)
  1476. {
  1477. tx = distance * i * Math.Cos(angle);
  1478. ty = distance * i * Math.Sin(angle);
  1479. ptsx.Add(tx + ptsx[j * rag]);
  1480. ptsy.Add(ty + ptsy[j * rag]);
  1481. }
  1482. }
  1483. }
  1484. private void btn30_Click(object sender, EventArgs e)
  1485. {
  1486. txtsample1x.Text = "21.7";
  1487. txtsample1y.Text = "90";
  1488. btnrect_Click(null, null);
  1489. }
  1490. private void btn45_Click(object sender, EventArgs e)
  1491. {
  1492. txtsample1x.Text = "29.65";
  1493. txtsample1y.Text = "100.35";
  1494. btnrect_Click(null, null);
  1495. }
  1496. private void btn60_Click(object sender, EventArgs e)
  1497. {
  1498. txtsample1x.Text = "40";
  1499. txtsample1y.Text = "108.3";
  1500. btnrect_Click(null, null);
  1501. }
  1502. private void button2_Click(object sender, EventArgs e)
  1503. {
  1504. float ret = iSEM.GetSEMVoltage();
  1505. if (float.IsNaN(ret))
  1506. {
  1507. txtVoltage.Text = "NaN";
  1508. txtVoltage.Enabled = false;
  1509. button2.Enabled = false;
  1510. }
  1511. else
  1512. {
  1513. txtVoltage.Text = ret.ToString();
  1514. button2.Enabled = true;
  1515. }
  1516. }
  1517. private void button1_Click(object sender, EventArgs e)
  1518. {
  1519. float set = 0;
  1520. if (float.TryParse(txtVoltage.Text, out set))
  1521. {
  1522. iSEM.SetSEMVoltage(set);
  1523. }
  1524. }
  1525. }
  1526. }