FormUnitControl.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  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. using MeasureThread;
  23. namespace HOZProject
  24. {
  25. public partial class FormUnitControl : Form
  26. {
  27. #region 系统参数
  28. //全局只有一个fatorySEM
  29. static FactoryHardware factorySEM = FactoryHardware.Instance;
  30. ISEMControl iSEM = factorySEM.ISEM;
  31. //static FactoryHardware factorySEM = null;
  32. //ISEMControl iSEM = null;
  33. public XmlManager xmg = new XmlManager();
  34. private String path = Directory.GetCurrentDirectory();
  35. private int st_flag = 0;
  36. ImageProcess wr = new ImageProcess(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  37. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  38. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  39. String[] sT;
  40. String[] firms;
  41. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  42. #endregion
  43. #region 构造函数
  44. public FormUnitControl()
  45. {
  46. InitializeComponent();
  47. Control.CheckForIllegalCrossThreadCalls = false;
  48. //if(iSEM.ConnectStatus())
  49. //{
  50. // float ret = iSEM.GetFIBIMAGING();
  51. // if(ret==0)
  52. // {
  53. // btnSEM.BackColor = Color.Lime;
  54. // }
  55. // else if(ret==1)
  56. // {
  57. // btnFIB.BackColor = Color.Lime;
  58. // panelFIB.Visible = true;
  59. // }
  60. // else if(ret==2)
  61. // {
  62. // btnMILL.BackColor = Color.Lime;
  63. // }
  64. //}
  65. ////Calling Notification for updated status
  66. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  67. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  68. //加载参数
  69. }
  70. #endregion
  71. #region 缩放Get
  72. private void btnenlargeGet_Click(object sender, EventArgs e)
  73. {
  74. float ret = iSEM.GetMagnification();
  75. if (float.IsNaN(ret))
  76. {
  77. txtenlargeSet.Text = "NaN";
  78. txtenlargeSet.Enabled = false;
  79. btnenlargeSet.Enabled = false;
  80. }
  81. else
  82. {
  83. txtenlargeSet.Text = ret.ToString();
  84. btnenlargeSet.Enabled = true;
  85. }
  86. }
  87. #endregion
  88. #region 缩放Set
  89. private void btnenlargeSet_Click(object sender, EventArgs e)
  90. {
  91. float set = 0;
  92. if (float.TryParse(txtenlargeSet.Text, out set))
  93. {
  94. iSEM.SetMagnification(set);
  95. }
  96. }
  97. #endregion
  98. #region 焦距Get
  99. private void btnWDGet_Click(object sender, EventArgs e)
  100. {
  101. float ret = iSEM.GetWorkingDistance();
  102. if (float.IsNaN(ret))
  103. {
  104. txtWDSet.Text = "NaN";
  105. txtWDSet.Enabled = false;
  106. btnWDSet.Enabled = false;
  107. }
  108. else
  109. {
  110. txtWDSet.Text = ret.ToString();
  111. btnWDSet.Enabled = true;
  112. }
  113. }
  114. #endregion
  115. #region 焦距Set
  116. private void btnWDSet_Click(object sender, EventArgs e)
  117. {
  118. float set = 0;
  119. if (float.TryParse(txtWDSet.Text, out set))
  120. {
  121. iSEM.SetWorkingDistance(set);
  122. }
  123. }
  124. #endregion
  125. #region 亮度Get
  126. private void btnBrightnessGet_Click(object sender, EventArgs e)
  127. {
  128. float ret = iSEM.GetBrightness();
  129. if (float.IsNaN(ret))
  130. {
  131. txtBrightnessSet.Text = "NaN";
  132. txtBrightnessSet.Enabled = false;
  133. btnBrightnessSet.Enabled = false;
  134. }
  135. else
  136. {
  137. txtBrightnessSet.Text = ret.ToString();
  138. btnBrightnessSet.Enabled = true;
  139. }
  140. }
  141. #endregion
  142. #region 亮度Set
  143. private void btnBrightnessSet_Click(object sender, EventArgs e)
  144. {
  145. float set = 0;
  146. if (float.TryParse(txtBrightnessSet.Text, out set))
  147. {
  148. iSEM.SetBrightness(set);
  149. }
  150. }
  151. #endregion
  152. #region 对比度Get
  153. private void btnContrastGet_Click(object sender, EventArgs e)
  154. {
  155. float ret = iSEM.GetContrast();
  156. if (float.IsNaN(ret))
  157. {
  158. txtContrastSet.Text = "NaN";
  159. txtContrastSet.Enabled = false;
  160. btnContrastSet.Enabled = false;
  161. }
  162. else
  163. {
  164. txtContrastSet.Text = ret.ToString();
  165. btnContrastSet.Enabled = true;
  166. }
  167. }
  168. #endregion
  169. #region 对比度Set
  170. private void btnContrastSet_Click(object sender, EventArgs e)
  171. {
  172. float set = 0;
  173. if (float.TryParse(txtContrastSet.Text, out set))
  174. {
  175. iSEM.SetContrast(set);
  176. }
  177. }
  178. #endregion
  179. #region 消像散X Get
  180. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  181. {
  182. float ret = iSEM.GetAstigmatismX();
  183. if (float.IsNaN(ret))
  184. {
  185. txtAstigmatismXSet.Text = "NaN";
  186. txtAstigmatismXSet.Enabled = false;
  187. btnAstigmatismXSet.Enabled = false;
  188. }
  189. else
  190. {
  191. txtAstigmatismXSet.Text = ret.ToString();
  192. btnAstigmatismXSet.Enabled = true;
  193. }
  194. }
  195. #endregion
  196. #region 消像散X Set
  197. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  198. {
  199. float set = 0;
  200. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  201. {
  202. iSEM.SetAstigmatismX(set);
  203. }
  204. }
  205. #endregion
  206. #region 消像散Y Get
  207. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  208. {
  209. float ret = iSEM.GetAstigmatismY();
  210. if (float.IsNaN(ret))
  211. {
  212. txtAstigmatismYSet.Text = "NaN";
  213. txtAstigmatismYSet.Enabled = false;
  214. btnAstigmatismYSet.Enabled = false;
  215. }
  216. else
  217. {
  218. txtAstigmatismYSet.Text = ret.ToString();
  219. btnAstigmatismYSet.Enabled = true;
  220. }
  221. }
  222. #endregion
  223. #region 消像散Y Set
  224. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  225. {
  226. float set = 0;
  227. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  228. {
  229. iSEM.SetAstigmatismY(set);
  230. }
  231. }
  232. #endregion
  233. #region 角度补偿Get
  234. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  235. {
  236. float ret = iSEM.GetTiltAngle();
  237. if (float.IsNaN(ret))
  238. {
  239. txtTiltAngleSet.Text = "NaN";
  240. txtTiltAngleSet.Enabled = false;
  241. btnTiltAngleSet.Enabled = false;
  242. }
  243. else
  244. {
  245. txtTiltAngleSet.Text = ret.ToString();
  246. btnTiltAngleSet.Enabled = true;
  247. }
  248. }
  249. #endregion
  250. #region 角度补偿Set
  251. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  252. {
  253. float set = 0;
  254. if (float.TryParse(txtTiltAngleSet.Text, out set))
  255. {
  256. //iSEM.SetTiltAngleOn();
  257. iSEM.SetTiltAngle(set);
  258. }
  259. }
  260. #endregion
  261. #region 抓取图像
  262. private void btnGrabImage_Click(object sender, EventArgs e)
  263. {
  264. SaveFileDialog sfd = new SaveFileDialog();
  265. sfd.Title = "图像保存位置:";
  266. sfd.FileName = "test.tif";
  267. sfd.Filter = "TIF文件|*.tif";
  268. if (sfd.ShowDialog() == DialogResult.OK)
  269. {
  270. string fn = sfd.FileName;
  271. iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
  272. }
  273. }
  274. #endregion
  275. #region ScanRotate Get
  276. private void btnScanRotationGet_Click(object sender, EventArgs e)
  277. {
  278. float ret = iSEM.GetScanRotation();
  279. if (float.IsNaN(ret))
  280. {
  281. txtScanRotationSet.Text = "NaN";
  282. txtScanRotationSet.Enabled = false;
  283. btnScanRotationSet.Enabled = false;
  284. }
  285. else
  286. {
  287. txtScanRotationSet.Text = ret.ToString();
  288. btnScanRotationSet.Enabled = true;
  289. }
  290. }
  291. #endregion
  292. #region ScanRotate Set
  293. private void btnScanRotationSet_Click(object sender, EventArgs e)
  294. {
  295. float set = 0;
  296. if (float.TryParse(txtScanRotationSet.Text, out set))
  297. {
  298. //iSEM.SetScanRotationOn();
  299. iSEM.SetScanRotation(set);
  300. }
  301. }
  302. #endregion
  303. #region PixelSize Get
  304. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  305. {
  306. float ret = iSEM.GetPixelSize();
  307. if (float.IsNaN(ret))
  308. {
  309. lblPixelSizeGet.Text = "NaN";
  310. }
  311. else
  312. {
  313. lblPixelSizeGet.Text = ret.ToString();
  314. }
  315. }
  316. #endregion
  317. #region 电子束
  318. private void btnTiltCorrXGet_Click(object sender, EventArgs e)
  319. {
  320. float ret = iSEM.GetBeamShiftX();
  321. if (float.IsNaN(ret))
  322. {
  323. txtTiltCorrX.Text = "NaN";
  324. txtTiltCorrX.Enabled = false;
  325. btnTiltCorrXSet.Enabled = false;
  326. }
  327. else
  328. {
  329. txtTiltCorrX.Text = ret.ToString();
  330. btnTiltCorrXSet.Enabled = true;
  331. }
  332. }
  333. private void btnTiltCorrXSet_Click(object sender, EventArgs e)
  334. {
  335. float set = 0;
  336. if (float.TryParse(txtTiltCorrX.Text, out set))
  337. {
  338. iSEM.SetBeamShiftX(set);
  339. }
  340. }
  341. private void btnTiltCorrYGet_Click(object sender, EventArgs e)
  342. {
  343. float ret = iSEM.GetBeamShiftY();
  344. if (float.IsNaN(ret))
  345. {
  346. txtTiltCorrY.Text = "NaN";
  347. txtTiltCorrY.Enabled = false;
  348. btnTiltCorrYSet.Enabled = false;
  349. }
  350. else
  351. {
  352. txtTiltCorrY.Text = ret.ToString();
  353. btnTiltCorrYSet.Enabled = true;
  354. }
  355. }
  356. private void btnTiltCorrYSet_Click(object sender, EventArgs e)
  357. {
  358. float set = 0;
  359. if (float.TryParse(txtTiltCorrY.Text, out set))
  360. {
  361. iSEM.SetBeamShiftY(set);
  362. }
  363. }
  364. #endregion
  365. #region 开启电压
  366. private void btnOpenVoltage_Click(object sender, EventArgs e)
  367. {
  368. iSEM.CmdOpenVoltage();
  369. }
  370. #endregion
  371. #region 关闭电压
  372. private void btnCloseVoltage_Click(object sender, EventArgs e)
  373. {
  374. iSEM.CmdCloseVoltage();
  375. }
  376. #endregion
  377. #region 电子束校正
  378. private void btnTiltCorr_Click(object sender, EventArgs e)
  379. {
  380. float ret = iSEM.GetTiltCorrection();
  381. if (float.IsNaN(ret))
  382. {
  383. btnTiltCorr.BackColor = Color.Red;
  384. }
  385. else
  386. {
  387. if(ret==0)
  388. {
  389. btnTiltCorr.BackColor = Color.Blue;
  390. iSEM.SetTiltCorrectionOn();
  391. btnTiltCorr.Text = "电子束状态:On";
  392. }
  393. else
  394. {
  395. btnTiltCorr.BackColor = Color.Lime;
  396. iSEM.SetTiltCorrectionOff();
  397. btnTiltCorr.Text = "电子束状态:Off";
  398. }
  399. }
  400. }
  401. #endregion
  402. #region 样品台位置获取
  403. private void btnStageGetX_Click(object sender, EventArgs e)
  404. {
  405. float ret = iSEM.GetStageAtX();
  406. if (float.IsNaN(ret))
  407. {
  408. lblStageX.Text = "NaN";
  409. }
  410. else
  411. {
  412. lblStageX.Text = ret.ToString();
  413. }
  414. }
  415. private void btnStageGetY_Click(object sender, EventArgs e)
  416. {
  417. float ret = iSEM.GetStageAtY();
  418. if (float.IsNaN(ret))
  419. {
  420. lblStageY.Text = "NaN";
  421. }
  422. else
  423. {
  424. lblStageY.Text = ret.ToString();
  425. }
  426. }
  427. private void btnStageGetZ_Click(object sender, EventArgs e)
  428. {
  429. float ret = iSEM.GetStageAtZ();
  430. if (float.IsNaN(ret))
  431. {
  432. lblStageZ.Text = "NaN";
  433. }
  434. else
  435. {
  436. lblStageZ.Text = ret.ToString();
  437. }
  438. }
  439. private void btnStageGetT_Click(object sender, EventArgs e)
  440. {
  441. float ret = iSEM.GetStageAtT();
  442. if (float.IsNaN(ret))
  443. {
  444. lblStageT.Text = "NaN";
  445. }
  446. else
  447. {
  448. lblStageT.Text = ret.ToString();
  449. }
  450. }
  451. private void btnStageGetR_Click(object sender, EventArgs e)
  452. {
  453. float ret = iSEM.GetStageAtR();
  454. if (float.IsNaN(ret))
  455. {
  456. lblStageR.Text = "NaN";
  457. }
  458. else
  459. {
  460. lblStageR.Text = ret.ToString();
  461. }
  462. }
  463. private void btnStageGetM_Click(object sender, EventArgs e)
  464. {
  465. float ret = iSEM.GetStageAtM();
  466. if (float.IsNaN(ret))
  467. {
  468. lblStageM.Text = "NaN";
  469. }
  470. else
  471. {
  472. lblStageM.Text = ret.ToString();
  473. }
  474. }
  475. #endregion
  476. #region 样品台位置设置
  477. private void btnStageSetX_Click(object sender, EventArgs e)
  478. {
  479. float set = 0;
  480. if (float.TryParse(txtStageX.Text, out set))
  481. {
  482. iSEM.SetStageGotoX(set);
  483. }
  484. }
  485. private void btnStageSetY_Click(object sender, EventArgs e)
  486. {
  487. float set = 0;
  488. if (float.TryParse(txtStageY.Text, out set))
  489. {
  490. iSEM.SetStageGotoY(set);
  491. }
  492. }
  493. private void btnStageSetZ_Click(object sender, EventArgs e)
  494. {
  495. float set = 0;
  496. if (float.TryParse(txtStageZ.Text, out set))
  497. {
  498. iSEM.SetStageGotoZ(set);
  499. }
  500. }
  501. private void btnStageSetT_Click(object sender, EventArgs e)
  502. {
  503. float set = 0;
  504. if (float.TryParse(txtStageT.Text, out set))
  505. {
  506. iSEM.SetStageGotoT(set);
  507. }
  508. }
  509. private void btnStageSetR_Click(object sender, EventArgs e)
  510. {
  511. float set = 0;
  512. if (float.TryParse(txtStageR.Text, out set))
  513. {
  514. iSEM.SetStageGotoR(set);
  515. }
  516. }
  517. private void btnStageSetM_Click(object sender, EventArgs e)
  518. {
  519. float set = 0;
  520. if (float.TryParse(txtStageM.Text, out set))
  521. {
  522. iSEM.SetStageGotoM(set);
  523. }
  524. }
  525. #endregion
  526. #region 获取样品台位置数组
  527. private void btnGetStagePosition_Click(object sender, EventArgs e)
  528. {
  529. float[] pt = iSEM.GetStagePosition();
  530. if (!float.IsNaN(pt[0]))
  531. {
  532. lblStageX.Text = pt[0].ToString();
  533. }
  534. if (!float.IsNaN(pt[1]))
  535. {
  536. lblStageY.Text = pt[1].ToString();
  537. }
  538. if (!float.IsNaN(pt[2]))
  539. {
  540. lblStageZ.Text = pt[2].ToString();
  541. }
  542. if (!float.IsNaN(pt[3]))
  543. {
  544. lblStageT.Text = pt[3].ToString();
  545. }
  546. if (!float.IsNaN(pt[4]))
  547. {
  548. lblStageR.Text = pt[4].ToString();
  549. }
  550. if (!float.IsNaN(pt[5]))
  551. {
  552. lblStageM.Text = pt[5].ToString();
  553. }
  554. }
  555. #endregion
  556. #region 窗体关闭
  557. private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
  558. {
  559. if(iSEM!=null)
  560. {
  561. iSEM.Dispose();
  562. }
  563. }
  564. #endregion
  565. #region 宏文件
  566. private void btnCMDMCF_Click(object sender, EventArgs e)
  567. {
  568. iSEM.CMDMCFFilename("OPTON");
  569. }
  570. #endregion
  571. #region 读取Xml文件
  572. private void btnReadXml_Click(object sender, EventArgs e)
  573. {
  574. MeasureFile mf = new MeasureFile();
  575. XmlDocument doc = new XmlDocument();
  576. doc.Load("test_opton.msf");//载入xml文件
  577. XmlNode root = doc.SelectSingleNode("XMLData");
  578. mf.Serialize(false, doc, root);
  579. doc.Save("test_opton.msf");
  580. }
  581. #endregion
  582. #region 写入Xml文件
  583. private void btnWriteXml_Click(object sender, EventArgs e)
  584. {
  585. MeasureFile mf = new MeasureFile();
  586. mf.FileName = path + "\\test_opton.msf";
  587. mf.FilePath = path;
  588. CutHole ch = new CutHole();
  589. //ch.OPT = Operation.Image;
  590. ch.START = System.DateTime.Now;
  591. ch.END = System.DateTime.Now.AddHours(2);
  592. ch.STATE = State.Success;
  593. ch.SWITCH = true;
  594. SemPosition sp = new SemPosition();
  595. sp.X = 11;
  596. sp.Y = 22;
  597. sp.Z = 33;
  598. sp.T = 44;
  599. sp.R = 55;
  600. sp.M = 66;
  601. ch.Position = sp;
  602. mf.ListCutHole.Add(ch);
  603. ch = new CutHole();
  604. //ch.OPT = Operation.Image;
  605. ch.START = System.DateTime.Now;
  606. ch.END = System.DateTime.Now.AddHours(2);
  607. ch.STATE = State.Success;
  608. ch.SWITCH = true;
  609. sp = new SemPosition();
  610. sp.X = 12;
  611. sp.Y = 34;
  612. sp.Z = 56;
  613. sp.T = 78;
  614. sp.R = 90;
  615. sp.M = 55;
  616. ch.Position = sp;
  617. mf.ListCutHole.Add(ch);
  618. MeasureParam md = new MeasureParam();
  619. md.SampleType = "aaaaaa";
  620. md.IfPT = true;
  621. md.RemotePTOriginalEly = "bbbbb";
  622. md.RemoteFIBOriginalEly = "cccc";
  623. //md.FocusMode = 2;
  624. mf.MParam = md;
  625. mf.New();
  626. //XmlDocument doc = new XmlDocument();
  627. //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
  628. //XmlNode root = doc.SelectSingleNode("XMLData");
  629. //mf.Serialize(true, doc, root);
  630. //doc.Save("test.aaa");
  631. }
  632. #endregion
  633. #region SEM模式
  634. private void btnSEM_Click(object sender, EventArgs e)
  635. {
  636. if(iSEM.CmdFIBModeSEM())
  637. {
  638. btnFIB.BackColor = SystemColors.Control;
  639. btnSEM.BackColor = Color.Lime;
  640. btnMILL.BackColor = SystemColors.Control;
  641. panelFIB.Visible = false;
  642. }
  643. }
  644. #endregion
  645. #region FIB模式
  646. private void btnFIB_Click(object sender, EventArgs e)
  647. {
  648. if(iSEM.CmdFIBModeFIB())
  649. {
  650. btnFIB.BackColor = Color.Lime;
  651. btnSEM.BackColor = SystemColors.Control;
  652. btnMILL.BackColor = SystemColors.Control;
  653. panelFIB.Visible = true;
  654. }
  655. }
  656. #endregion
  657. #region MILL模式
  658. private void btnMILL_Click(object sender, EventArgs e)
  659. {
  660. if(iSEM.CmdFIBModeMILL())
  661. {
  662. btnFIB.BackColor = SystemColors.Control;
  663. btnSEM.BackColor = SystemColors.Control;
  664. btnMILL.BackColor = Color.Lime;
  665. }
  666. }
  667. #endregion
  668. #region 自动对焦1
  669. private void btnAutoFocus1_Click(object sender, EventArgs e)
  670. {
  671. //抓图1
  672. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  673. if (File.Exists(path + "\\test1.tif"))
  674. {
  675. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  676. pictureBox1.Image = Image.FromStream(fileStream);
  677. fileStream.Close();
  678. fileStream.Dispose();
  679. }
  680. Thread.Sleep(1000);
  681. iSEM.CmdAutoFocusCoarse();
  682. btnAutoFocus1.BackColor = Color.Red;
  683. st_flag = 1;
  684. Thread.Sleep(1000);
  685. Thread thread = new Thread(AutoFunction);
  686. thread.Start();
  687. }
  688. #endregion
  689. #region 自动函数监测线程
  690. private void AutoFunction()
  691. {
  692. float ret = 111;
  693. Boolean state = false;
  694. while(true)
  695. {
  696. Thread.Sleep(1000);
  697. ret = iSEM.GetAutoFunction();
  698. if(ret==0)
  699. {
  700. if (st_flag == 1 && state == true)
  701. {
  702. btnAutoFocus1.BackColor = Color.Lime;
  703. Thread.Sleep(1000);
  704. //抓图1
  705. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  706. if (File.Exists(path + "\\test2.tif"))
  707. {
  708. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  709. pictureBox2.Image = Image.FromStream(fileStream);
  710. fileStream.Close();
  711. fileStream.Dispose();
  712. }
  713. break;
  714. }
  715. else if(st_flag==2 && state)
  716. {
  717. btnAutoFocus2.BackColor = Color.Lime;
  718. Thread.Sleep(1000);
  719. //抓图1
  720. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  721. if (File.Exists(path + "\\test2.tif"))
  722. {
  723. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  724. pictureBox2.Image = Image.FromStream(fileStream);
  725. fileStream.Close();
  726. fileStream.Dispose();
  727. }
  728. break;
  729. }
  730. else if (st_flag == 3)
  731. {
  732. btnAutoBrightness.BackColor = Color.Lime;
  733. Thread.Sleep(1000);
  734. //抓图1
  735. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  736. if (File.Exists(path + "\\test2.tif"))
  737. {
  738. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  739. pictureBox2.Image = Image.FromStream(fileStream);
  740. fileStream.Close();
  741. fileStream.Dispose();
  742. }
  743. break;
  744. }
  745. else if (st_flag == 4)
  746. {
  747. btnAutoContrast.BackColor = Color.Lime;
  748. Thread.Sleep(1000);
  749. //抓图1
  750. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  751. if (File.Exists(path + "\\test2.tif"))
  752. {
  753. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  754. pictureBox2.Image = Image.FromStream(fileStream);
  755. fileStream.Close();
  756. fileStream.Dispose();
  757. }
  758. break;
  759. }
  760. else if (st_flag == 5)
  761. {
  762. btnAutoBrightness.BackColor = Color.Lime;
  763. btnAutoContrast.BackColor = Color.Lime;
  764. btnAutoBC.BackColor = Color.Lime;
  765. Thread.Sleep(1000);
  766. //抓图1
  767. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  768. if (File.Exists(path + "\\test2.tif"))
  769. {
  770. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  771. pictureBox2.Image = Image.FromStream(fileStream);
  772. fileStream.Close();
  773. fileStream.Dispose();
  774. }
  775. break;
  776. }
  777. else if (st_flag == 6 && state)
  778. {
  779. btnAutoBCCancle.BackColor = Color.Lime;
  780. Thread.Sleep(1000);
  781. //抓图1
  782. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  783. if (File.Exists(path + "\\test2.tif"))
  784. {
  785. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  786. pictureBox2.Image = Image.FromStream(fileStream);
  787. fileStream.Close();
  788. fileStream.Dispose();
  789. }
  790. break;
  791. }
  792. else if (st_flag == 7 && state)
  793. {
  794. btnAutoStig.BackColor = Color.Lime;
  795. Thread.Sleep(1000);
  796. //抓图1
  797. iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  798. if (File.Exists(path + "\\test2.tif"))
  799. {
  800. FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  801. pictureBox2.Image = Image.FromStream(fileStream);
  802. fileStream.Close();
  803. fileStream.Dispose();
  804. }
  805. break;
  806. }
  807. ////抓图1
  808. //iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
  809. //if (File.Exists(path + "\\test2.tif"))
  810. //{
  811. // FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
  812. // pictureBox2.Image = Image.FromStream(fileStream);
  813. // fileStream.Close();
  814. // fileStream.Dispose();
  815. //}
  816. }
  817. else if(ret>0 && ret<12)
  818. {
  819. state = true;
  820. }
  821. }
  822. }
  823. #endregion
  824. #region 自动对焦2
  825. private void btnAutoFocus2_Click(object sender, EventArgs e)
  826. {
  827. //抓图1
  828. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  829. if (File.Exists(path + "\\test1.tif"))
  830. {
  831. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  832. pictureBox1.Image = Image.FromStream(fileStream);
  833. fileStream.Close();
  834. fileStream.Dispose();
  835. }
  836. Thread.Sleep(1000);
  837. iSEM.CmdAutoFocusFine();
  838. btnAutoFocus2.BackColor = Color.Red;
  839. st_flag = 2;
  840. Thread.Sleep(1000);
  841. Thread thread = new Thread(AutoFunction);
  842. thread.Start();
  843. }
  844. #endregion
  845. #region 自动亮度、对比度
  846. private void btnAutoBrightness_Click(object sender, EventArgs e)
  847. {
  848. //抓图1
  849. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  850. if (File.Exists(path + "\\test1.tif"))
  851. {
  852. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  853. pictureBox1.Image = Image.FromStream(fileStream);
  854. fileStream.Close();
  855. fileStream.Dispose();
  856. }
  857. Thread.Sleep(1000);
  858. iSEM.SetAutoVideoBrightness();
  859. btnAutoBrightness.BackColor = Color.Red;
  860. st_flag = 3;
  861. Thread.Sleep(1000);
  862. Thread thread = new Thread(AutoFunction);
  863. thread.Start();
  864. }
  865. private void btnAutoContrast_Click(object sender, EventArgs e)
  866. {
  867. //抓图1
  868. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  869. if (File.Exists(path + "\\test1.tif"))
  870. {
  871. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  872. pictureBox1.Image = Image.FromStream(fileStream);
  873. fileStream.Close();
  874. fileStream.Dispose();
  875. }
  876. Thread.Sleep(1000);
  877. iSEM.SetAutoVideoContrast();
  878. btnAutoContrast.BackColor = Color.Red;
  879. st_flag = 4;
  880. Thread.Sleep(1000);
  881. Thread thread = new Thread(AutoFunction);
  882. thread.Start();
  883. }
  884. private void btnAutoBC_Click(object sender, EventArgs e)
  885. {
  886. //抓图1
  887. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  888. if (File.Exists(path + "\\test1.tif"))
  889. {
  890. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  891. pictureBox1.Image = Image.FromStream(fileStream);
  892. fileStream.Close();
  893. fileStream.Dispose();
  894. }
  895. Thread.Sleep(1000);
  896. iSEM.SetAutoVideoBrightnessAndContrast();
  897. btnAutoBrightness.BackColor = Color.Red;
  898. btnAutoContrast.BackColor = Color.Red;
  899. btnAutoBC.BackColor = Color.Red;
  900. st_flag = 5;
  901. Thread.Sleep(1000);
  902. Thread thread = new Thread(AutoFunction);
  903. thread.Start();
  904. }
  905. private void btnAutoBCCancle_Click(object sender, EventArgs e)
  906. {
  907. iSEM.SetAutoVideoOff();
  908. btnAutoBCCancle.BackColor = Color.Red;
  909. st_flag = 6;
  910. Thread.Sleep(1000);
  911. Thread thread = new Thread(AutoFunction);
  912. thread.Start();
  913. }
  914. #endregion
  915. #region 自动消像散
  916. private void btnAutoStig_Click(object sender, EventArgs e)
  917. {
  918. //抓图1
  919. iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
  920. if (File.Exists(path + "\\test1.tif"))
  921. {
  922. FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
  923. pictureBox1.Image = Image.FromStream(fileStream);
  924. fileStream.Close();
  925. fileStream.Dispose();
  926. }
  927. Thread.Sleep(1000);
  928. iSEM.CmdAutoStig();
  929. btnAutoStig.BackColor = Color.Red;
  930. st_flag = 7;
  931. Thread.Sleep(1000);
  932. Thread thread = new Thread(AutoFunction);
  933. thread.Start();
  934. }
  935. #endregion
  936. #region FIB缩放Get
  937. private void btnFIBMagGet_Click(object sender, EventArgs e)
  938. {
  939. float ret = iSEM.GetFIBMagnification();
  940. if (float.IsNaN(ret))
  941. {
  942. txtFIBMag.Text = "NaN";
  943. txtFIBMag.Enabled = false;
  944. btnFIBMagSet.Enabled = false;
  945. }
  946. else
  947. {
  948. txtFIBMag.Text = ret.ToString();
  949. btnFIBMagSet.Enabled = true;
  950. }
  951. }
  952. #endregion
  953. #region FIB缩放Set
  954. private void btnFIBMagSet_Click(object sender, EventArgs e)
  955. {
  956. float set = 0;
  957. if (float.TryParse(txtFIBMag.Text, out set))
  958. {
  959. iSEM.SetFIBMagnification(set);
  960. }
  961. }
  962. #endregion
  963. #region FIB焦距Get
  964. private void btnFIBWDGet_Click(object sender, EventArgs e)
  965. {
  966. float ret = iSEM.GetFIBObjectivePotential();
  967. if (float.IsNaN(ret))
  968. {
  969. txtFIBWD.Text = "NaN";
  970. txtFIBWD.Enabled = false;
  971. btnFIBWDSet.Enabled = false;
  972. }
  973. else
  974. {
  975. txtFIBWD.Text = ret.ToString();
  976. btnFIBWDSet.Enabled = true;
  977. }
  978. }
  979. #endregion
  980. #region FIB焦距Set
  981. private void btnFIBWDSet_Click(object sender, EventArgs e)
  982. {
  983. float set = 0;
  984. if (float.TryParse(txtFIBWD.Text, out set))
  985. {
  986. iSEM.SetFIBObjectivePotential(set);
  987. }
  988. }
  989. #endregion
  990. #region FIB电子束移动
  991. private void btnFIBBeamShiftXGet_Click(object sender, EventArgs e)
  992. {
  993. float ret = iSEM.GetFIBBeamShiftX();
  994. if (float.IsNaN(ret))
  995. {
  996. txtFIBBeamShiftX.Text = "NaN";
  997. txtFIBBeamShiftX.Enabled = false;
  998. btnFIBBeamShiftXSet.Enabled = false;
  999. }
  1000. else
  1001. {
  1002. txtFIBBeamShiftX.Text = ret.ToString();
  1003. btnFIBBeamShiftXSet.Enabled = true;
  1004. }
  1005. }
  1006. private void btnFIBBeamShiftXSet_Click(object sender, EventArgs e)
  1007. {
  1008. float set = 0;
  1009. if (float.TryParse(txtFIBBeamShiftX.Text, out set))
  1010. {
  1011. iSEM.SetFIBBeamShiftX(set);
  1012. }
  1013. }
  1014. private void btnFIBBeamShiftYGet_Click(object sender, EventArgs e)
  1015. {
  1016. float ret = iSEM.GetFIBBeamShiftY();
  1017. if (float.IsNaN(ret))
  1018. {
  1019. txtFIBBeamShiftY.Text = "NaN";
  1020. txtFIBBeamShiftY.Enabled = false;
  1021. btnFIBBeamShiftYSet.Enabled = false;
  1022. }
  1023. else
  1024. {
  1025. txtFIBBeamShiftY.Text = ret.ToString();
  1026. btnFIBBeamShiftYSet.Enabled = true;
  1027. }
  1028. }
  1029. private void btnFIBBeamShiftYSet_Click(object sender, EventArgs e)
  1030. {
  1031. float set = 0;
  1032. if (float.TryParse(txtFIBBeamShiftY.Text, out set))
  1033. {
  1034. iSEM.SetFIBBeamShiftY(set);
  1035. }
  1036. }
  1037. #endregion
  1038. #region 执行宏文件
  1039. private void btnMCF_Click(object sender, EventArgs e)
  1040. {
  1041. OpenFileDialog sfd = new OpenFileDialog();
  1042. sfd.Title = "选择宏文件:";
  1043. sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1044. sfd.Filter = "MLF文件|*.MLF";
  1045. if (sfd.ShowDialog() == DialogResult.OK)
  1046. {
  1047. //string fn = Path.GetFileNameWithoutExtension(sfd.FileName).ToUpper();
  1048. iSEM.SetRemoteDesMLFPath(@"\\192.168.1.197\wq\");
  1049. iSEM.CMDMCFFilename(sfd.FileName);
  1050. }
  1051. }
  1052. #endregion
  1053. #region FIB消像散
  1054. private void btnFIBAstigmatismXGet_Click(object sender, EventArgs e)
  1055. {
  1056. float ret = iSEM.GetFIBAstigmatismX();
  1057. if (float.IsNaN(ret))
  1058. {
  1059. txtFIBAstigmatismX.Text = "NaN";
  1060. txtFIBAstigmatismX.Enabled = false;
  1061. btnFIBAstigmatismXSet.Enabled = false;
  1062. }
  1063. else
  1064. {
  1065. txtFIBAstigmatismX.Text = ret.ToString();
  1066. btnFIBAstigmatismXSet.Enabled = true;
  1067. }
  1068. }
  1069. private void btnFIBAstigmatismXSet_Click(object sender, EventArgs e)
  1070. {
  1071. float set = 0;
  1072. if (float.TryParse(txtFIBAstigmatismX.Text, out set))
  1073. {
  1074. iSEM.SetFIBAstigmatismX(set);
  1075. }
  1076. }
  1077. private void btnFIBAstigmatismYGet_Click(object sender, EventArgs e)
  1078. {
  1079. float ret = iSEM.GetFIBAstigmatismY();
  1080. if (float.IsNaN(ret))
  1081. {
  1082. txtFIBAstigmatismY.Text = "NaN";
  1083. txtFIBAstigmatismY.Enabled = false;
  1084. btnFIBAstigmatismYSet.Enabled = false;
  1085. }
  1086. else
  1087. {
  1088. txtFIBAstigmatismY.Text = ret.ToString();
  1089. btnFIBAstigmatismYSet.Enabled = true;
  1090. }
  1091. }
  1092. private void btnFIBAstigmatismYSet_Click(object sender, EventArgs e)
  1093. {
  1094. float set = 0;
  1095. if (float.TryParse(txtFIBAstigmatismY.Text, out set))
  1096. {
  1097. iSEM.SetFIBAstigmatismY(set);
  1098. }
  1099. }
  1100. #endregion
  1101. #region 移动样品台XY
  1102. private void btnMoveXY_Click(object sender, EventArgs e)
  1103. {
  1104. float setx = 0;
  1105. float sety = 0;
  1106. if (!float.TryParse(txtStageX.Text, out setx))
  1107. {
  1108. return;
  1109. }
  1110. if(!float.TryParse(txtStageY.Text,out sety))
  1111. {
  1112. return;
  1113. }
  1114. btnMoveXY.BackColor = Color.Red;
  1115. iSEM.MoveStageXY(setx, sety);
  1116. Thread.Sleep(500);
  1117. Thread th = new Thread(MoveStagexy);
  1118. th.Start();
  1119. }
  1120. private void MoveStagexy()
  1121. {
  1122. float ret = 111;
  1123. while(true)
  1124. {
  1125. ret = iSEM.GetStageIs();
  1126. if(ret==0)
  1127. {
  1128. btnMoveXY.BackColor = Color.Lime;
  1129. break;
  1130. }
  1131. }
  1132. }
  1133. #endregion
  1134. #region 获取分辨率
  1135. private void btnImageStoreGet_Click(object sender, EventArgs e)
  1136. {
  1137. int[] ret = iSEM.GetImageStore();
  1138. lblImageStore.Text = ret[0].ToString() + "*" + ret[1].ToString();
  1139. }
  1140. #endregion
  1141. #region 设置分辨率
  1142. private void btnImageStoreSet_Click(object sender, EventArgs e)
  1143. {
  1144. if (cmbImageStore.SelectedIndex > -1 && cmbImageStore.SelectedIndex < 12)
  1145. {
  1146. iSEM.SetImageStore(cmbImageStore.SelectedIndex);
  1147. }
  1148. }
  1149. #endregion
  1150. #region 样品台急停
  1151. private void btnAbort_Click(object sender, EventArgs e)
  1152. {
  1153. iSEM.CmdStageAbort();
  1154. }
  1155. #endregion
  1156. private void btnLive_Click(object sender, EventArgs e)
  1157. {
  1158. iSEM.ImageLive();
  1159. }
  1160. private void btnFrozen_Click(object sender, EventArgs e)
  1161. {
  1162. iSEM.ImageFrozen();
  1163. }
  1164. private void btnExeEly_Click(object sender, EventArgs e)
  1165. {
  1166. OpenFileDialog sfd = new OpenFileDialog();
  1167. sfd.Title = "选择ELY文件:";
  1168. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1169. sfd.Filter = "ELY文件|*.ELY";
  1170. if (sfd.ShowDialog() == DialogResult.OK)
  1171. {
  1172. iSEM.SetRemoteDesELYPath(@"\\192.168.1.197\wq\");
  1173. iSEM.CmdFIBLoadELY(sfd.FileName);
  1174. }
  1175. }
  1176. private void btnExeEly2_Click(object sender, EventArgs e)
  1177. {
  1178. iSEM.CmdFIBEXPOSUREELY();
  1179. }
  1180. private void btnFIBStatus_Click(object sender, EventArgs e)
  1181. {
  1182. btnFIBStatus.Text = iSEM.GetFIBMode().ToString();
  1183. }
  1184. private void btnPost1_Click(object sender, EventArgs e)
  1185. {
  1186. float degree = 0;
  1187. int direction = 0;
  1188. int state = 0;
  1189. wr.Img_OffsetAngle_Direction(txtaddr.Text,Convert.ToInt32(txtTypee.Text),txtfirm.Text, out degree, out direction, out state);
  1190. lbldegree1.Text = degree.ToString("0.0");
  1191. lbldirection1.Text = direction.ToString();
  1192. lblstate1.Text = state.ToString();
  1193. }
  1194. private void btnPost2_Click(object sender, EventArgs e)
  1195. {
  1196. float offsetx1 = 0;
  1197. float offsety1 = 0;
  1198. float offsetx2 = 0;
  1199. float offsety2 = 0;
  1200. int state = 0;
  1201. wr.Img_Cut_Position(txtaddr.Text, Convert.ToInt32(txtTypee.Text), txtfirm.Text, out offsetx1, out offsety1, out offsetx2, out offsety2, out state);
  1202. lbllocationx1.Text = offsetx1.ToString("0.0");
  1203. lbllocationy1.Text = offsety1.ToString("0.0");
  1204. lbllocationx2.Text = offsetx2.ToString("0.0");
  1205. lbllocationy2.Text = offsety2.ToString("0.0");
  1206. lblstate2.Text = state.ToString();
  1207. }
  1208. private void btnPost3_Click(object sender, EventArgs e)
  1209. {
  1210. int state = 0;
  1211. wr.Img_Cut_Success(txtaddr.Text, txtaddr2.Text, out state);
  1212. lblstate3.Text = state.ToString();
  1213. }
  1214. private void btnPost4_Click(object sender, EventArgs e)
  1215. {
  1216. float offsetx = 0;
  1217. float offsety = 0;
  1218. int state = 0;
  1219. //wr.Img_Trapezoid_Top_Center_Position(txtaddr.Text, out offsetx, out offsety, out state);
  1220. lbltopcx.Text = offsetx.ToString("0.0");
  1221. lbltopcy.Text = offsety.ToString("0.0");
  1222. lblstate4.Text = state.ToString();
  1223. }
  1224. private void btnPost5_Click(object sender, EventArgs e)
  1225. {
  1226. List<string> filenames = new List<string>();
  1227. filenames.Add("1111111");
  1228. filenames.Add("2222222");
  1229. filenames.Add("3333333");
  1230. lblfocuspath.Text = wr.Img_Auto_Focus(filenames);
  1231. }
  1232. private void btnPost6_Click(object sender, EventArgs e)
  1233. {
  1234. List<string> filenames = new List<string>();
  1235. filenames.Add("1111111");
  1236. filenames.Add("2222222");
  1237. filenames.Add("3333333");
  1238. lblstigpath.Text = wr.Img_Auto_Focus(filenames);
  1239. }
  1240. private void btnPost7_Click(object sender, EventArgs e)
  1241. {
  1242. float degree = 0;
  1243. int direction = 0;
  1244. int state = 0;
  1245. wr.Img_Center_Position_OffsetAngle_Direction(txtaddr.Text, Convert.ToInt32(txtTypee.Text), txtfirm.Text, out degree, out direction, out state);
  1246. //lblcenterx.Text = offsetx.ToString("0.0");
  1247. //lblcentery.Text = offsety.ToString("0.0");
  1248. lbldegree2.Text = degree.ToString();
  1249. lbldirection2.Text = direction.ToString();
  1250. lblstate7.Text = state.ToString();
  1251. }
  1252. private void btnPost9_Click(object sender, EventArgs e)
  1253. {
  1254. int state = 0;
  1255. wr.Img_Measure_Size(txtaddr.Text, txtaddr2.Text,0.000001f,0.000002f,"D:\\", Convert.ToInt32(txtTypee.Text), txtfirm.Text,out state);
  1256. lblstate9.Text = state.ToString();
  1257. }
  1258. private void btnScanRotationSetLock_Click(object sender, EventArgs e)
  1259. {
  1260. iSEM.SetScanRotationOff();
  1261. }
  1262. private void button1_Click_1(object sender, EventArgs e)
  1263. {
  1264. iSEM.SetTiltAngleOff();
  1265. }
  1266. private void btnTiltAngleSetOn_Click(object sender, EventArgs e)
  1267. {
  1268. iSEM.SetTiltAngleOn();
  1269. }
  1270. private void btnScanRotationSetOn_Click(object sender, EventArgs e)
  1271. {
  1272. iSEM.SetScanRotationOn();
  1273. }
  1274. private void btnExeEly3_Click(object sender, EventArgs e)
  1275. {
  1276. iSEM.CmdFIBSTARTELY();
  1277. }
  1278. private void btnCreateConfig_Click(object sender, EventArgs e)
  1279. {
  1280. MeasureParam cfm = new MeasureParam();
  1281. cfm.IsShotSectionToRun = chkWIsP.Checked;
  1282. cfm.IfPT = chkWPT.Checked;
  1283. cfm.RemotePTOriginalEly = txtWPTF.Text;
  1284. cfm.RemoteFIBOriginalEly = txtWFIBF.Text;
  1285. cfm.Straighten_Magnification = Convert.ToSingle(cbbWLZ.Text);
  1286. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  1287. cfm.Voltage = Convert.ToSingle(cbbWQGD.Text);
  1288. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  1289. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  1290. //if(cbbWXZ.SelectedIndex==0)
  1291. //{
  1292. // cfm.Correction_Angle = 36;
  1293. //}
  1294. //else
  1295. //{
  1296. // cfm.Correction_Angle = 54;
  1297. //}
  1298. cfm.SampleType = cbbWYP.Text;
  1299. cfm.Firm = cbbWCS.Text;
  1300. ConfigFile cf = new ConfigFile(cfm);
  1301. cf.Save(@"E:\test.cfg");
  1302. List<String> _sT = sT.ToList();
  1303. if(_sT.IndexOf(cbbWYP.Text)<0)
  1304. {
  1305. _sT.Add(cbbWYP.Text);
  1306. sT = _sT.ToArray();
  1307. string wsT = "";
  1308. for(int i=0;i<sT.Length;i++)
  1309. {
  1310. wsT += sT[i] + ",";
  1311. }
  1312. wsT = wsT.Substring(0, wsT.Length - 1);
  1313. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  1314. }
  1315. List<String> _firms = firms.ToList();
  1316. if (_firms.IndexOf(cbbWCS.Text) < 0)
  1317. {
  1318. _firms.Add(cbbWCS.Text);
  1319. firms = _firms.ToArray();
  1320. string wFirms = "";
  1321. for (int i = 0; i < firms.Length; i++)
  1322. {
  1323. wFirms += firms[i] + ",";
  1324. }
  1325. wFirms = wFirms.Substring(0, wFirms.Length - 1);
  1326. config.AppSettings.Settings["Firm"].Value = wFirms;
  1327. }
  1328. config.Save(ConfigurationSaveMode.Modified);
  1329. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  1330. reloadconfig();
  1331. }
  1332. private void btnReadConfig_Click(object sender, EventArgs e)
  1333. {
  1334. MeasureParam cfm = new MeasureParam();
  1335. ConfigFile cf = new ConfigFile(cfm);
  1336. cf.Read(@"E:\test.cfg");
  1337. chkRIsP.Checked = cfm.IsShotSectionToRun;
  1338. chkRPT.Checked = cfm.IfPT;
  1339. txtRPTF.Text = cfm.RemotePTOriginalEly;
  1340. txtRFIBF.Text = cfm.RemoteFIBOriginalEly;
  1341. txtRLZ.Text = cfm.Straighten_Magnification.ToString();
  1342. txtRQGF.Text = cfm.Location_Magnification.ToString();
  1343. txtRQGD.Text = cfm.Voltage.ToString();
  1344. txtRPZF.Text = cfm.Photograph_Magnification.ToString();
  1345. txtRPZD.Text = cfm.Photograph_Voltage.ToString();
  1346. //txtRXZ.Text = cfm.Correction_Angle.ToString();
  1347. txtRYP.Text = cfm.SampleType;
  1348. txtRCS.Text = cfm.Firm;
  1349. }
  1350. private void FormUnitControl_Load(object sender, EventArgs e)
  1351. {
  1352. reloadconfig();
  1353. cbbWYP.SelectedIndex = 0;
  1354. cbbWCS.SelectedIndex = 0;
  1355. cbbWXZ.SelectedIndex = 0;
  1356. this.chart1.Series[0].Points.Clear();
  1357. }
  1358. private void reloadconfig()
  1359. {
  1360. String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
  1361. String firm = ConfigurationManager.AppSettings["Firm"];
  1362. sT = sample_Type.Split(',');
  1363. cbbWYP.Items.Clear();
  1364. for (int i = 0; i < sT.Length; i++)
  1365. {
  1366. cbbWYP.Items.Add(sT[i]);
  1367. }
  1368. firms = firm.Split(',');
  1369. cbbWCS.Items.Clear();
  1370. for (int i = 0; i < firms.Length; i++)
  1371. {
  1372. cbbWCS.Items.Add(firms[i]);
  1373. }
  1374. }
  1375. private void btnPsFile_Click(object sender, EventArgs e)
  1376. {
  1377. OpenFileDialog sfd = new OpenFileDialog();
  1378. sfd.Title = "选择位置文件:";
  1379. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1380. sfd.Filter = "TXT文件|*.TXT";
  1381. if (sfd.ShowDialog() == DialogResult.OK)
  1382. {
  1383. //Console.WriteLine(sfd.FileName);
  1384. StreamReader sr = new StreamReader(sfd.FileName, Encoding.Default);
  1385. String line = "";
  1386. sr.ReadLine();
  1387. sr.ReadLine();
  1388. sr.ReadLine();
  1389. sr.ReadLine();
  1390. line = sr.ReadLine();
  1391. sr.Close();
  1392. sr.Dispose();
  1393. String[] lines = line.Split(',');
  1394. double x = Convert.ToDouble(lines[1]);
  1395. double y = Convert.ToDouble(lines[2]);
  1396. chart1.Series[0].Points.AddXY(x, y);
  1397. chart1.Series[0].Points[0].Label = x.ToString("0.000") + "," + y.ToString("0.000");
  1398. }
  1399. }
  1400. private void btnrect_Click(object sender, EventArgs e)
  1401. {
  1402. this.chart1.Series[0].Points.Clear();
  1403. List<double> xpoints = new List<double>();
  1404. List<double> ypoints = new List<double>();
  1405. //排列数
  1406. int rag = Convert.ToInt32(txtarray.Text);
  1407. //间距
  1408. float dist = Convert.ToSingle(txtdistance.Text);
  1409. //中心点x,y轴坐标
  1410. float cx = Convert.ToSingle(txtx.Text);
  1411. float cy = Convert.ToSingle(txty.Text);
  1412. //所有点集合
  1413. List<PointF> ptfs = new List<PointF>();
  1414. ptfs = AnalysisPosition(cx, cy, Convert.ToSingle(txtsample1x.Text),
  1415. Convert.ToSingle(txtsample1y.Text), dist, rag);
  1416. for(int i=0;i<ptfs.Count;i++)
  1417. {
  1418. chart1.Series[0].Points.AddXY(ptfs[i].X, ptfs[i].Y);
  1419. chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = ptfs[i].X.ToString("0.000") + "," + ptfs[i].Y.ToString("0.000");
  1420. }
  1421. ////求样品1的水平角度
  1422. //double angle = 0;
  1423. ////xpoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1424. ////ypoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
  1425. //xpoints.Add(Convert.ToDouble(txtsample1x.Text));
  1426. //ypoints.Add(Convert.ToDouble(txtsample1y.Text));
  1427. ////计算第一个点与X轴的交角度数
  1428. //angle = Math.Atan2(ypoints[0] - cy, cx - xpoints[0]) * 180 / Math.PI;
  1429. //lblPs1.Text = angle.ToString("0.0");
  1430. ////这里是求与第一个点横向排列的其他点的移动角度
  1431. ////就是按45度向左向右移动的度
  1432. //angle = 45 - angle;
  1433. //angle = angle * Math.PI / 180;
  1434. //txtsample1x.Text = xpoints[0].ToString("0.000");
  1435. //txtsample1y.Text = ypoints[0].ToString("0.000");
  1436. //chart1.Series[0].Points.AddXY(xpoints[0], ypoints[0]);
  1437. //chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[0].ToString("0.000") + "," + ypoints[0].ToString("0.000");
  1438. //double tx = 0;
  1439. //double ty = 0;
  1440. //for (int j = 0; j < rag; j++)
  1441. //{
  1442. // //计算每行第一个点的坐标
  1443. // if(j>0)
  1444. // {
  1445. // tx = dist * j * Math.Sin(angle);
  1446. // ty = dist * j * Math.Cos(angle);
  1447. // xpoints.Add(tx + xpoints[0]);
  1448. // ypoints.Add(ypoints[0] - ty);
  1449. // chart1.Series[0].Points.AddXY(xpoints[xpoints.Count-1], ypoints[ypoints.Count-1]);
  1450. // 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");
  1451. // }
  1452. // //计算每行其他点的坐标
  1453. // for (int i = 1; i < rag; i++)
  1454. // {
  1455. // tx = dist * i * Math.Cos(angle);
  1456. // ty = dist * i * Math.Sin(angle);
  1457. // xpoints.Add(tx + xpoints[j * rag]);
  1458. // ypoints.Add(ty + ypoints[j * rag]);
  1459. // chart1.Series[0].Points.AddXY(xpoints[xpoints.Count - 1], ypoints[ypoints.Count - 1]);
  1460. // 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");
  1461. // }
  1462. //}
  1463. }
  1464. /// <summary>
  1465. /// 分析点坐标
  1466. /// </summary>
  1467. /// <param name="centerX">中心点X轴坐标</param>
  1468. /// <param name="centerY">中心点Y轴坐标</param>
  1469. /// <param name="firstX">第一个点X轴坐标</param>
  1470. /// <param name="firstY">第一个点Y轴坐标</param>
  1471. /// <param name="distance">点与点的距离</param>
  1472. /// <param name="rag">行、列数</param>
  1473. /// <param name="ptsx">计算生成所有X轴坐标</param>
  1474. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  1475. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  1476. {
  1477. //求样品1的水平角度
  1478. double angle = 0;
  1479. //清空所有点信息
  1480. List<float> ptsx = new List<float>();
  1481. List<float> ptsy = new List<float>();
  1482. //将第一个点加入到点信息中
  1483. ptsx.Add(firstX);
  1484. ptsy.Add(firstY);
  1485. //计算第一个点与X轴的交角度数
  1486. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  1487. //这里是求与第一个点横向排列的其他点的移动角度
  1488. //就是按45度向左向右移动的度
  1489. angle = 45 - angle;
  1490. angle = angle * Math.PI / 180;
  1491. float tx = 0;
  1492. float ty = 0;
  1493. for (int j = 0; j < rag; j++)
  1494. {
  1495. //计算每行第一个点的坐标
  1496. if (j > 0)
  1497. {
  1498. tx = (float)(distance * j * Math.Sin(angle));
  1499. ty = (float)(distance * j * Math.Cos(angle));
  1500. ptsx.Add(tx + ptsx[0]);
  1501. ptsy.Add(ptsy[0] - ty);
  1502. }
  1503. //计算每行其他点的坐标
  1504. for (int i = 1; i < rag; i++)
  1505. {
  1506. tx = (float)(distance * i * Math.Cos(angle));
  1507. ty = (float)(distance * i * Math.Sin(angle));
  1508. ptsx.Add(tx + ptsx[j * rag]);
  1509. ptsy.Add(ty + ptsy[j * rag]);
  1510. }
  1511. }
  1512. List<PointF> pts = new List<PointF>();
  1513. for (int i = 0; i < ptsx.Count; i++)
  1514. {
  1515. //增加的点
  1516. PointF pf = new PointF();
  1517. pf.X = ptsx[i];
  1518. pf.Y = ptsy[i];
  1519. pts.Add(pf);
  1520. }
  1521. return pts;
  1522. }
  1523. private void btn30_Click(object sender, EventArgs e)
  1524. {
  1525. txtsample1x.Text = "21.7";
  1526. txtsample1y.Text = "90";
  1527. btnrect_Click(null, null);
  1528. }
  1529. private void btn45_Click(object sender, EventArgs e)
  1530. {
  1531. txtsample1x.Text = "29.65";
  1532. txtsample1y.Text = "100.35";
  1533. btnrect_Click(null, null);
  1534. }
  1535. private void btn60_Click(object sender, EventArgs e)
  1536. {
  1537. txtsample1x.Text = "40";
  1538. txtsample1y.Text = "108.3";
  1539. btnrect_Click(null, null);
  1540. }
  1541. private void button2_Click(object sender, EventArgs e)
  1542. {
  1543. float ret = iSEM.GetSEMVoltage();
  1544. if (float.IsNaN(ret))
  1545. {
  1546. txtVoltage.Text = "NaN";
  1547. txtVoltage.Enabled = false;
  1548. button2.Enabled = false;
  1549. }
  1550. else
  1551. {
  1552. txtVoltage.Text = ret.ToString();
  1553. button2.Enabled = true;
  1554. }
  1555. }
  1556. private void button1_Click(object sender, EventArgs e)
  1557. {
  1558. float set = 0;
  1559. if (float.TryParse(txtVoltage.Text, out set))
  1560. {
  1561. iSEM.SetSEMVoltage(set);
  1562. }
  1563. }
  1564. /// 图像拉直算法
  1565. /// </summary>
  1566. /// <param name="Slope">倾斜角度</param>
  1567. /// <param name="x0">圆心坐标x</param>
  1568. /// <param name="y0">圆心坐标y</param>
  1569. /// <param name="x1">倾斜情况下帧图的坐标x</param>
  1570. /// <param name="y1">倾斜情况下帧图的坐标y</param>
  1571. /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>
  1572. /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>
  1573. /// <returns></returns>
  1574. public bool Straightening(float Slope, float x0, float y0, float x1, float y1, ref float Hx, ref float Hy)
  1575. {
  1576. try
  1577. {
  1578. float xr = x1 - x0;//倾斜图到中心的距离差x
  1579. float yr = y1 - y0;//倾斜图到中心的距离差y
  1580. float R =(float)Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
  1581. //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
  1582. float k = (float)(Math.Atan(yr / xr) / Math.PI * 180);//x1,y1的直角三角形圆心角度
  1583. float k_S = k - Slope;//通过夹角差求x2,y2
  1584. //int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);
  1585. //int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);
  1586. float y2 = (float)(Math.Sin(Math.PI / (180 / k_S)) * R);
  1587. float x2 = (float)(Math.Cos(Math.PI / (180 / k_S)) * R);
  1588. if (Slope > 0 || Slope < 0)
  1589. {
  1590. Hx = x0 + x2;
  1591. Hy = y0 + y2;
  1592. }
  1593. else
  1594. {
  1595. Hx = 0;
  1596. Hy = 0;
  1597. }
  1598. return true;
  1599. }
  1600. catch (Exception)
  1601. {
  1602. return false;
  1603. }
  1604. }
  1605. private void button3_Click(object sender, EventArgs e)
  1606. {
  1607. float x1 = 0, y1 = 0;
  1608. Straightening(45, 48.156f, 49.968f, (float)31.679, (float)58.870, ref x1, ref y1);
  1609. button3.Text = x1.ToString("0.00") + "\n" + y1.ToString("0.00");
  1610. }
  1611. private void btntest_Click(object sender, EventArgs e)
  1612. {
  1613. //FileStream fs = new FileStream(txtaddr.Text, FileMode.Create, FileAccess.Write);
  1614. //StreamWriter sw = new StreamWriter(fs);
  1615. //sw.WriteLine("aaaa");
  1616. //sw.Close();
  1617. //sw.Dispose();
  1618. //fs.Close();
  1619. //fs.Dispose();
  1620. File.Copy(txtaddr2.Text, txtaddr.Text, true);
  1621. }
  1622. private void button4_Click(object sender, EventArgs e)
  1623. {
  1624. iSEM.SetWorkingDistance(0.006f);
  1625. Thread.Sleep(8000);
  1626. iSEM.GrabImage("D:\\HOZ1.0\\6.tif", 0, 0, 1024, 768, 0);
  1627. Thread.Sleep(3000);
  1628. iSEM.SetWorkingDistance(0.007f);
  1629. Thread.Sleep(8000);
  1630. iSEM.GrabImage("D:\\HOZ1.0\\7.tif", 0, 0, 1024, 768, 0);
  1631. Thread.Sleep(3000);
  1632. iSEM.SetWorkingDistance(0.0073f);
  1633. Thread.Sleep(8000);
  1634. iSEM.GrabImage("D:\\HOZ1.0\\73.tif", 0, 0, 1024, 768, 0);
  1635. Thread.Sleep(3000);
  1636. }
  1637. //移动到像素位置
  1638. bool MoveToPix(float sx,float sy,float xc, float yc,float ps,out float nx,out float ny)
  1639. {
  1640. int width = 1024/2;
  1641. int height = 768/2;
  1642. float deltX = (xc - (float)width) * ps;
  1643. float deltY = (yc - (float)height) * ps;
  1644. float xpCur = sx;
  1645. float ypCur = sy;
  1646. float xpNew = xpCur - deltX;
  1647. float ypNew = ypCur - deltY;
  1648. nx = xpNew;
  1649. ny = ypNew;
  1650. //if (deltX > 10)//使用移动样品台实现
  1651. //{
  1652. // if (!iSEM.SetStageGotoX(xpNew))
  1653. // {
  1654. // return false;
  1655. // }
  1656. // //判断是否移动完成
  1657. // while (true)
  1658. // {
  1659. // Thread.Sleep(5000);
  1660. // if (iSEM.GetStageIs() == 0)
  1661. // {
  1662. // break;
  1663. // }
  1664. // }
  1665. // //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  1666. // //arg.State = true;
  1667. // //SendMsg("1-7");
  1668. //}
  1669. //else//使用移动光束实现
  1670. //{
  1671. // float beamX = deltX * (float)0.66;
  1672. // if (!iSEM.SetBeamShiftX(beamX))
  1673. // {
  1674. // return false;
  1675. // }
  1676. //}
  1677. //if (deltY > 10)//使用移动样品台实现
  1678. //{
  1679. // if (!iSEM.SetStageGotoY(ypNew))
  1680. // {
  1681. // return false;
  1682. // }
  1683. // //判断是否移动完成
  1684. // while (true)
  1685. // {
  1686. // Thread.Sleep(5000);
  1687. // if (iSEM.GetStageIs() == 0)
  1688. // {
  1689. // break;
  1690. // }
  1691. // }
  1692. //}
  1693. //else//使用移动光束实现
  1694. //{
  1695. // float beamY = deltY * (float)0.671;
  1696. // if (!iSEM.SetBeamShiftY(beamY))
  1697. // {
  1698. // return false;
  1699. // }
  1700. //}
  1701. return true;
  1702. }
  1703. private void btnimgv_Click(object sender, EventArgs e)
  1704. {
  1705. float sx = 0, sy = 0;
  1706. float x1 = 0, y1 = 0;
  1707. float nx = 0, ny = 0;
  1708. float ps = 0;
  1709. sx = Convert.ToSingle(txtstagenx.Text);
  1710. sy = Convert.ToSingle(txtstageny.Text);
  1711. x1 = Convert.ToSingle(txtimgx.Text);
  1712. y1 = Convert.ToSingle(txtimgy.Text);
  1713. ps = Convert.ToSingle(txtps.Text);
  1714. MoveToPix(sx,sy,x1, y1, ps,out nx,out ny);
  1715. txtstagevx.Text = nx.ToString("0.000000");
  1716. txtstagevy.Text = ny.ToString("0.000000");
  1717. }
  1718. private void btnPost8_Click(object sender, EventArgs e)
  1719. {
  1720. System.Drawing.Point pt1, pt2, pt3;
  1721. float mag1 = 0, mag2 = 0;
  1722. int state = 0;
  1723. wr.Img_Two_Region_Position(txtaddr.Text, Convert.ToInt32(txtTypee.Text), txtfirm.Text, out pt1, out mag1, out pt2, out mag2, out pt3, out state);
  1724. if(state==1)
  1725. {
  1726. lblcenter1.Text = pt1.X.ToString() + "," + pt1.Y.ToString();
  1727. lblcenter2.Text = pt2.X.ToString() + "," + pt2.Y.ToString();
  1728. lblMag1.Text = mag1.ToString();
  1729. lblMag2.Text = mag2.ToString();
  1730. lblstate8.Text = state.ToString();
  1731. }
  1732. else
  1733. {
  1734. lblstate8.Text = "0";
  1735. lblcenter1.Text = "";
  1736. lblcenter2.Text = "";
  1737. lblMag1.Text = "";
  1738. lblMag2.Text = "";
  1739. }
  1740. }
  1741. private void button5_Click(object sender, EventArgs e)
  1742. {
  1743. XmlDocument xmlDoc = new XmlDocument();
  1744. xmlDoc.Load(@"E:\HOZ\test3.ely");//加载baixml文件,xmlpath 为XML文件的路径du
  1745. XmlNode xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/TRAPEZOID");
  1746. if (xns != null)
  1747. {
  1748. XmlAttributeCollection attributeCol = xns.Attributes;
  1749. //遍历自己点属性
  1750. foreach (XmlAttribute attri in attributeCol)
  1751. {
  1752. if (attri.Name == "x")
  1753. {
  1754. attri.InnerText = "123";
  1755. }
  1756. else if (attri.Name == "y")
  1757. {
  1758. attri.InnerText = "321";
  1759. }
  1760. ////获取每个节点属性的key,value值
  1761. //string name = attri.Name;
  1762. //string value = attri.Value;
  1763. //Console.WriteLine("{0}={1}", name, value);
  1764. }
  1765. }
  1766. xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/RECT");
  1767. if (xns != null)
  1768. {
  1769. XmlAttributeCollection attributeCol = xns.Attributes;
  1770. //遍历自己点属性
  1771. foreach (XmlAttribute attri in attributeCol)
  1772. {
  1773. if (attri.Name == "x")
  1774. {
  1775. attri.InnerText = "123";
  1776. }
  1777. else if (attri.Name == "y")
  1778. {
  1779. attri.InnerText = "323";
  1780. }
  1781. ////获取每个节点属性的key,value值
  1782. //string name = attri.Name;
  1783. //string value = attri.Value;
  1784. //Console.WriteLine("{0}={1}", name, value);
  1785. }
  1786. }
  1787. xmlDoc.Save(@"E:\HOZ\test3.ely");//保存的该XML文件,否则更新无效
  1788. xmlDoc = new XmlDocument();
  1789. xmlDoc.Load(@"E:\HOZ\test2.ely");//加载baixml文件,xmlpath 为XML文件的路径du
  1790. xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/RECT");
  1791. if (xns != null)
  1792. {
  1793. XmlAttributeCollection attributeCol = xns.Attributes;
  1794. //遍历自己点属性
  1795. foreach (XmlAttribute attri in attributeCol)
  1796. {
  1797. if (attri.Name == "x")
  1798. {
  1799. attri.InnerText = "123";
  1800. }
  1801. else if (attri.Name == "y")
  1802. {
  1803. attri.InnerText = "321";
  1804. }
  1805. ////获取每个节点属性的key,value值
  1806. //string name = attri.Name;
  1807. //string value = attri.Value;
  1808. //Console.WriteLine("{0}={1}", name, value);
  1809. }
  1810. }
  1811. xmlDoc.Save(@"E:\HOZ\test2.ely");//保存的该XML文件,否则更新无效
  1812. }
  1813. private void button6_Click(object sender, EventArgs e)
  1814. {
  1815. int x1, x2, y1, y2;
  1816. x1 = Convert.ToInt32(textBox1.Text);
  1817. y1 = Convert.ToInt32(textBox2.Text);
  1818. x2 = x1 - (1024 / 2);
  1819. y2 = (768 / 2) - y1;
  1820. button6.Text=x2.ToString() + "," + y2.ToString();
  1821. }
  1822. private void btnDRSet_Click(object sender, EventArgs e)
  1823. {
  1824. float set = 0;
  1825. if (float.TryParse(txtDRSet.Text, out set))
  1826. {
  1827. iSEM.SetStageDeltaR(set);
  1828. }
  1829. }
  1830. private void btnDeltaR_Click(object sender, EventArgs e)
  1831. {
  1832. float set = 0;
  1833. if (float.TryParse(txtDRSet.Text, out set))
  1834. {
  1835. iSEM.SetStageDeltaR(set);
  1836. }
  1837. }
  1838. private void button9_Click(object sender, EventArgs e)
  1839. {
  1840. OpenFileDialog sfd = new OpenFileDialog();
  1841. sfd.Title = "选择ELY文件:";
  1842. //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
  1843. sfd.Filter = "ELY文件|*.ELY";
  1844. if (sfd.ShowDialog() == DialogResult.OK)
  1845. {
  1846. double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1847. x1 = Convert.ToDouble(txtelyx.Text);
  1848. y1 = Convert.ToDouble(txtelyy.Text);
  1849. x2 = x1 - 512;
  1850. y2 = 384 - y1;
  1851. float px = iSEM.GetPixelSize();
  1852. XmlDocument xmlDoc = new XmlDocument();
  1853. xmlDoc.Load(sfd.FileName);//加载baixml文件,xmlpath 为XML文件的路径du
  1854. XmlNode xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/TRAPEZOID");
  1855. if (xns != null)
  1856. {
  1857. XmlAttributeCollection attributeCol = xns.Attributes;
  1858. //遍历自己点属性
  1859. foreach (XmlAttribute attri in attributeCol)
  1860. {
  1861. if (attri.Name == "x")
  1862. {
  1863. attri.InnerText = ((x2 * px) * 1000000).ToString();
  1864. }
  1865. else if (attri.Name == "y")
  1866. {
  1867. attri.InnerText = ((y2 * px) * 1000000).ToString();
  1868. }
  1869. ////获取每个节点属性的key,value值
  1870. //string name = attri.Name;
  1871. //string value = attri.Value;
  1872. //Console.WriteLine("{0}={1}", name, value);
  1873. }
  1874. }
  1875. xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/RECT");
  1876. if (xns != null)
  1877. {
  1878. XmlAttributeCollection attributeCol = xns.Attributes;
  1879. //遍历自己点属性
  1880. foreach (XmlAttribute attri in attributeCol)
  1881. {
  1882. if (attri.Name == "x")
  1883. {
  1884. attri.InnerText = ((x2 * px) * 1000000).ToString();
  1885. }
  1886. else if (attri.Name == "y")
  1887. {
  1888. attri.InnerText = ((y2 * px) * 1000000 + 2).ToString();
  1889. }
  1890. ////获取每个节点属性的key,value值
  1891. //string name = attri.Name;
  1892. //string value = attri.Value;
  1893. //Console.WriteLine("{0}={1}", name, value);
  1894. }
  1895. }
  1896. xmlDoc.Save(sfd.FileName);//保存的该XML文件,否则更新无效
  1897. iSEM.CmdFIBLoadELY(sfd.FileName);
  1898. }
  1899. }
  1900. //移动到像素位置
  1901. bool MoveToPix(float xc, float yc)
  1902. {
  1903. //单位是m/pix
  1904. float pixSize = iSEM.GetPixelSize();
  1905. LogManager.AddHardwareLog("像素尺寸=" + pixSize.ToString() + "m/pixel", true);
  1906. Thread.Sleep(500);
  1907. //0:width, 1:height
  1908. int[] imageSize = iSEM.GetImageStore();
  1909. int width = imageSize[0] / 2;
  1910. int height = imageSize[1] / 2;
  1911. LogManager.AddHardwareLog("目标像素是(" + xc.ToString() + "," + yc.ToString() + ")", true);
  1912. LogManager.AddHardwareLog("中心像素是(" + width.ToString() + "," + height.ToString() + ")", true);
  1913. float deltX = (xc - (float)width) * pixSize;
  1914. float deltY = (yc - (float)height) * pixSize;
  1915. LogManager.AddHardwareLog("x位移量 = " + deltX.ToString() + "m", true);
  1916. LogManager.AddHardwareLog("y位移量 = " + deltY.ToString() + "m", true);
  1917. float xpCur = iSEM.GetStageAtX();
  1918. float ypCur = iSEM.GetStageAtY();
  1919. LogManager.AddHardwareLog("当前位置(" + xpCur.ToString() + "," + ypCur.ToString() + "),单位m", true);
  1920. float xpNew = xpCur - deltX;
  1921. float ypNew = ypCur + deltY;
  1922. LogManager.AddHardwareLog("目标位置(" + xpNew.ToString() + "," + ypNew.ToString() + "),单位m", true);
  1923. //计算最大偏移量
  1924. float beamXCur = iSEM.GetBeamShiftX();//单位是%
  1925. iSEM.SetBeamShiftX(100);
  1926. float beamXMax = iSEM.GetBeamOffsetX();//单位是m
  1927. iSEM.SetBeamShiftX(beamXCur);
  1928. //计算光束偏移值:
  1929. float beamX = iSEM.GetBeamOffsetX();
  1930. LogManager.AddHardwareLog("当前X方向光束偏移量=" + beamX.ToString() + "m", true);
  1931. beamX = (-deltX + beamX);
  1932. LogManager.AddHardwareLog("X方向光束偏移量应为=" + beamX.ToString() + "m", true);
  1933. if (beamX < beamXMax || beamX < -beamXMax)
  1934. {
  1935. LogManager.AddHardwareLog("X方向移动光束", true);
  1936. float beamXShift = beamX * 100 / beamXMax;
  1937. if (!iSEM.SetBeamShiftX(beamXShift))
  1938. {
  1939. LogManager.AddHardwareLog("X方向光束偏移量" + beamX.ToString() + "m失败", true);
  1940. return false;
  1941. }
  1942. }
  1943. else if (deltX > 0.000003 || deltX < -0.000003)//大于3um使用移动样品台实现
  1944. {
  1945. LogManager.AddHardwareLog("X方向移动样品台", true);
  1946. if (!iSEM.SetStageGotoX(xpNew))
  1947. {
  1948. return false;
  1949. }
  1950. //判断是否移动完成
  1951. while (true)
  1952. {
  1953. Thread.Sleep(5000);
  1954. if (iSEM.GetStageIs() == 0)
  1955. {
  1956. break;
  1957. }
  1958. }
  1959. }
  1960. float beamY = iSEM.GetBeamOffsetY();
  1961. LogManager.AddHardwareLog("当前Y方向光束偏移量=" + beamY.ToString() + "m", true);
  1962. beamY = (-deltY + beamY);
  1963. LogManager.AddHardwareLog("Y方向光束偏移量应为=" + beamY.ToString() + "m", true);
  1964. //计算最大偏移量
  1965. float beamYCur = iSEM.GetBeamShiftY();//单位是%
  1966. iSEM.SetBeamShiftY(100);
  1967. float beamYMax = iSEM.GetBeamOffsetY();//单位是m
  1968. iSEM.SetBeamShiftY(beamYCur);
  1969. if (beamY < beamYMax || beamY < -beamYMax)
  1970. {
  1971. LogManager.AddHardwareLog("Y方向移动光束", true);
  1972. float beamYShift = beamY * 100 / beamYMax;
  1973. if (!iSEM.SetBeamShiftY(beamY))
  1974. {
  1975. LogManager.AddHardwareLog("Y方向光束偏移量" + beamY.ToString() + "m失败", true);
  1976. return false;
  1977. }
  1978. }
  1979. else if (deltY > 0.000003 || deltY < -0.000003)//大于3um使用移动样品台实现
  1980. {
  1981. LogManager.AddHardwareLog("Y方向移动样品台", true);
  1982. if (!iSEM.SetStageGotoY(ypNew))
  1983. {
  1984. return false;
  1985. }
  1986. //判断是否移动完成
  1987. while (true)
  1988. {
  1989. Thread.Sleep(5000);
  1990. if (iSEM.GetStageIs() == 0)
  1991. {
  1992. break;
  1993. }
  1994. }
  1995. //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  1996. //arg.State = true;
  1997. //SendMsg("1-7");
  1998. }
  1999. return true;
  2000. }
  2001. private void button10_Click(object sender, EventArgs e)
  2002. {
  2003. MoveToPix(Convert.ToSingle(txtTx.Text), Convert.ToSingle(txtTy.Text));
  2004. }
  2005. float cycle_time = 0;
  2006. private void button11_Click(object sender, EventArgs e)
  2007. {
  2008. iSEM.SetReduced(256, 192, 512, 512);
  2009. Thread.Sleep(100);
  2010. iSEM.CmdFocusRate(4);
  2011. Thread.Sleep(200);
  2012. cycle_time = iSEM.GetCycleTime();
  2013. Thread.Sleep(200 + Convert.ToInt32(cycle_time));
  2014. //放大到10000倍
  2015. iSEM.SetMagnification(10000);
  2016. Thread.Sleep(200 + Convert.ToInt32(cycle_time));
  2017. //自动亮度对比度
  2018. iSEM.SetAutoVideoBrightnessAndContrast();
  2019. Thread.Sleep(5000);
  2020. //自动对焦
  2021. if (Directory.Exists(txtFocus.Text))
  2022. {
  2023. Directory.Delete(txtFocus.Text, true);
  2024. }
  2025. Thread.Sleep(3000);
  2026. //再创建文件夹
  2027. Directory.CreateDirectory(txtFocus.Text);
  2028. //1、对焦参数类,2、输出工作距离
  2029. int wd = 0;
  2030. //20201015 根据当前的工作距离重新计算对焦位置
  2031. float currentWd = iSEM.GetWorkingDistance();//0.0154m =15.4mm = 15400um
  2032. MeasureFile m_measureFile = new MeasureFile();
  2033. //设置工作距离
  2034. iSEM.SetWorkingDistance((float)(wd * 0.00000001));
  2035. //设置完工作距离后必须延迟5秒
  2036. Thread.Sleep(2000);
  2037. //放大倍数5000
  2038. iSEM.SetMagnification(5000);
  2039. Thread.Sleep(200 + Convert.ToInt32(cycle_time));
  2040. //自动消像散
  2041. //if (!ImageStig1())
  2042. //{
  2043. // MessageBox.Show("消像散失败");
  2044. //}
  2045. //放大到10000倍
  2046. iSEM.SetMagnification(10000);
  2047. Thread.Sleep(200 + Convert.ToInt32(cycle_time));
  2048. //自动消像散
  2049. //if (!ImageStig1())
  2050. //{
  2051. // MessageBox.Show("消像散失败");
  2052. //}
  2053. //增亮图像
  2054. iSEM.SetAutoVideoOff();
  2055. Thread.Sleep(200);
  2056. float currentBright = iSEM.GetBrightness();
  2057. Thread.Sleep(200);
  2058. float currentContrast = iSEM.GetContrast();
  2059. Thread.Sleep(200);
  2060. iSEM.SetBrightness(currentBright + 1);
  2061. Thread.Sleep(500);
  2062. iSEM.SetContrast(currentContrast + 1);
  2063. Thread.Sleep(500);
  2064. iSEM.CloseReduced();
  2065. Thread.Sleep(200);
  2066. cycle_time = iSEM.GetCycleTime();
  2067. Thread.Sleep(200 + Convert.ToInt32(cycle_time));
  2068. }
  2069. private void button12_Click(object sender, EventArgs e)
  2070. {
  2071. ltPoints.Items.Clear();
  2072. List<Point> pts = new List<Point>();
  2073. int state = 0;
  2074. wr.EDS_Param_Points(txtPicPath.Text, 1, 0, "N-BOE", out pts, out state);
  2075. foreach(Point pt in pts)
  2076. {
  2077. ltPoints.Items.Add(pt.X.ToString() + "," + pt.Y.ToString());
  2078. }
  2079. button12.Text = pts.Count.ToString();
  2080. }
  2081. private void button13_Click(object sender, EventArgs e)
  2082. {
  2083. ltLines.Items.Clear();
  2084. List<Point> pts = new List<Point>();
  2085. int state = 0;
  2086. //wr.EDS_Param_Lines(txtPicPath.Text, 1, 0, "N-BOE", out pts, out state);
  2087. foreach (Point pt in pts)
  2088. {
  2089. ltLines.Items.Add(pt.X.ToString() + "," + pt.Y.ToString());
  2090. }
  2091. button13.Text = pts.Count.ToString();
  2092. }
  2093. private void button14_Click(object sender, EventArgs e)
  2094. {
  2095. Point pt = new Point();
  2096. int w = 0;
  2097. int h = 0;
  2098. int state = 0;
  2099. wr.EDS_Param_Areas(txtPicPath.Text, 1, 0, "N-BOE", out pt, out w, out h, out state);
  2100. lblEDSX.Text = pt.X.ToString();
  2101. lblEDSY.Text = pt.Y.ToString();
  2102. lblEDSW.Text = w.ToString();
  2103. lblEDSH.Text = h.ToString();
  2104. }
  2105. private void button15_Click(object sender, EventArgs e)
  2106. {
  2107. iSEM.SetReduced(256, 192, Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text));
  2108. }
  2109. }
  2110. }