FormUnitControl.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. //时间:
  2. //作者:
  3. //功能:单元测试功能
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.IO;
  16. using SmartSEMControl;
  17. using FileManager;
  18. using System.Xml;
  19. using MeasureData;
  20. namespace HOZProject
  21. {
  22. public partial class FormUnitControl : Form
  23. {
  24. #region 系统参数
  25. //全局只有一个fatorySEM
  26. static FactoryHardware factorySEM = FactoryHardware.Instance;
  27. ISEMControl iSEM = factorySEM.ISEM;
  28. public XmlManager xmg = new XmlManager();
  29. private String path = Directory.GetCurrentDirectory();
  30. private int st_flag = 0;
  31. #endregion
  32. #region 构造函数
  33. public FormUnitControl()
  34. {
  35. InitializeComponent();
  36. Control.CheckForIllegalCrossThreadCalls = false;
  37. if(iSEM.ConnectStatus())
  38. {
  39. float ret = iSEM.GetFIBIMAGING();
  40. if(ret==0)
  41. {
  42. btnSEM.BackColor = Color.Lime;
  43. }
  44. else if(ret==1)
  45. {
  46. btnFIB.BackColor = Color.Lime;
  47. panelFIB.Visible = true;
  48. }
  49. else if(ret==2)
  50. {
  51. btnMILL.BackColor = Color.Lime;
  52. }
  53. }
  54. //Calling Notification for updated status
  55. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  56. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  57. //加载参数
  58. }
  59. #endregion
  60. #region 缩放Get
  61. private void btnenlargeGet_Click(object sender, EventArgs e)
  62. {
  63. float ret = iSEM.GetMagnification();
  64. if (float.IsNaN(ret))
  65. {
  66. txtenlargeSet.Text = "NaN";
  67. txtenlargeSet.Enabled = false;
  68. btnenlargeSet.Enabled = false;
  69. }
  70. else
  71. {
  72. txtenlargeSet.Text = ret.ToString();
  73. btnenlargeSet.Enabled = true;
  74. }
  75. }
  76. #endregion
  77. #region 缩放Set
  78. private void btnenlargeSet_Click(object sender, EventArgs e)
  79. {
  80. float set = 0;
  81. if (float.TryParse(txtenlargeSet.Text, out set))
  82. {
  83. iSEM.SetMagnification(set);
  84. }
  85. }
  86. #endregion
  87. #region 焦距Get
  88. private void btnWDGet_Click(object sender, EventArgs e)
  89. {
  90. float ret = iSEM.GetWorkingDistance();
  91. if (float.IsNaN(ret))
  92. {
  93. txtWDSet.Text = "NaN";
  94. txtWDSet.Enabled = false;
  95. btnWDSet.Enabled = false;
  96. }
  97. else
  98. {
  99. txtWDSet.Text = ret.ToString();
  100. btnWDSet.Enabled = true;
  101. }
  102. }
  103. #endregion
  104. #region 焦距Set
  105. private void btnWDSet_Click(object sender, EventArgs e)
  106. {
  107. float set = 0;
  108. if (float.TryParse(txtWDSet.Text, out set))
  109. {
  110. iSEM.SetWorkingDistance(set);
  111. }
  112. }
  113. #endregion
  114. #region 亮度Get
  115. private void btnBrightnessGet_Click(object sender, EventArgs e)
  116. {
  117. float ret = iSEM.GetBrightness();
  118. if (float.IsNaN(ret))
  119. {
  120. txtBrightnessSet.Text = "NaN";
  121. txtBrightnessSet.Enabled = false;
  122. btnBrightnessSet.Enabled = false;
  123. }
  124. else
  125. {
  126. txtBrightnessSet.Text = ret.ToString();
  127. btnBrightnessSet.Enabled = true;
  128. }
  129. }
  130. #endregion
  131. #region 亮度Set
  132. private void btnBrightnessSet_Click(object sender, EventArgs e)
  133. {
  134. float set = 0;
  135. if (float.TryParse(txtBrightnessSet.Text, out set))
  136. {
  137. iSEM.SetBrightness(set);
  138. }
  139. }
  140. #endregion
  141. #region 对比度Get
  142. private void btnContrastGet_Click(object sender, EventArgs e)
  143. {
  144. float ret = iSEM.GetContrast();
  145. if (float.IsNaN(ret))
  146. {
  147. txtContrastSet.Text = "NaN";
  148. txtContrastSet.Enabled = false;
  149. btnContrastSet.Enabled = false;
  150. }
  151. else
  152. {
  153. txtContrastSet.Text = ret.ToString();
  154. btnContrastSet.Enabled = true;
  155. }
  156. }
  157. #endregion
  158. #region 对比度Set
  159. private void btnContrastSet_Click(object sender, EventArgs e)
  160. {
  161. float set = 0;
  162. if (float.TryParse(txtContrastSet.Text, out set))
  163. {
  164. iSEM.SetContrast(set);
  165. }
  166. }
  167. #endregion
  168. #region 消像散X Get
  169. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  170. {
  171. float ret = iSEM.GetAstigmatismX();
  172. if (float.IsNaN(ret))
  173. {
  174. txtAstigmatismXSet.Text = "NaN";
  175. txtAstigmatismXSet.Enabled = false;
  176. btnAstigmatismXSet.Enabled = false;
  177. }
  178. else
  179. {
  180. txtAstigmatismXSet.Text = ret.ToString();
  181. btnAstigmatismXSet.Enabled = true;
  182. }
  183. }
  184. #endregion
  185. #region 消像散X Set
  186. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  187. {
  188. float set = 0;
  189. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  190. {
  191. iSEM.SetAstigmatismX(set);
  192. }
  193. }
  194. #endregion
  195. #region 消像散Y Get
  196. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  197. {
  198. float ret = iSEM.GetAstigmatismY();
  199. if (float.IsNaN(ret))
  200. {
  201. txtAstigmatismYSet.Text = "NaN";
  202. txtAstigmatismYSet.Enabled = false;
  203. btnAstigmatismYSet.Enabled = false;
  204. }
  205. else
  206. {
  207. txtAstigmatismYSet.Text = ret.ToString();
  208. btnAstigmatismYSet.Enabled = true;
  209. }
  210. }
  211. #endregion
  212. #region 消像散Y Set
  213. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  214. {
  215. float set = 0;
  216. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  217. {
  218. iSEM.SetAstigmatismY(set);
  219. }
  220. }
  221. #endregion
  222. #region 角度补偿Get
  223. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  224. {
  225. float ret = iSEM.GetTiltAngle();
  226. if (float.IsNaN(ret))
  227. {
  228. txtTiltAngleSet.Text = "NaN";
  229. txtTiltAngleSet.Enabled = false;
  230. btnTiltAngleSet.Enabled = false;
  231. }
  232. else
  233. {
  234. txtTiltAngleSet.Text = ret.ToString();
  235. btnTiltAngleSet.Enabled = true;
  236. }
  237. }
  238. #endregion
  239. #region 角度补偿Set
  240. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  241. {
  242. float set = 0;
  243. if (float.TryParse(txtTiltAngleSet.Text, out set))
  244. {
  245. iSEM.SetTiltAngle(set);
  246. }
  247. }
  248. #endregion
  249. #region 抓取图像
  250. private void btnGrabImage_Click(object sender, EventArgs e)
  251. {
  252. SaveFileDialog sfd = new SaveFileDialog();
  253. sfd.Title = "图像保存位置:";
  254. sfd.FileName = "test.tif";
  255. sfd.Filter = "TIF文件|*.tif";
  256. if (sfd.ShowDialog() == DialogResult.OK)
  257. {
  258. string fn = sfd.FileName;
  259. iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
  260. }
  261. }
  262. #endregion
  263. #region ScanRotate Get
  264. private void btnScanRotationGet_Click(object sender, EventArgs e)
  265. {
  266. float ret = iSEM.GetScanRotation();
  267. if (float.IsNaN(ret))
  268. {
  269. txtScanRotationSet.Text = "NaN";
  270. txtScanRotationSet.Enabled = false;
  271. btnScanRotationSet.Enabled = false;
  272. }
  273. else
  274. {
  275. txtScanRotationSet.Text = ret.ToString();
  276. btnScanRotationSet.Enabled = true;
  277. }
  278. }
  279. #endregion
  280. #region ScanRotate Set
  281. private void btnScanRotationSet_Click(object sender, EventArgs e)
  282. {
  283. float set = 0;
  284. if (float.TryParse(txtScanRotationSet.Text, out set))
  285. {
  286. iSEM.SetScanRotation(set);
  287. }
  288. }
  289. #endregion
  290. #region PixelSize Get
  291. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  292. {
  293. float ret = iSEM.GetPixelSize();
  294. if (float.IsNaN(ret))
  295. {
  296. lblPixelSizeGet.Text = "NaN";
  297. }
  298. else
  299. {
  300. lblPixelSizeGet.Text = ret.ToString();
  301. }
  302. }
  303. #endregion
  304. #region 电子束
  305. private void btnTiltCorrXGet_Click(object sender, EventArgs e)
  306. {
  307. float ret = iSEM.GetBeamShiftX();
  308. if (float.IsNaN(ret))
  309. {
  310. txtTiltCorrX.Text = "NaN";
  311. txtTiltCorrX.Enabled = false;
  312. btnTiltCorrXSet.Enabled = false;
  313. }
  314. else
  315. {
  316. txtTiltCorrX.Text = ret.ToString();
  317. btnTiltCorrXSet.Enabled = true;
  318. }
  319. }
  320. private void btnTiltCorrXSet_Click(object sender, EventArgs e)
  321. {
  322. float set = 0;
  323. if (float.TryParse(txtTiltCorrX.Text, out set))
  324. {
  325. iSEM.SetBeamShiftX(set);
  326. }
  327. }
  328. private void btnTiltCorrYGet_Click(object sender, EventArgs e)
  329. {
  330. float ret = iSEM.GetBeamShiftY();
  331. if (float.IsNaN(ret))
  332. {
  333. txtTiltCorrY.Text = "NaN";
  334. txtTiltCorrY.Enabled = false;
  335. btnTiltCorrYSet.Enabled = false;
  336. }
  337. else
  338. {
  339. txtTiltCorrY.Text = ret.ToString();
  340. btnTiltCorrYSet.Enabled = true;
  341. }
  342. }
  343. private void btnTiltCorrYSet_Click(object sender, EventArgs e)
  344. {
  345. float set = 0;
  346. if (float.TryParse(txtTiltCorrY.Text, out set))
  347. {
  348. iSEM.SetBeamShiftY(set);
  349. }
  350. }
  351. #endregion
  352. #region 开启电压
  353. private void btnOpenVoltage_Click(object sender, EventArgs e)
  354. {
  355. iSEM.CmdOpenVoltage();
  356. }
  357. #endregion
  358. #region 关闭电压
  359. private void btnCloseVoltage_Click(object sender, EventArgs e)
  360. {
  361. iSEM.CmdCloseVoltage();
  362. }
  363. #endregion
  364. #region 电子束校正
  365. private void btnTiltCorr_Click(object sender, EventArgs e)
  366. {
  367. float ret = iSEM.GetTiltCorrection();
  368. if (float.IsNaN(ret))
  369. {
  370. btnTiltCorr.BackColor = Color.Red;
  371. }
  372. else
  373. {
  374. if(ret==0)
  375. {
  376. btnTiltCorr.BackColor = Color.Blue;
  377. iSEM.SetTiltCorrectionOn();
  378. btnTiltCorr.Text = "电子束状态:On";
  379. }
  380. else
  381. {
  382. btnTiltCorr.BackColor = Color.Lime;
  383. iSEM.SetTiltCorrectionOff();
  384. btnTiltCorr.Text = "电子束状态:Off";
  385. }
  386. }
  387. }
  388. #endregion
  389. #region 样品台位置获取
  390. private void btnStageGetX_Click(object sender, EventArgs e)
  391. {
  392. float ret = iSEM.GetStageAtX();
  393. if (float.IsNaN(ret))
  394. {
  395. lblStageX.Text = "NaN";
  396. }
  397. else
  398. {
  399. lblStageX.Text = ret.ToString();
  400. }
  401. }
  402. private void btnStageGetY_Click(object sender, EventArgs e)
  403. {
  404. float ret = iSEM.GetStageAtY();
  405. if (float.IsNaN(ret))
  406. {
  407. lblStageY.Text = "NaN";
  408. }
  409. else
  410. {
  411. lblStageY.Text = ret.ToString();
  412. }
  413. }
  414. private void btnStageGetZ_Click(object sender, EventArgs e)
  415. {
  416. float ret = iSEM.GetStageAtZ();
  417. if (float.IsNaN(ret))
  418. {
  419. lblStageZ.Text = "NaN";
  420. }
  421. else
  422. {
  423. lblStageZ.Text = ret.ToString();
  424. }
  425. }
  426. private void btnStageGetT_Click(object sender, EventArgs e)
  427. {
  428. float ret = iSEM.GetStageAtT();
  429. if (float.IsNaN(ret))
  430. {
  431. lblStageT.Text = "NaN";
  432. }
  433. else
  434. {
  435. lblStageT.Text = ret.ToString();
  436. }
  437. }
  438. private void btnStageGetR_Click(object sender, EventArgs e)
  439. {
  440. float ret = iSEM.GetStageAtR();
  441. if (float.IsNaN(ret))
  442. {
  443. lblStageR.Text = "NaN";
  444. }
  445. else
  446. {
  447. lblStageR.Text = ret.ToString();
  448. }
  449. }
  450. private void btnStageGetM_Click(object sender, EventArgs e)
  451. {
  452. float ret = iSEM.GetStageAtM();
  453. if (float.IsNaN(ret))
  454. {
  455. lblStageM.Text = "NaN";
  456. }
  457. else
  458. {
  459. lblStageM.Text = ret.ToString();
  460. }
  461. }
  462. #endregion
  463. #region 样品台位置设置
  464. private void btnStageSetX_Click(object sender, EventArgs e)
  465. {
  466. float set = 0;
  467. if (float.TryParse(txtStageX.Text, out set))
  468. {
  469. iSEM.SetStageGotoX(set);
  470. }
  471. }
  472. private void btnStageSetY_Click(object sender, EventArgs e)
  473. {
  474. float set = 0;
  475. if (float.TryParse(txtStageY.Text, out set))
  476. {
  477. iSEM.SetStageGotoY(set);
  478. }
  479. }
  480. private void btnStageSetZ_Click(object sender, EventArgs e)
  481. {
  482. float set = 0;
  483. if (float.TryParse(txtStageZ.Text, out set))
  484. {
  485. iSEM.SetStageGotoZ(set);
  486. }
  487. }
  488. private void btnStageSetT_Click(object sender, EventArgs e)
  489. {
  490. float set = 0;
  491. if (float.TryParse(txtStageT.Text, out set))
  492. {
  493. iSEM.SetStageGotoT(set);
  494. }
  495. }
  496. private void btnStageSetR_Click(object sender, EventArgs e)
  497. {
  498. float set = 0;
  499. if (float.TryParse(txtStageR.Text, out set))
  500. {
  501. iSEM.SetStageGotoR(set);
  502. }
  503. }
  504. private void btnStageSetM_Click(object sender, EventArgs e)
  505. {
  506. float set = 0;
  507. if (float.TryParse(txtStageM.Text, out set))
  508. {
  509. iSEM.SetStageGotoM(set);
  510. }
  511. }
  512. #endregion
  513. #region 获取样品台位置数组
  514. private void btnGetStagePosition_Click(object sender, EventArgs e)
  515. {
  516. float[] pt = iSEM.GetStagePosition();
  517. if (!float.IsNaN(pt[0]))
  518. {
  519. lblStageX.Text = pt[0].ToString();
  520. }
  521. if (!float.IsNaN(pt[1]))
  522. {
  523. lblStageY.Text = pt[1].ToString();
  524. }
  525. if (!float.IsNaN(pt[2]))
  526. {
  527. lblStageZ.Text = pt[2].ToString();
  528. }
  529. if (!float.IsNaN(pt[3]))
  530. {
  531. lblStageT.Text = pt[3].ToString();
  532. }
  533. if (!float.IsNaN(pt[4]))
  534. {
  535. lblStageR.Text = pt[4].ToString();
  536. }
  537. if (!float.IsNaN(pt[5]))
  538. {
  539. lblStageM.Text = pt[5].ToString();
  540. }
  541. }
  542. #endregion
  543. #region 窗体关闭
  544. private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
  545. {
  546. if(iSEM!=null)
  547. {
  548. iSEM.Dispose();
  549. }
  550. }
  551. #endregion
  552. #region 宏文件
  553. private void btnCMDMCF_Click(object sender, EventArgs e)
  554. {
  555. iSEM.CMDMCFFilename("OPTON");
  556. }
  557. #endregion
  558. #region 读取Xml文件
  559. private void btnReadXml_Click(object sender, EventArgs e)
  560. {
  561. MeasureFile mf = new MeasureFile();
  562. XmlDocument doc = new XmlDocument();
  563. doc.Load("test.xml");//载入xml文件
  564. XmlNode root = doc.SelectSingleNode("XMLData");
  565. mf.Serialize(false, doc, root);
  566. doc.Save("test.xml");
  567. }
  568. #endregion
  569. #region 写入Xml文件
  570. private void btnWriteXml_Click(object sender, EventArgs e)
  571. {
  572. MeasureFile mf = new MeasureFile();
  573. mf.FileName = "test_opton.msf";
  574. mf.FilePath = path;
  575. CutHole ch = new CutHole();
  576. ch.SampleName = "SampleName1";
  577. ch.PT = true;
  578. ch.FIBTemp = "FIBTemp1";
  579. ch.PTTemp = "PTTemp1";
  580. ch.OPT = Operation.Image;
  581. ch.START = System.DateTime.Now;
  582. ch.END = System.DateTime.Now.AddHours(2);
  583. ch.STATE = State.Success;
  584. ch.SWITCH = true;
  585. SemPosition sp = new SemPosition();
  586. sp.X = 11;
  587. sp.Y = 22;
  588. sp.Z = 33;
  589. sp.T = 44;
  590. sp.R = 55;
  591. sp.M = 66;
  592. ch.Position = sp;
  593. mf.ListCutHole.Add(ch);
  594. ch = new CutHole();
  595. ch.SampleName = "SampleName2";
  596. ch.PT = true;
  597. ch.FIBTemp = "FIBTemp2";
  598. ch.PTTemp = "PTTemp2";
  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. mf.New();
  614. //XmlDocument doc = new XmlDocument();
  615. //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
  616. //XmlNode root = doc.SelectSingleNode("XMLData");
  617. //mf.Serialize(true, doc, root);
  618. //doc.Save("test.aaa");
  619. }
  620. #endregion
  621. #region SEM模式
  622. private void btnSEM_Click(object sender, EventArgs e)
  623. {
  624. if(iSEM.CmdFIBModeSEM())
  625. {
  626. btnFIB.BackColor = SystemColors.Control;
  627. btnSEM.BackColor = Color.Lime;
  628. btnMILL.BackColor = SystemColors.Control;
  629. panelFIB.Visible = false;
  630. }
  631. }
  632. #endregion
  633. #region FIB模式
  634. private void btnFIB_Click(object sender, EventArgs e)
  635. {
  636. if(iSEM.CmdFIBModeFIB())
  637. {
  638. btnFIB.BackColor = Color.Lime;
  639. btnSEM.BackColor = SystemColors.Control;
  640. btnMILL.BackColor = SystemColors.Control;
  641. panelFIB.Visible = true;
  642. }
  643. }
  644. #endregion
  645. #region MILL模式
  646. private void btnMILL_Click(object sender, EventArgs e)
  647. {
  648. if(iSEM.CmdFIBModeMILL())
  649. {
  650. btnFIB.BackColor = SystemColors.Control;
  651. btnSEM.BackColor = SystemColors.Control;
  652. btnMILL.BackColor = Color.Lime;
  653. }
  654. }
  655. #endregion
  656. #region 自动对焦1
  657. private void btnAutoFocus1_Click(object sender, EventArgs e)
  658. {
  659. //抓图1
  660. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  661. if (File.Exists(path + "\\test1.tif"))
  662. {
  663. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  664. pictureBox1.Image = Image.FromStream(fileStream);
  665. fileStream.Close();
  666. fileStream.Dispose();
  667. }
  668. Thread.Sleep(1000);
  669. iSEM.CmdAutoFocusCoarse();
  670. btnAutoFocus1.BackColor = Color.Red;
  671. st_flag = 1;
  672. Thread.Sleep(1000);
  673. Thread thread = new Thread(AutoFunction);
  674. thread.Start();
  675. }
  676. #endregion
  677. #region 自动函数监测线程
  678. private void AutoFunction()
  679. {
  680. float ret = 111;
  681. Boolean state = false;
  682. while(true)
  683. {
  684. Thread.Sleep(1000);
  685. ret = iSEM.GetAutoFunction();
  686. if(ret==0)
  687. {
  688. if (st_flag == 1 && state == true)
  689. {
  690. btnAutoFocus1.BackColor = Color.Lime;
  691. Thread.Sleep(1000);
  692. //抓图1
  693. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  694. if (File.Exists(path + "\\test2.tif"))
  695. {
  696. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  697. pictureBox2.Image = Image.FromStream(fileStream);
  698. fileStream.Close();
  699. fileStream.Dispose();
  700. }
  701. break;
  702. }
  703. else if(st_flag==2 && state)
  704. {
  705. btnAutoFocus2.BackColor = Color.Lime;
  706. Thread.Sleep(1000);
  707. //抓图1
  708. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  709. if (File.Exists(path + "\\test2.tif"))
  710. {
  711. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  712. pictureBox2.Image = Image.FromStream(fileStream);
  713. fileStream.Close();
  714. fileStream.Dispose();
  715. }
  716. break;
  717. }
  718. else if (st_flag == 3)
  719. {
  720. btnAutoBrightness.BackColor = Color.Lime;
  721. Thread.Sleep(1000);
  722. //抓图1
  723. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  724. if (File.Exists(path + "\\test2.tif"))
  725. {
  726. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  727. pictureBox2.Image = Image.FromStream(fileStream);
  728. fileStream.Close();
  729. fileStream.Dispose();
  730. }
  731. break;
  732. }
  733. else if (st_flag == 4)
  734. {
  735. btnAutoContrast.BackColor = Color.Lime;
  736. Thread.Sleep(1000);
  737. //抓图1
  738. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  739. if (File.Exists(path + "\\test2.tif"))
  740. {
  741. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  742. pictureBox2.Image = Image.FromStream(fileStream);
  743. fileStream.Close();
  744. fileStream.Dispose();
  745. }
  746. break;
  747. }
  748. else if (st_flag == 5)
  749. {
  750. btnAutoBrightness.BackColor = Color.Lime;
  751. btnAutoContrast.BackColor = Color.Lime;
  752. btnAutoBC.BackColor = Color.Lime;
  753. Thread.Sleep(1000);
  754. //抓图1
  755. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  756. if (File.Exists(path + "\\test2.tif"))
  757. {
  758. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  759. pictureBox2.Image = Image.FromStream(fileStream);
  760. fileStream.Close();
  761. fileStream.Dispose();
  762. }
  763. break;
  764. }
  765. else if (st_flag == 6 && state)
  766. {
  767. btnAutoBCCancle.BackColor = Color.Lime;
  768. Thread.Sleep(1000);
  769. //抓图1
  770. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  771. if (File.Exists(path + "\\test2.tif"))
  772. {
  773. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  774. pictureBox2.Image = Image.FromStream(fileStream);
  775. fileStream.Close();
  776. fileStream.Dispose();
  777. }
  778. break;
  779. }
  780. else if (st_flag == 7 && state)
  781. {
  782. btnAutoStig.BackColor = Color.Lime;
  783. Thread.Sleep(1000);
  784. //抓图1
  785. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  786. if (File.Exists(path + "\\test2.tif"))
  787. {
  788. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  789. pictureBox2.Image = Image.FromStream(fileStream);
  790. fileStream.Close();
  791. fileStream.Dispose();
  792. }
  793. break;
  794. }
  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. }
  805. else if(ret>0 && ret<12)
  806. {
  807. state = true;
  808. }
  809. }
  810. }
  811. #endregion
  812. #region 自动对焦2
  813. private void btnAutoFocus2_Click(object sender, EventArgs e)
  814. {
  815. //抓图1
  816. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  817. if (File.Exists(path + "\\test1.tif"))
  818. {
  819. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  820. pictureBox1.Image = Image.FromStream(fileStream);
  821. fileStream.Close();
  822. fileStream.Dispose();
  823. }
  824. Thread.Sleep(1000);
  825. iSEM.CmdAutoFocusFine();
  826. btnAutoFocus2.BackColor = Color.Red;
  827. st_flag = 2;
  828. Thread.Sleep(1000);
  829. Thread thread = new Thread(AutoFunction);
  830. thread.Start();
  831. }
  832. #endregion
  833. #region 自动亮度、对比度
  834. private void btnAutoBrightness_Click(object sender, EventArgs e)
  835. {
  836. //抓图1
  837. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  838. if (File.Exists(path + "\\test1.tif"))
  839. {
  840. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  841. pictureBox1.Image = Image.FromStream(fileStream);
  842. fileStream.Close();
  843. fileStream.Dispose();
  844. }
  845. Thread.Sleep(1000);
  846. iSEM.SetAutoVideoBrightness();
  847. btnAutoBrightness.BackColor = Color.Red;
  848. st_flag = 3;
  849. Thread.Sleep(1000);
  850. Thread thread = new Thread(AutoFunction);
  851. thread.Start();
  852. }
  853. private void btnAutoContrast_Click(object sender, EventArgs e)
  854. {
  855. //抓图1
  856. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  857. if (File.Exists(path + "\\test1.tif"))
  858. {
  859. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  860. pictureBox1.Image = Image.FromStream(fileStream);
  861. fileStream.Close();
  862. fileStream.Dispose();
  863. }
  864. Thread.Sleep(1000);
  865. iSEM.SetAutoVideoBrightness();
  866. btnAutoContrast.BackColor = Color.Red;
  867. st_flag = 4;
  868. Thread.Sleep(1000);
  869. Thread thread = new Thread(AutoFunction);
  870. thread.Start();
  871. }
  872. private void btnAutoBC_Click(object sender, EventArgs e)
  873. {
  874. //抓图1
  875. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  876. if (File.Exists(path + "\\test1.tif"))
  877. {
  878. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  879. pictureBox1.Image = Image.FromStream(fileStream);
  880. fileStream.Close();
  881. fileStream.Dispose();
  882. }
  883. Thread.Sleep(1000);
  884. iSEM.SetAutoVideoBrightness();
  885. btnAutoBrightness.BackColor = Color.Red;
  886. btnAutoContrast.BackColor = Color.Red;
  887. btnAutoBC.BackColor = Color.Red;
  888. st_flag = 5;
  889. Thread.Sleep(1000);
  890. Thread thread = new Thread(AutoFunction);
  891. thread.Start();
  892. }
  893. private void btnAutoBCCancle_Click(object sender, EventArgs e)
  894. {
  895. iSEM.SetAutoVideoOff();
  896. btnAutoBCCancle.BackColor = Color.Red;
  897. st_flag = 6;
  898. Thread.Sleep(1000);
  899. Thread thread = new Thread(AutoFunction);
  900. thread.Start();
  901. }
  902. #endregion
  903. #region 自动消像散
  904. private void btnAutoStig_Click(object sender, EventArgs e)
  905. {
  906. //抓图1
  907. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  908. if (File.Exists(path + "\\test1.tif"))
  909. {
  910. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  911. pictureBox1.Image = Image.FromStream(fileStream);
  912. fileStream.Close();
  913. fileStream.Dispose();
  914. }
  915. Thread.Sleep(1000);
  916. iSEM.CmdAutoStig();
  917. btnAutoStig.BackColor = Color.Red;
  918. st_flag = 7;
  919. Thread.Sleep(1000);
  920. Thread thread = new Thread(AutoFunction);
  921. thread.Start();
  922. }
  923. #endregion
  924. #region FIB缩放Get
  925. private void btnFIBMagGet_Click(object sender, EventArgs e)
  926. {
  927. float ret = iSEM.GetFIBMagnification();
  928. if (float.IsNaN(ret))
  929. {
  930. txtFIBMag.Text = "NaN";
  931. txtFIBMag.Enabled = false;
  932. btnFIBMagSet.Enabled = false;
  933. }
  934. else
  935. {
  936. txtFIBMag.Text = ret.ToString();
  937. btnFIBMagSet.Enabled = true;
  938. }
  939. }
  940. #endregion
  941. #region FIB缩放Set
  942. private void btnFIBMagSet_Click(object sender, EventArgs e)
  943. {
  944. float set = 0;
  945. if (float.TryParse(txtFIBMag.Text, out set))
  946. {
  947. iSEM.SetFIBMagnification(set);
  948. }
  949. }
  950. #endregion
  951. #region FIB焦距Get
  952. private void btnFIBWDGet_Click(object sender, EventArgs e)
  953. {
  954. float ret = iSEM.GetFIBObjectivePotential();
  955. if (float.IsNaN(ret))
  956. {
  957. txtFIBWD.Text = "NaN";
  958. txtFIBWD.Enabled = false;
  959. btnFIBWDSet.Enabled = false;
  960. }
  961. else
  962. {
  963. txtFIBWD.Text = ret.ToString();
  964. btnFIBWDSet.Enabled = true;
  965. }
  966. }
  967. #endregion
  968. #region FIB焦距Set
  969. private void btnFIBWDSet_Click(object sender, EventArgs e)
  970. {
  971. float set = 0;
  972. if (float.TryParse(txtFIBWD.Text, out set))
  973. {
  974. iSEM.SetFIBObjectivePotential(set);
  975. }
  976. }
  977. #endregion
  978. #region FIB电子束移动
  979. private void btnFIBBeamShiftXGet_Click(object sender, EventArgs e)
  980. {
  981. float ret = iSEM.GetFIBBeamShiftX();
  982. if (float.IsNaN(ret))
  983. {
  984. txtFIBBeamShiftX.Text = "NaN";
  985. txtFIBBeamShiftX.Enabled = false;
  986. btnFIBBeamShiftXSet.Enabled = false;
  987. }
  988. else
  989. {
  990. txtFIBBeamShiftX.Text = ret.ToString();
  991. btnFIBBeamShiftXSet.Enabled = true;
  992. }
  993. }
  994. private void btnFIBBeamShiftXSet_Click(object sender, EventArgs e)
  995. {
  996. float set = 0;
  997. if (float.TryParse(txtFIBBeamShiftX.Text, out set))
  998. {
  999. iSEM.SetFIBBeamShiftX(set);
  1000. }
  1001. }
  1002. private void btnFIBBeamShiftYGet_Click(object sender, EventArgs e)
  1003. {
  1004. float ret = iSEM.GetFIBBeamShiftY();
  1005. if (float.IsNaN(ret))
  1006. {
  1007. txtFIBBeamShiftY.Text = "NaN";
  1008. txtFIBBeamShiftY.Enabled = false;
  1009. btnFIBBeamShiftYSet.Enabled = false;
  1010. }
  1011. else
  1012. {
  1013. txtFIBBeamShiftY.Text = ret.ToString();
  1014. btnFIBBeamShiftYSet.Enabled = true;
  1015. }
  1016. }
  1017. private void btnFIBBeamShiftYSet_Click(object sender, EventArgs e)
  1018. {
  1019. float set = 0;
  1020. if (float.TryParse(txtFIBBeamShiftY.Text, out set))
  1021. {
  1022. iSEM.SetFIBBeamShiftY(set);
  1023. }
  1024. }
  1025. #endregion
  1026. #region 执行宏文件
  1027. private void btnMCF_Click(object sender, EventArgs e)
  1028. {
  1029. OpenFileDialog sfd = new OpenFileDialog();
  1030. sfd.Title = "选择宏文件:";
  1031. sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1032. sfd.Filter = "MLF文件|*.MLF";
  1033. if (sfd.ShowDialog() == DialogResult.OK)
  1034. {
  1035. string fn = Path.GetFileNameWithoutExtension(sfd.FileName).ToUpper();
  1036. iSEM.CMDMCFFilename(fn);
  1037. }
  1038. }
  1039. #endregion
  1040. #region FIB消像散
  1041. private void btnFIBAstigmatismXGet_Click(object sender, EventArgs e)
  1042. {
  1043. float ret = iSEM.GetFIBAstigmatismX();
  1044. if (float.IsNaN(ret))
  1045. {
  1046. txtFIBAstigmatismX.Text = "NaN";
  1047. txtFIBAstigmatismX.Enabled = false;
  1048. btnFIBAstigmatismXSet.Enabled = false;
  1049. }
  1050. else
  1051. {
  1052. txtFIBAstigmatismX.Text = ret.ToString();
  1053. btnFIBAstigmatismXSet.Enabled = true;
  1054. }
  1055. }
  1056. private void btnFIBAstigmatismXSet_Click(object sender, EventArgs e)
  1057. {
  1058. float set = 0;
  1059. if (float.TryParse(txtFIBAstigmatismX.Text, out set))
  1060. {
  1061. iSEM.SetFIBAstigmatismX(set);
  1062. }
  1063. }
  1064. private void btnFIBAstigmatismYGet_Click(object sender, EventArgs e)
  1065. {
  1066. float ret = iSEM.GetFIBAstigmatismY();
  1067. if (float.IsNaN(ret))
  1068. {
  1069. txtFIBAstigmatismY.Text = "NaN";
  1070. txtFIBAstigmatismY.Enabled = false;
  1071. btnFIBAstigmatismYSet.Enabled = false;
  1072. }
  1073. else
  1074. {
  1075. txtFIBAstigmatismY.Text = ret.ToString();
  1076. btnFIBAstigmatismYSet.Enabled = true;
  1077. }
  1078. }
  1079. private void btnFIBAstigmatismYSet_Click(object sender, EventArgs e)
  1080. {
  1081. float set = 0;
  1082. if (float.TryParse(txtFIBAstigmatismY.Text, out set))
  1083. {
  1084. iSEM.SetFIBAstigmatismY(set);
  1085. }
  1086. }
  1087. #endregion
  1088. #region 移动样品台XY
  1089. private void btnMoveXY_Click(object sender, EventArgs e)
  1090. {
  1091. float setx = 0;
  1092. float sety = 0;
  1093. if (!float.TryParse(txtStageX.Text, out setx))
  1094. {
  1095. return;
  1096. }
  1097. if(!float.TryParse(txtStageY.Text,out sety))
  1098. {
  1099. return;
  1100. }
  1101. btnMoveXY.BackColor = Color.Red;
  1102. iSEM.MoveStageXY(setx, sety);
  1103. Thread.Sleep(500);
  1104. Thread th = new Thread(MoveStagexy);
  1105. th.Start();
  1106. }
  1107. private void MoveStagexy()
  1108. {
  1109. float ret = 111;
  1110. while(true)
  1111. {
  1112. ret = iSEM.GetStageIs();
  1113. if(ret==0)
  1114. {
  1115. btnMoveXY.BackColor = Color.Lime;
  1116. break;
  1117. }
  1118. }
  1119. }
  1120. #endregion
  1121. #region 获取分辨率
  1122. private void btnImageStoreGet_Click(object sender, EventArgs e)
  1123. {
  1124. int[] ret = iSEM.GetImageStore();
  1125. lblImageStore.Text = ret[0].ToString() + "*" + ret[1].ToString();
  1126. }
  1127. #endregion
  1128. #region 设置分辨率
  1129. private void btnImageStoreSet_Click(object sender, EventArgs e)
  1130. {
  1131. if (cmbImageStore.SelectedIndex > -1 && cmbImageStore.SelectedIndex < 12)
  1132. {
  1133. iSEM.SetImageStore(cmbImageStore.SelectedIndex);
  1134. }
  1135. }
  1136. #endregion
  1137. #region 样品台急停
  1138. private void btnAbort_Click(object sender, EventArgs e)
  1139. {
  1140. iSEM.CmdStageAbort();
  1141. }
  1142. #endregion
  1143. private void btnLive_Click(object sender, EventArgs e)
  1144. {
  1145. iSEM.ImageLive();
  1146. }
  1147. private void btnFrozen_Click(object sender, EventArgs e)
  1148. {
  1149. iSEM.ImageFrozen();
  1150. }
  1151. private void btnExeEly_Click(object sender, EventArgs e)
  1152. {
  1153. iSEM.CmdFIBLoadELY(@"E:\HOZ\MillStep2.ely");
  1154. }
  1155. private void btnExeEly2_Click(object sender, EventArgs e)
  1156. {
  1157. iSEM.CmdFIBLoadELY(@"E:\HOZ\MillStep4.ely");
  1158. }
  1159. private void btnFIBStatus_Click(object sender, EventArgs e)
  1160. {
  1161. btnFIBStatus.Text = iSEM.GetFIBApiStatus().ToString();
  1162. }
  1163. //测量线程测试
  1164. private void button1_Click(object sender, EventArgs e)
  1165. {
  1166. FormMeasureTest Measure = new FormMeasureTest();
  1167. Measure.Show();
  1168. }
  1169. }
  1170. }