FormUnitControl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. //时间:
  2. //作者:
  3. //功能:单元测试功能
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.IO;
  16. using SmartSEMControl;
  17. namespace HOZProject
  18. {
  19. public partial class FormUnitControl : Form
  20. {
  21. //全局只有一个fatorySEM
  22. static FactoryHardware factorySEM = FactoryHardware.Instance;
  23. ISEMControl iSEM = factorySEM.ISEM;
  24. #region 系统参数
  25. private String path = Directory.GetCurrentDirectory();
  26. #endregion
  27. #region 构造函数
  28. public FormUnitControl()
  29. {
  30. InitializeComponent();
  31. //Calling Notification for updated status
  32. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  33. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  34. //加载参数
  35. }
  36. #endregion
  37. #region 缩放Get
  38. private void btnenlargeGet_Click(object sender, EventArgs e)
  39. {
  40. float ret = iSEM.GetMagnification();
  41. if (float.IsNaN(ret))
  42. {
  43. lblenlargeGet.Text = "NaN";
  44. txtenlargeSet.Enabled = false;
  45. btnenlargeSet.Enabled = false;
  46. }
  47. else
  48. {
  49. lblenlargeGet.Text = ret.ToString();
  50. txtenlargeSet.Text = ret.ToString();
  51. btnenlargeSet.Enabled = true;
  52. }
  53. }
  54. #endregion
  55. #region 缩放Set
  56. private void btnenlargeSet_Click(object sender, EventArgs e)
  57. {
  58. float set = 0;
  59. if (float.TryParse(txtenlargeSet.Text, out set))
  60. {
  61. iSEM.SetMagnification(set);
  62. }
  63. }
  64. #endregion
  65. #region 焦距Get
  66. private void btnWDGet_Click(object sender, EventArgs e)
  67. {
  68. float ret = iSEM.GetWorkingDistance();
  69. if (float.IsNaN(ret))
  70. {
  71. lblWDGet.Text = "NaN";
  72. txtWDSet.Enabled = false;
  73. btnWDSet.Enabled = false;
  74. }
  75. else
  76. {
  77. lblWDGet.Text = ret.ToString();
  78. txtWDSet.Text = ret.ToString();
  79. btnWDSet.Enabled = true;
  80. }
  81. }
  82. #endregion
  83. #region 焦距Set
  84. private void btnWDSet_Click(object sender, EventArgs e)
  85. {
  86. float set = 0;
  87. if (float.TryParse(txtWDSet.Text, out set))
  88. {
  89. iSEM.SetWorkingDistance(set);
  90. }
  91. }
  92. #endregion
  93. #region 亮度Get
  94. private void btnBrightnessGet_Click(object sender, EventArgs e)
  95. {
  96. float ret = iSEM.GetBrightness();
  97. if (float.IsNaN(ret))
  98. {
  99. lblBrightnessGet.Text = "NaN";
  100. txtBrightnessSet.Enabled = false;
  101. btnBrightnessSet.Enabled = false;
  102. }
  103. else
  104. {
  105. lblBrightnessGet.Text = ret.ToString();
  106. txtBrightnessSet.Text = ret.ToString();
  107. btnBrightnessSet.Enabled = true;
  108. }
  109. }
  110. #endregion
  111. #region 亮度Set
  112. private void btnBrightnessSet_Click(object sender, EventArgs e)
  113. {
  114. float set = 0;
  115. if (float.TryParse(txtBrightnessSet.Text, out set))
  116. {
  117. iSEM.SetBrightness(set);
  118. }
  119. }
  120. #endregion
  121. #region 对比度Get
  122. private void btnContrastGet_Click(object sender, EventArgs e)
  123. {
  124. float ret = iSEM.GetContrast();
  125. if (float.IsNaN(ret))
  126. {
  127. lblContrastGet.Text = "NaN";
  128. txtContrastSet.Enabled = false;
  129. btnContrastSet.Enabled = false;
  130. }
  131. else
  132. {
  133. lblContrastGet.Text = ret.ToString();
  134. txtContrastSet.Text = ret.ToString();
  135. btnContrastSet.Enabled = true;
  136. }
  137. }
  138. #endregion
  139. #region 对比度Set
  140. private void btnContrastSet_Click(object sender, EventArgs e)
  141. {
  142. float set = 0;
  143. if (float.TryParse(txtContrastSet.Text, out set))
  144. {
  145. iSEM.SetContrast(set);
  146. }
  147. }
  148. #endregion
  149. #region 消像散X Get
  150. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  151. {
  152. float ret = iSEM.GetAstigmatismX();
  153. if (float.IsNaN(ret))
  154. {
  155. lblAstigmatismXGet.Text = "NaN";
  156. txtAstigmatismXSet.Enabled = false;
  157. btnAstigmatismXSet.Enabled = false;
  158. }
  159. else
  160. {
  161. lblAstigmatismXGet.Text = ret.ToString();
  162. txtAstigmatismXSet.Text = ret.ToString();
  163. btnAstigmatismXSet.Enabled = true;
  164. }
  165. }
  166. #endregion
  167. #region 消像散X Set
  168. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  169. {
  170. float set = 0;
  171. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  172. {
  173. iSEM.SetAstigmatismX(set);
  174. }
  175. }
  176. #endregion
  177. #region 消像散Y Get
  178. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  179. {
  180. float ret = iSEM.GetAstigmatismY();
  181. if (float.IsNaN(ret))
  182. {
  183. lblAstigmatismYGet.Text = "NaN";
  184. txtAstigmatismYSet.Enabled = false;
  185. btnAstigmatismYSet.Enabled = false;
  186. }
  187. else
  188. {
  189. lblAstigmatismYGet.Text = ret.ToString();
  190. txtAstigmatismYSet.Text = ret.ToString();
  191. btnAstigmatismYSet.Enabled = true;
  192. }
  193. }
  194. #endregion
  195. #region 消像散Y Set
  196. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  197. {
  198. float set = 0;
  199. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  200. {
  201. iSEM.SetAstigmatismY(set);
  202. }
  203. }
  204. #endregion
  205. #region 角度补偿Get
  206. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  207. {
  208. float ret = iSEM.GetTiltAngle();
  209. if (float.IsNaN(ret))
  210. {
  211. lblTiltAngleGet.Text = "NaN";
  212. txtTiltAngleSet.Enabled = false;
  213. btnTiltAngleSet.Enabled = false;
  214. }
  215. else
  216. {
  217. lblTiltAngleGet.Text = ret.ToString();
  218. txtTiltAngleSet.Text = ret.ToString();
  219. btnTiltAngleSet.Enabled = true;
  220. }
  221. }
  222. #endregion
  223. #region 角度补偿Set
  224. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  225. {
  226. float set = 0;
  227. if (float.TryParse(txtTiltAngleSet.Text, out set))
  228. {
  229. iSEM.SetTiltAngle(set);
  230. }
  231. }
  232. #endregion
  233. #region 抓取图像
  234. private void btnGrabImage_Click(object sender, EventArgs e)
  235. {
  236. SaveFileDialog sfd = new SaveFileDialog();
  237. sfd.Title = "图像保存位置:";
  238. sfd.FileName = "test.tif";
  239. sfd.Filter = "TIF文件|*.tif";
  240. if (sfd.ShowDialog() == DialogResult.OK)
  241. {
  242. string fn = sfd.FileName;
  243. iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
  244. }
  245. }
  246. #endregion
  247. #region ScanRotate Get
  248. private void btnScanRotationGet_Click(object sender, EventArgs e)
  249. {
  250. float ret = iSEM.GetScanRotation();
  251. if (float.IsNaN(ret))
  252. {
  253. lblScanRotationGet.Text = "NaN";
  254. txtScanRotationSet.Enabled = false;
  255. btnScanRotationSet.Enabled = false;
  256. }
  257. else
  258. {
  259. lblScanRotationGet.Text = ret.ToString();
  260. txtScanRotationSet.Text = ret.ToString();
  261. btnScanRotationSet.Enabled = true;
  262. }
  263. }
  264. #endregion
  265. #region ScanRotate Set
  266. private void btnScanRotationSet_Click(object sender, EventArgs e)
  267. {
  268. float set = 0;
  269. if (float.TryParse(txtScanRotationSet.Text, out set))
  270. {
  271. iSEM.SetScanRotation(set);
  272. }
  273. }
  274. #endregion
  275. #region PixelSize Get
  276. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  277. {
  278. float ret = iSEM.GetPixelSize();
  279. if (float.IsNaN(ret))
  280. {
  281. lblPixelSizeGet.Text = "NaN";
  282. }
  283. else
  284. {
  285. lblPixelSizeGet.Text = ret.ToString();
  286. }
  287. }
  288. #endregion
  289. #region 开启电压
  290. private void btnOpenVoltage_Click(object sender, EventArgs e)
  291. {
  292. iSEM.CmdOpenVoltage();
  293. }
  294. #endregion
  295. #region 关闭电压
  296. private void btnCloseVoltage_Click(object sender, EventArgs e)
  297. {
  298. iSEM.CmdCloseVoltage();
  299. }
  300. #endregion
  301. #region 样品台位置获取
  302. private void btnStageGetX_Click(object sender, EventArgs e)
  303. {
  304. float ret = iSEM.GetStageAtX();
  305. if (float.IsNaN(ret))
  306. {
  307. lblStageX.Text = "NaN";
  308. }
  309. else
  310. {
  311. lblStageX.Text = ret.ToString();
  312. }
  313. }
  314. private void btnStageGetY_Click(object sender, EventArgs e)
  315. {
  316. float ret = iSEM.GetStageAtY();
  317. if (float.IsNaN(ret))
  318. {
  319. lblStageY.Text = "NaN";
  320. }
  321. else
  322. {
  323. lblStageY.Text = ret.ToString();
  324. }
  325. }
  326. private void btnStageGetZ_Click(object sender, EventArgs e)
  327. {
  328. float ret = iSEM.GetStageAtZ();
  329. if (float.IsNaN(ret))
  330. {
  331. lblStageZ.Text = "NaN";
  332. }
  333. else
  334. {
  335. lblStageZ.Text = ret.ToString();
  336. }
  337. }
  338. private void btnStageGetT_Click(object sender, EventArgs e)
  339. {
  340. float ret = iSEM.GetStageAtT();
  341. if (float.IsNaN(ret))
  342. {
  343. lblStageT.Text = "NaN";
  344. }
  345. else
  346. {
  347. lblStageT.Text = ret.ToString();
  348. }
  349. }
  350. private void btnStageGetR_Click(object sender, EventArgs e)
  351. {
  352. float ret = iSEM.GetStageAtR();
  353. if (float.IsNaN(ret))
  354. {
  355. lblStageR.Text = "NaN";
  356. }
  357. else
  358. {
  359. lblStageR.Text = ret.ToString();
  360. }
  361. }
  362. private void btnStageGetM_Click(object sender, EventArgs e)
  363. {
  364. float ret = iSEM.GetStageAtM();
  365. if (float.IsNaN(ret))
  366. {
  367. lblStageM.Text = "NaN";
  368. }
  369. else
  370. {
  371. lblStageM.Text = ret.ToString();
  372. }
  373. }
  374. #endregion
  375. #region 样品台位置设置
  376. private void btnStageSetX_Click(object sender, EventArgs e)
  377. {
  378. float set = 0;
  379. if (float.TryParse(txtStageX.Text, out set))
  380. {
  381. iSEM.SetStageGotoX(set);
  382. }
  383. }
  384. private void btnStageSetY_Click(object sender, EventArgs e)
  385. {
  386. float set = 0;
  387. if (float.TryParse(txtStageY.Text, out set))
  388. {
  389. iSEM.SetStageGotoY(set);
  390. }
  391. }
  392. private void btnStageSetZ_Click(object sender, EventArgs e)
  393. {
  394. float set = 0;
  395. if (float.TryParse(txtStageZ.Text, out set))
  396. {
  397. iSEM.SetStageGotoZ(set);
  398. }
  399. }
  400. private void btnStageSetT_Click(object sender, EventArgs e)
  401. {
  402. float set = 0;
  403. if (float.TryParse(txtStageT.Text, out set))
  404. {
  405. iSEM.SetStageGotoT(set);
  406. }
  407. }
  408. private void btnStageSetR_Click(object sender, EventArgs e)
  409. {
  410. float set = 0;
  411. if (float.TryParse(txtStageR.Text, out set))
  412. {
  413. iSEM.SetStageGotoR(set);
  414. }
  415. }
  416. private void btnStageSetM_Click(object sender, EventArgs e)
  417. {
  418. float set = 0;
  419. if (float.TryParse(txtStageM.Text, out set))
  420. {
  421. iSEM.SetStageGotoM(set);
  422. }
  423. }
  424. #endregion
  425. #region 获取样品台位置数组
  426. private void btnGetStagePosition_Click(object sender, EventArgs e)
  427. {
  428. float[] pt = iSEM.GetStagePosition();
  429. if (!float.IsNaN(pt[0]))
  430. {
  431. lblStageX.Text = pt[0].ToString();
  432. }
  433. if (!float.IsNaN(pt[1]))
  434. {
  435. lblStageY.Text = pt[1].ToString();
  436. }
  437. if (!float.IsNaN(pt[2]))
  438. {
  439. lblStageZ.Text = pt[2].ToString();
  440. }
  441. if (!float.IsNaN(pt[3]))
  442. {
  443. lblStageT.Text = pt[3].ToString();
  444. }
  445. if (!float.IsNaN(pt[4]))
  446. {
  447. lblStageR.Text = pt[4].ToString();
  448. }
  449. if (!float.IsNaN(pt[5]))
  450. {
  451. lblStageM.Text = pt[5].ToString();
  452. }
  453. }
  454. #endregion
  455. private void btnDoSemDriftCorrn_Click(object sender, EventArgs e)
  456. {
  457. iSEM.SetTiltCorrectionOff();
  458. }
  459. private void button1_Click(object sender, EventArgs e)
  460. {
  461. iSEM.SetTiltCorrectionOn();
  462. }
  463. private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
  464. {
  465. if(iSEM!=null)
  466. {
  467. iSEM.Dispose();
  468. }
  469. }
  470. }
  471. }