FormUnitControl.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  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. //static FactoryHardware factorySEM = null;
  31. //ISEMControl iSEM = null;
  32. public XmlManager xmg = new XmlManager();
  33. private String path = Directory.GetCurrentDirectory();
  34. private int st_flag = 0;
  35. WebResult wr = new WebResult(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  36. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  37. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  38. String[] sT;
  39. String[] firms;
  40. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  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 = 2;
  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. float degree = 0;
  1184. int direction = 0;
  1185. int state = 0;
  1186. wr.Img_OffsetAngle_Direction(txtaddr.Text,Convert.ToInt32(txtTypee.Text),txtfirm.Text, 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. float offsetx1 = 0;
  1194. float offsety1 = 0;
  1195. float offsetx2 = 0;
  1196. float offsety2 = 0;
  1197. int state = 0;
  1198. wr.Img_Cut_Position(txtaddr.Text, Convert.ToInt32(txtTypee.Text), txtfirm.Text, out offsetx1, out offsety1, out offsetx2, out offsety2, out state);
  1199. lbllocationx1.Text = offsetx1.ToString("0.0");
  1200. lbllocationy1.Text = offsety1.ToString("0.0");
  1201. lbllocationx2.Text = offsetx2.ToString("0.0");
  1202. lbllocationy2.Text = offsety2.ToString("0.0");
  1203. lblstate2.Text = state.ToString();
  1204. }
  1205. private void btnPost3_Click(object sender, EventArgs e)
  1206. {
  1207. int state = 0;
  1208. wr.Img_Cut_Success(txtaddr.Text, txtaddr2.Text, out state);
  1209. lblstate3.Text = state.ToString();
  1210. }
  1211. private void btnPost4_Click(object sender, EventArgs e)
  1212. {
  1213. float offsetx = 0;
  1214. float offsety = 0;
  1215. int state = 0;
  1216. wr.Img_Trapezoid_Top_Center_Position(txtaddr.Text, out offsetx, out offsety, out state);
  1217. lbltopcx.Text = offsetx.ToString("0.0");
  1218. lbltopcy.Text = offsety.ToString("0.0");
  1219. lblstate4.Text = state.ToString();
  1220. }
  1221. private void btnPost5_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. lblfocuspath.Text = wr.Img_Auto_Focus(filenames);
  1228. }
  1229. private void btnPost6_Click(object sender, EventArgs e)
  1230. {
  1231. List<string> filenames = new List<string>();
  1232. filenames.Add("1111111");
  1233. filenames.Add("2222222");
  1234. filenames.Add("3333333");
  1235. lblstigpath.Text = wr.Img_Auto_Focus(filenames);
  1236. }
  1237. private void btnPost7_Click(object sender, EventArgs e)
  1238. {
  1239. float degree = 0;
  1240. int direction = 0;
  1241. int state = 0;
  1242. wr.Img_Center_Position_OffsetAngle_Direction(txtaddr.Text, out degree, out direction, out state);
  1243. //lblcenterx.Text = offsetx.ToString("0.0");
  1244. //lblcentery.Text = offsety.ToString("0.0");
  1245. lbldegree2.Text = degree.ToString();
  1246. lbldirection2.Text = direction.ToString();
  1247. lblstate5.Text = state.ToString();
  1248. }
  1249. private void btnPost8_Click(object sender, EventArgs e)
  1250. {
  1251. int state = 0;
  1252. wr.Img_Measure_Size(txtaddr.Text, 1000, (float)0.005, out state);
  1253. lblstate6.Text = state.ToString();
  1254. }
  1255. private void btnScanRotationSetLock_Click(object sender, EventArgs e)
  1256. {
  1257. iSEM.SetScanRotationOff();
  1258. }
  1259. private void button1_Click_1(object sender, EventArgs e)
  1260. {
  1261. iSEM.SetTiltAngleOff();
  1262. }
  1263. private void btnTiltAngleSetOn_Click(object sender, EventArgs e)
  1264. {
  1265. iSEM.SetTiltAngleOn();
  1266. }
  1267. private void btnScanRotationSetOn_Click(object sender, EventArgs e)
  1268. {
  1269. iSEM.SetScanRotationOn();
  1270. }
  1271. private void btnExeEly3_Click(object sender, EventArgs e)
  1272. {
  1273. iSEM.CmdFIBSTARTELY();
  1274. }
  1275. private void btnCreateConfig_Click(object sender, EventArgs e)
  1276. {
  1277. MeasureParam cfm = new MeasureParam();
  1278. cfm.Is_Photograph = chkWIsP.Checked;
  1279. cfm.PT = chkWPT.Checked;
  1280. cfm.PTTemp = txtWPTF.Text;
  1281. cfm.FIBTemp = txtWFIBF.Text;
  1282. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  1283. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  1284. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  1285. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  1286. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  1287. if(cbbWXZ.SelectedIndex==0)
  1288. {
  1289. cfm.Correction_Angle = 36;
  1290. }
  1291. else
  1292. {
  1293. cfm.Correction_Angle = 54;
  1294. }
  1295. cfm.SampleName = cbbWYP.Text;
  1296. cfm.Firm = cbbWCS.Text;
  1297. ConfigFile cf = new ConfigFile(cfm);
  1298. cf.Save(@"E:\test.cfg");
  1299. List<String> _sT = sT.ToList();
  1300. if(_sT.IndexOf(cbbWYP.Text)<0)
  1301. {
  1302. _sT.Add(cbbWYP.Text);
  1303. sT = _sT.ToArray();
  1304. string wsT = "";
  1305. for(int i=0;i<sT.Length;i++)
  1306. {
  1307. wsT += sT[i] + ",";
  1308. }
  1309. wsT = wsT.Substring(0, wsT.Length - 1);
  1310. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  1311. }
  1312. List<String> _firms = firms.ToList();
  1313. if (_firms.IndexOf(cbbWCS.Text) < 0)
  1314. {
  1315. _firms.Add(cbbWCS.Text);
  1316. firms = _firms.ToArray();
  1317. string wFirms = "";
  1318. for (int i = 0; i < firms.Length; i++)
  1319. {
  1320. wFirms += firms[i] + ",";
  1321. }
  1322. wFirms = wFirms.Substring(0, wFirms.Length - 1);
  1323. config.AppSettings.Settings["Firm"].Value = wFirms;
  1324. }
  1325. config.Save(ConfigurationSaveMode.Modified);
  1326. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  1327. reloadconfig();
  1328. }
  1329. private void btnReadConfig_Click(object sender, EventArgs e)
  1330. {
  1331. MeasureParam cfm = new MeasureParam();
  1332. ConfigFile cf = new ConfigFile(cfm);
  1333. cf.Read(@"E:\test.cfg");
  1334. chkRIsP.Checked = cfm.Is_Photograph;
  1335. chkRPT.Checked = cfm.PT;
  1336. txtRPTF.Text = cfm.PTTemp;
  1337. txtRFIBF.Text = cfm.FIBTemp;
  1338. txtRLZ.Text = cfm.Stretch_Magnification.ToString();
  1339. txtRQGF.Text = cfm.Location_Magnification.ToString();
  1340. txtRQGD.Text = cfm.Location_Voltage.ToString();
  1341. txtRPZF.Text = cfm.Photograph_Magnification.ToString();
  1342. txtRPZD.Text = cfm.Photograph_Voltage.ToString();
  1343. txtRXZ.Text = cfm.Correction_Angle.ToString();
  1344. txtRYP.Text = cfm.SampleName;
  1345. txtRCS.Text = cfm.Firm;
  1346. }
  1347. private void FormUnitControl_Load(object sender, EventArgs e)
  1348. {
  1349. reloadconfig();
  1350. cbbWYP.SelectedIndex = 0;
  1351. cbbWCS.SelectedIndex = 0;
  1352. cbbWXZ.SelectedIndex = 0;
  1353. this.chart1.Series[0].Points.Clear();
  1354. }
  1355. private void reloadconfig()
  1356. {
  1357. String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
  1358. String firm = ConfigurationManager.AppSettings["Firm"];
  1359. sT = sample_Type.Split(',');
  1360. cbbWYP.Items.Clear();
  1361. for (int i = 0; i < sT.Length; i++)
  1362. {
  1363. cbbWYP.Items.Add(sT[i]);
  1364. }
  1365. firms = firm.Split(',');
  1366. cbbWCS.Items.Clear();
  1367. for (int i = 0; i < firms.Length; i++)
  1368. {
  1369. cbbWCS.Items.Add(firms[i]);
  1370. }
  1371. }
  1372. private void btnPsFile_Click(object sender, EventArgs e)
  1373. {
  1374. OpenFileDialog sfd = new OpenFileDialog();
  1375. sfd.Title = "选择位置文件:";
  1376. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1377. sfd.Filter = "TXT文件|*.TXT";
  1378. if (sfd.ShowDialog() == DialogResult.OK)
  1379. {
  1380. //Console.WriteLine(sfd.FileName);
  1381. StreamReader sr = new StreamReader(sfd.FileName, Encoding.Default);
  1382. String line = "";
  1383. sr.ReadLine();
  1384. sr.ReadLine();
  1385. sr.ReadLine();
  1386. sr.ReadLine();
  1387. line = sr.ReadLine();
  1388. sr.Close();
  1389. sr.Dispose();
  1390. String[] lines = line.Split(',');
  1391. double x = Convert.ToDouble(lines[1]);
  1392. double y = Convert.ToDouble(lines[2]);
  1393. chart1.Series[0].Points.AddXY(x, y);
  1394. chart1.Series[0].Points[0].Label = x.ToString("0.000") + "," + y.ToString("0.000");
  1395. }
  1396. }
  1397. private void btnrect_Click(object sender, EventArgs e)
  1398. {
  1399. this.chart1.Series[0].Points.Clear();
  1400. List<double> xpoints = new List<double>();
  1401. List<double> ypoints = new List<double>();
  1402. //排列数
  1403. int rag = Convert.ToInt32(txtarray.Text);
  1404. //间距
  1405. float dist = Convert.ToSingle(txtdistance.Text);
  1406. //中心点x,y轴坐标
  1407. float cx = Convert.ToSingle(txtx.Text);
  1408. float cy = Convert.ToSingle(txty.Text);
  1409. //所有点集合
  1410. List<PointF> ptfs = new List<PointF>();
  1411. ptfs = AnalysisPosition(cx, cy, Convert.ToSingle(txtsample1x.Text),
  1412. Convert.ToSingle(txtsample1y.Text), dist, rag);
  1413. for(int i=0;i<ptfs.Count;i++)
  1414. {
  1415. chart1.Series[0].Points.AddXY(ptfs[i].X, ptfs[i].Y);
  1416. chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = ptfs[i].X.ToString("0.000") + "," + ptfs[i].Y.ToString("0.000");
  1417. }
  1418. ////求样品1的水平角度
  1419. //double angle = 0;
  1420. ////xpoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1421. ////ypoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1422. //xpoints.Add(Convert.ToDouble(txtsample1x.Text));
  1423. //ypoints.Add(Convert.ToDouble(txtsample1y.Text));
  1424. ////计算第一个点与X轴的交角度数
  1425. //angle = Math.Atan2(ypoints[0] - cy, cx - xpoints[0]) * 180 / Math.PI;
  1426. //lblPs1.Text = angle.ToString("0.0");
  1427. ////这里是求与第一个点横向排列的其他点的移动角度
  1428. ////就是按45度向左向右移动的度
  1429. //angle = 45 - angle;
  1430. //angle = angle * Math.PI / 180;
  1431. //txtsample1x.Text = xpoints[0].ToString("0.000");
  1432. //txtsample1y.Text = ypoints[0].ToString("0.000");
  1433. //chart1.Series[0].Points.AddXY(xpoints[0], ypoints[0]);
  1434. //chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[0].ToString("0.000") + "," + ypoints[0].ToString("0.000");
  1435. //double tx = 0;
  1436. //double ty = 0;
  1437. //for (int j = 0; j < rag; j++)
  1438. //{
  1439. // //计算每行第一个点的坐标
  1440. // if(j>0)
  1441. // {
  1442. // tx = dist * j * Math.Sin(angle);
  1443. // ty = dist * j * Math.Cos(angle);
  1444. // xpoints.Add(tx + xpoints[0]);
  1445. // ypoints.Add(ypoints[0] - ty);
  1446. // chart1.Series[0].Points.AddXY(xpoints[xpoints.Count-1], ypoints[ypoints.Count-1]);
  1447. // 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");
  1448. // }
  1449. // //计算每行其他点的坐标
  1450. // for (int i = 1; i < rag; i++)
  1451. // {
  1452. // tx = dist * i * Math.Cos(angle);
  1453. // ty = dist * i * Math.Sin(angle);
  1454. // xpoints.Add(tx + xpoints[j * rag]);
  1455. // ypoints.Add(ty + ypoints[j * rag]);
  1456. // chart1.Series[0].Points.AddXY(xpoints[xpoints.Count - 1], ypoints[ypoints.Count - 1]);
  1457. // 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");
  1458. // }
  1459. //}
  1460. }
  1461. /// <summary>
  1462. /// 分析点坐标
  1463. /// </summary>
  1464. /// <param name="centerX">中心点X轴坐标</param>
  1465. /// <param name="centerY">中心点Y轴坐标</param>
  1466. /// <param name="firstX">第一个点X轴坐标</param>
  1467. /// <param name="firstY">第一个点Y轴坐标</param>
  1468. /// <param name="distance">点与点的距离</param>
  1469. /// <param name="rag">行、列数</param>
  1470. /// <param name="ptsx">计算生成所有X轴坐标</param>
  1471. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  1472. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  1473. {
  1474. //求样品1的水平角度
  1475. double angle = 0;
  1476. //清空所有点信息
  1477. List<float> ptsx = new List<float>();
  1478. List<float> ptsy = new List<float>();
  1479. //将第一个点加入到点信息中
  1480. ptsx.Add(firstX);
  1481. ptsy.Add(firstY);
  1482. //计算第一个点与X轴的交角度数
  1483. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  1484. //这里是求与第一个点横向排列的其他点的移动角度
  1485. //就是按45度向左向右移动的度
  1486. angle = 45 - angle;
  1487. angle = angle * Math.PI / 180;
  1488. float tx = 0;
  1489. float ty = 0;
  1490. for (int j = 0; j < rag; j++)
  1491. {
  1492. //计算每行第一个点的坐标
  1493. if (j > 0)
  1494. {
  1495. tx = (float)(distance * j * Math.Sin(angle));
  1496. ty = (float)(distance * j * Math.Cos(angle));
  1497. ptsx.Add(tx + ptsx[0]);
  1498. ptsy.Add(ptsy[0] - ty);
  1499. }
  1500. //计算每行其他点的坐标
  1501. for (int i = 1; i < rag; i++)
  1502. {
  1503. tx = (float)(distance * i * Math.Cos(angle));
  1504. ty = (float)(distance * i * Math.Sin(angle));
  1505. ptsx.Add(tx + ptsx[j * rag]);
  1506. ptsy.Add(ty + ptsy[j * rag]);
  1507. }
  1508. }
  1509. List<PointF> pts = new List<PointF>();
  1510. for (int i = 0; i < ptsx.Count; i++)
  1511. {
  1512. //增加的点
  1513. PointF pf = new PointF();
  1514. pf.X = ptsx[i];
  1515. pf.Y = ptsy[i];
  1516. pts.Add(pf);
  1517. }
  1518. return pts;
  1519. }
  1520. private void btn30_Click(object sender, EventArgs e)
  1521. {
  1522. txtsample1x.Text = "21.7";
  1523. txtsample1y.Text = "90";
  1524. btnrect_Click(null, null);
  1525. }
  1526. private void btn45_Click(object sender, EventArgs e)
  1527. {
  1528. txtsample1x.Text = "29.65";
  1529. txtsample1y.Text = "100.35";
  1530. btnrect_Click(null, null);
  1531. }
  1532. private void btn60_Click(object sender, EventArgs e)
  1533. {
  1534. txtsample1x.Text = "40";
  1535. txtsample1y.Text = "108.3";
  1536. btnrect_Click(null, null);
  1537. }
  1538. private void button2_Click(object sender, EventArgs e)
  1539. {
  1540. float ret = iSEM.GetSEMVoltage();
  1541. if (float.IsNaN(ret))
  1542. {
  1543. txtVoltage.Text = "NaN";
  1544. txtVoltage.Enabled = false;
  1545. button2.Enabled = false;
  1546. }
  1547. else
  1548. {
  1549. txtVoltage.Text = ret.ToString();
  1550. button2.Enabled = true;
  1551. }
  1552. }
  1553. private void button1_Click(object sender, EventArgs e)
  1554. {
  1555. float set = 0;
  1556. if (float.TryParse(txtVoltage.Text, out set))
  1557. {
  1558. iSEM.SetSEMVoltage(set);
  1559. }
  1560. }
  1561. /// 图像拉直算法
  1562. /// </summary>
  1563. /// <param name="Slope">倾斜角度</param>
  1564. /// <param name="x0">圆心坐标x</param>
  1565. /// <param name="y0">圆心坐标y</param>
  1566. /// <param name="x1">倾斜情况下帧图的坐标x</param>
  1567. /// <param name="y1">倾斜情况下帧图的坐标y</param>
  1568. /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>
  1569. /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>
  1570. /// <returns></returns>
  1571. public bool Straightening(float Slope, float x0, float y0, float x1, float y1, ref float Hx, ref float Hy)
  1572. {
  1573. try
  1574. {
  1575. float xr = x1 - x0;//倾斜图到中心的距离差x
  1576. float yr = y1 - y0;//倾斜图到中心的距离差y
  1577. float R =(float)Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
  1578. //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
  1579. float k = (float)(Math.Atan(yr / xr) / Math.PI * 180);//x1,y1的直角三角形圆心角度
  1580. float k_S = k - Slope;//通过夹角差求x2,y2
  1581. //int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);
  1582. //int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);
  1583. float y2 = (float)(Math.Sin(Math.PI / (180 / k_S)) * R);
  1584. float x2 = (float)(Math.Cos(Math.PI / (180 / k_S)) * R);
  1585. if (Slope > 0 || Slope < 0)
  1586. {
  1587. Hx = x0 + x2;
  1588. Hy = y0 + y2;
  1589. }
  1590. else
  1591. {
  1592. Hx = 0;
  1593. Hy = 0;
  1594. }
  1595. return true;
  1596. }
  1597. catch (Exception)
  1598. {
  1599. return false;
  1600. }
  1601. }
  1602. private void button3_Click(object sender, EventArgs e)
  1603. {
  1604. float x1 = 0, y1 = 0;
  1605. Straightening(45, 48.156f, 49.968f, (float)31.679, (float)58.870, ref x1, ref y1);
  1606. button3.Text = x1.ToString("0.00") + "\n" + y1.ToString("0.00");
  1607. }
  1608. private void btntest_Click(object sender, EventArgs e)
  1609. {
  1610. //FileStream fs = new FileStream(txtaddr.Text, FileMode.Create, FileAccess.Write);
  1611. //StreamWriter sw = new StreamWriter(fs);
  1612. //sw.WriteLine("aaaa");
  1613. //sw.Close();
  1614. //sw.Dispose();
  1615. //fs.Close();
  1616. //fs.Dispose();
  1617. File.Copy(txtaddr2.Text, txtaddr.Text, true);
  1618. }
  1619. private void button4_Click(object sender, EventArgs e)
  1620. {
  1621. iSEM.SetWorkingDistance(0.006f);
  1622. Thread.Sleep(8000);
  1623. iSEM.GrabImage("D:\\HOZ1.0\\6.tif", 0, 0, 1024, 768, 0);
  1624. Thread.Sleep(3000);
  1625. iSEM.SetWorkingDistance(0.007f);
  1626. Thread.Sleep(8000);
  1627. iSEM.GrabImage("D:\\HOZ1.0\\7.tif", 0, 0, 1024, 768, 0);
  1628. Thread.Sleep(3000);
  1629. iSEM.SetWorkingDistance(0.0073f);
  1630. Thread.Sleep(8000);
  1631. iSEM.GrabImage("D:\\HOZ1.0\\73.tif", 0, 0, 1024, 768, 0);
  1632. Thread.Sleep(3000);
  1633. }
  1634. //移动到像素位置
  1635. bool MoveToPix(float sx,float sy,float xc, float yc,float ps,out float nx,out float ny)
  1636. {
  1637. int width = 1024/2;
  1638. int height = 768/2;
  1639. float deltX = (xc - (float)width) * ps;
  1640. float deltY = (yc - (float)height) * ps;
  1641. float xpCur = sx;
  1642. float ypCur = sy;
  1643. float xpNew = xpCur - deltX;
  1644. float ypNew = ypCur - deltY;
  1645. nx = xpNew;
  1646. ny = ypNew;
  1647. //if (deltX > 10)//使用移动样品台实现
  1648. //{
  1649. // if (!iSEM.SetStageGotoX(xpNew))
  1650. // {
  1651. // return false;
  1652. // }
  1653. // //判断是否移动完成
  1654. // while (true)
  1655. // {
  1656. // Thread.Sleep(5000);
  1657. // if (iSEM.GetStageIs() == 0)
  1658. // {
  1659. // break;
  1660. // }
  1661. // }
  1662. // //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  1663. // //arg.State = true;
  1664. // //SendMsg("1-7");
  1665. //}
  1666. //else//使用移动光束实现
  1667. //{
  1668. // float beamX = deltX * (float)0.66;
  1669. // if (!iSEM.SetBeamShiftX(beamX))
  1670. // {
  1671. // return false;
  1672. // }
  1673. //}
  1674. //if (deltY > 10)//使用移动样品台实现
  1675. //{
  1676. // if (!iSEM.SetStageGotoY(ypNew))
  1677. // {
  1678. // return false;
  1679. // }
  1680. // //判断是否移动完成
  1681. // while (true)
  1682. // {
  1683. // Thread.Sleep(5000);
  1684. // if (iSEM.GetStageIs() == 0)
  1685. // {
  1686. // break;
  1687. // }
  1688. // }
  1689. //}
  1690. //else//使用移动光束实现
  1691. //{
  1692. // float beamY = deltY * (float)0.671;
  1693. // if (!iSEM.SetBeamShiftY(beamY))
  1694. // {
  1695. // return false;
  1696. // }
  1697. //}
  1698. return true;
  1699. }
  1700. private void btnimgv_Click(object sender, EventArgs e)
  1701. {
  1702. float sx = 0, sy = 0;
  1703. float x1 = 0, y1 = 0;
  1704. float nx = 0, ny = 0;
  1705. float ps = 0;
  1706. sx = Convert.ToSingle(txtstagenx.Text);
  1707. sy = Convert.ToSingle(txtstageny.Text);
  1708. x1 = Convert.ToSingle(txtimgx.Text);
  1709. y1 = Convert.ToSingle(txtimgy.Text);
  1710. ps = Convert.ToSingle(txtps.Text);
  1711. MoveToPix(sx,sy,x1, y1, ps,out nx,out ny);
  1712. txtstagevx.Text = nx.ToString("0.000000");
  1713. txtstagevy.Text = ny.ToString("0.000000");
  1714. }
  1715. }
  1716. }