FormUnitControl.cs 52 KB

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