SemTestForms.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.Xml;
  13. using OTSCLRINTERFACE;
  14. namespace OTSSysMgrApp
  15. {
  16. public partial class SemTestForms : Form
  17. {
  18. #region 全部变量声明
  19. //连接状态
  20. bool ConnectionState = false;
  21. // 判断是否是模拟状态 FASE: 不是在模拟环境下 True: 在模拟环境下
  22. //bool IsSimulationStatus = false;
  23. //获取当前电镜的ID号
  24. int SemType = 0;
  25. //获取XML 路径
  26. static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
  27. //日志路径
  28. //static string LogPath = System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ConnectionString;
  29. static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  30. //电镜设置对象
  31. OTSCLRINTERFACE.COTSControlFunExport cfun = null;
  32. //国际化
  33. OTSSysMgrTools.Language lan;
  34. //国际化存储信息
  35. Hashtable table;
  36. #endregion
  37. #region 构造方法
  38. public SemTestForms()
  39. {
  40. InitializeComponent();
  41. //控制类对象初始化
  42. cfun = COTSControlFunExport.GetControllerInstance();
  43. //国际化
  44. lan = new OTSSysMgrTools.Language(this);
  45. table = lan.GetNameTable(this.Name);
  46. }
  47. #endregion
  48. #region 保存设置
  49. /// <summary>
  50. /// 保存设置
  51. /// </summary>
  52. /// <param name="Name">节点名称</param>
  53. /// <param name="Value">节点参数值</param>
  54. public void SaveSetting(string Name, string Value)
  55. {
  56. try
  57. {
  58. //判断XML文件中是否存在
  59. if (!XMLOperationClass.ExistsXmlInfo(Name))
  60. {
  61. //调用添加XML节点功能
  62. XMLOperationClass.AddXmlInfo(Name, Value);
  63. }
  64. else
  65. {
  66. //调用修改XML节点功能
  67. XMLOperationClass.EditXmlInfo(Name, Value);
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. //记录日志信息
  73. log.Error(ex.Message.ToString());
  74. }
  75. }
  76. #endregion
  77. #region 修改设置
  78. public void EditSetting(string Name, string Value)
  79. {
  80. try
  81. {
  82. //调用修改XML节点功能
  83. XMLOperationClass.EditXmlInfo(Name, Value);
  84. }
  85. catch (Exception ex)
  86. {
  87. //记录日志信息
  88. log.Error(ex.Message.ToString());
  89. }
  90. }
  91. #endregion
  92. #region 判断文件路径
  93. /// <summary>
  94. /// 判断文件路径
  95. /// </summary>
  96. /// <param name="path"></param>
  97. /// <returns></returns>
  98. public bool CreateFile(string path)
  99. {
  100. Directory.CreateDirectory(path);
  101. return false;
  102. }
  103. #endregion
  104. #region 判断文件是否存在
  105. /// <summary>
  106. /// 判断文件是否存在
  107. /// </summary>
  108. /// <param name="path">文件路径</param>
  109. /// <returns></returns>
  110. public bool ExistsFile(string path)
  111. {
  112. try
  113. {
  114. if (File.Exists(path))
  115. {
  116. return true;
  117. }
  118. return false;
  119. }
  120. catch (Exception ex)
  121. {
  122. //记录日志信息
  123. log.Error(ex.Message.ToString());
  124. return false;
  125. }
  126. }
  127. #endregion
  128. public void GetBtnState(bool btnState)
  129. {
  130. //循环窗体中
  131. foreach (Control item in gbGetMethods.Controls)
  132. {
  133. if (item is Button)
  134. {
  135. //if(!(((Button)item).Name== "btnGLineTime"))
  136. //{
  137. ((Button)item).Enabled = btnState;
  138. //}
  139. }
  140. }
  141. foreach (Control item in gbSetMethods.Controls)
  142. {
  143. if (item is Button)
  144. {
  145. //if (!(((Button)item).Name == "btnGLineTime"))
  146. //{
  147. ((Button)item).Enabled = btnState;
  148. //}
  149. }
  150. }
  151. }
  152. #region 用户信息提示
  153. /// <summary>
  154. /// 提示
  155. /// </summary>
  156. /// <param name="Message"></param>
  157. private void ShowMessage(int MessageType)
  158. {
  159. string message1 = table["message1"].ToString();
  160. string message2 = table["message2"].ToString();
  161. string message3 = table["message3"].ToString();
  162. string message4 = table["message4"].ToString();
  163. string message5 = table["message5"].ToString();
  164. string message6 = table["message6"].ToString();
  165. string message7 = table["message7"].ToString();
  166. string message8 = table["message8"].ToString();
  167. string message9 = table["message9"].ToString();
  168. string message10 = table["message10"].ToString();
  169. string MessageInfo = string.Empty;
  170. switch (MessageType)
  171. {
  172. case 0:
  173. MessageInfo = message1;
  174. break;
  175. case 1:
  176. MessageInfo = message2;
  177. break;
  178. case 2:
  179. MessageInfo = message3;
  180. break;
  181. case 3:
  182. MessageInfo = message4;
  183. break;
  184. case 4:
  185. MessageInfo = message5;
  186. break;
  187. case 5:
  188. MessageInfo = message6;
  189. break;
  190. case 6:
  191. MessageInfo = message7;
  192. break;
  193. case 7:
  194. MessageInfo = message8;
  195. break;
  196. case 8:
  197. MessageInfo = message9;
  198. break;
  199. case 9:
  200. MessageInfo = message10;
  201. break;
  202. }
  203. MessageBox.Show(MessageInfo, "Tip");
  204. }
  205. #endregion
  206. #region 判断控制内容是否为空 与 判断输入的格式是否正确
  207. /// <summary>
  208. /// 判断控制内容是否为空
  209. /// </summary>
  210. /// <param name="tbContent"></param>
  211. /// <returns></returns>
  212. public bool IsNull(TextBox tbContent)
  213. {
  214. if (tbContent.Text.Trim().Equals(""))
  215. {
  216. //为空提示
  217. ShowMessage(0);
  218. //获取焦点
  219. tbContent.Focus();
  220. return false;
  221. }
  222. return true;
  223. }
  224. /// <summary>
  225. ///
  226. /// </summary>
  227. /// <param name="objValue"></param>
  228. /// <param name="objType"></param>
  229. /// <returns></returns>
  230. public bool IsType(object ObjValue, int ObjType)
  231. {
  232. try
  233. {
  234. switch (ObjType)
  235. {
  236. case 1:
  237. int intValue = Convert.ToInt32(ObjValue);
  238. break;
  239. case 2:
  240. double douValue = Convert.ToDouble(ObjValue);
  241. break;
  242. case 3:
  243. float floValue = Convert.ToSingle(ObjValue);
  244. break;
  245. }
  246. return true;
  247. }
  248. catch (Exception)
  249. {
  250. //为空提示
  251. ShowMessage(7);
  252. return false;
  253. }
  254. }
  255. /// <summary>
  256. /// 判断是否连接
  257. /// </summary>
  258. /// <returns></returns>
  259. public bool IsConnection()
  260. {
  261. try
  262. {
  263. if (ConnectionState)
  264. {
  265. return true;
  266. }
  267. return false;
  268. }
  269. catch (Exception)
  270. {
  271. //为空提示
  272. ShowMessage(7);
  273. return false;
  274. }
  275. }
  276. #endregion
  277. #region 窗体控制的事件汇总
  278. private void SemTestForms_Load(object sender, EventArgs e)
  279. {
  280. ////循环窗体中
  281. foreach (Control item in gbGetMethods.Controls)
  282. {
  283. if (item is Button)
  284. {
  285. //绑定按钮点击事件
  286. //item.Click += new System.EventHandler(btnGetInfo_Click);
  287. ((Button)item).Enabled = false;
  288. }
  289. }
  290. foreach (Control item in gbSetMethods.Controls)
  291. {
  292. if (item is Button)
  293. {
  294. //绑定按钮点击事件
  295. //item.Click += new System.EventHandler(btnSetInfo_Click);
  296. ((Button)item).Enabled = false;
  297. }
  298. }
  299. }
  300. private void btnDone_Click(object sender, EventArgs e)
  301. {
  302. //遍历tabHardwareSet标签中所有的TextBox控件
  303. //foreach (Control control in this.gbSetMethods.Controls)
  304. //{
  305. // //节点名称与节点参数值
  306. // string Name = string.Empty;
  307. // string Value = string.Empty;
  308. // //判断类型名称
  309. // if (control is TextBox)
  310. // {
  311. // Name = (control as TextBox).Name.Substring(2);
  312. // //获取节点名称与节点参数值
  313. // Value = (control as TextBox).Text;
  314. // if(!Value.Equals(""))
  315. // SaveSetting(Name, Value);
  316. // }
  317. // //判断类型名称
  318. // if (control is CheckBox)
  319. // {
  320. // Name = (control as CheckBox).Name.Substring(2);
  321. // //获取节点名称与节点参数值
  322. // Value = (control as CheckBox).Checked ? "true" : "false";
  323. // SaveSetting(Name, Value);
  324. // }
  325. //}
  326. //返回关闭窗口返回值
  327. this.DialogResult = DialogResult.OK;
  328. }
  329. private void btnGetInfo_Click(object sender, EventArgs e)
  330. {
  331. if (!IsConnection())
  332. {
  333. return;
  334. }
  335. //获取响应按钮
  336. Button btnTest = (Button)sender;
  337. try
  338. {
  339. //节点名称与节点参数值
  340. string Name = string.Empty;
  341. string Value = string.Empty;
  342. //判断本地中是否存在文件路径
  343. if (ExistsFile(xmlFilePath))
  344. {
  345. //遍历tabHardwareSet标签中所有的ComboBox控件
  346. foreach (Control control in this.gbGetMethods.Controls)
  347. {
  348. //判断类型名称
  349. if (control is TextBox)
  350. {
  351. Name = (control as TextBox).Name.Substring(2);
  352. if (btnTest.Name.Contains(Name))
  353. {
  354. //获取节点名称与节点参数值
  355. System.Xml.XmlNode xmlNode = XMLOperationClass.GetXMLInformationValue("S" + Name);
  356. (control as TextBox).Text = ((XmlElement)xmlNode).GetAttribute("Value");
  357. }
  358. }
  359. //判断类型名称
  360. if (control is CheckBox)
  361. {
  362. Name = (control as CheckBox).Name.Substring(2);
  363. if (btnTest.Name.Contains(Name))
  364. {
  365. //获取节点名称与节点参数值
  366. System.Xml.XmlNode xmlNode = XMLOperationClass.GetXMLInformationValue(Name);
  367. (control as CheckBox).Checked = ((XmlElement)xmlNode).GetAttribute("Value").Equals("true") ? true : false;
  368. }
  369. }
  370. }
  371. }
  372. else
  373. {
  374. //如果文件不存在,则创建文件
  375. CreateFile(xmlFilePath);
  376. }
  377. }
  378. catch (Exception ex)
  379. {
  380. //记录日志信息
  381. log.Error(ex.Message.ToString());
  382. }
  383. }
  384. private void btnSetInfo_Click(object sender, EventArgs e)
  385. {
  386. if (!IsConnection())
  387. {
  388. return;
  389. }
  390. //获取响应按钮
  391. Button btnTest = (Button)sender;
  392. try
  393. {
  394. //节点名称与节点参数值
  395. string Name = string.Empty;
  396. string Value = string.Empty;
  397. //判断本地中是否存在文件路径
  398. if (ExistsFile(xmlFilePath))
  399. {
  400. //遍历tabHardwareSet标签中所有的TextBox控件
  401. foreach (Control control in this.gbSetMethods.Controls)
  402. {
  403. //判断类型名称
  404. if (control is TextBox)
  405. {
  406. Name = (control as TextBox).Name.Substring(2);
  407. if (btnTest.Name.Contains(Name))
  408. {
  409. //获取节点名称与节点参数值
  410. Value = (control as TextBox).Text;
  411. SaveSetting(Name, Value);
  412. }
  413. }
  414. //判断类型名称
  415. if (control is CheckBox)
  416. {
  417. Name = (control as CheckBox).Name.Substring(2);
  418. if (btnTest.Name.Contains(Name))
  419. {
  420. //获取节点名称与节点参数值
  421. Value = (control as CheckBox).Checked ? "true" : "false";
  422. SaveSetting(Name, Value);
  423. }
  424. }
  425. }
  426. }
  427. else
  428. {
  429. //如果文件不存在,则创建文件
  430. CreateFile(xmlFilePath);
  431. }
  432. }
  433. catch (Exception ex)
  434. {
  435. //记录日志信息
  436. log.Error(ex.Message.ToString());
  437. }
  438. }
  439. private void btnGetAll_Click(object sender, EventArgs e)
  440. {
  441. }
  442. private void BtnConnect_Click(object sender, EventArgs e)
  443. {
  444. if (!ConnectionState)
  445. {
  446. if (!cfun.Init())
  447. {
  448. return;
  449. }
  450. //和电镜建立通讯连接
  451. ConnectionState = cfun.ConncetSem();
  452. ///获取当前电镜的ID号
  453. SemType = cfun.GetSemType();
  454. if (!ConnectionState)
  455. {
  456. ShowMessage(2);
  457. log.Error(table["message3"].ToString());
  458. }
  459. else
  460. {
  461. string str = table["str1"].ToString();
  462. BtnConnect.Text = str;
  463. GetBtnState(true);
  464. log.Info("The energy spectrum is connected");
  465. }
  466. }
  467. else
  468. {
  469. string str = table["str2"].ToString();
  470. //断开电镜连接
  471. //if (cfun.DisConnectSem())
  472. //{
  473. // log.Info(table["message10"].ToString());
  474. //}
  475. //else
  476. //{
  477. // //ShowMessage(9);
  478. //}
  479. BtnConnect.Text = str;
  480. ConnectionState = false;
  481. GetBtnState(false);
  482. }
  483. }
  484. private void SemTestForms_FormClosing(object sender, FormClosingEventArgs e)
  485. {
  486. //try
  487. //{
  488. // //断开电镜连接
  489. cfun.DisconnectSem();
  490. // //释放DLL内存
  491. // //cfun.FreeHardware();
  492. //}
  493. //catch (Exception ex)
  494. //{
  495. // //记录日志信息(异常日志)
  496. // log.Error(ex.Message.ToString());
  497. //}
  498. }
  499. private void btnGPositionXYR_Click(object sender, EventArgs e)
  500. {
  501. try
  502. {
  503. //赋值
  504. double PositionX = 0;
  505. double PositionY = 0;
  506. double PositionR = 0;
  507. //获取参数
  508. bool result = cfun.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
  509. if (result)
  510. {
  511. //赋值 显示
  512. tbPositionX.Text = Convert.ToDouble(PositionX).ToString();
  513. tbPositionY.Text = Convert.ToDouble(PositionY).ToString();
  514. tbPositionR.Text = Convert.ToDouble(PositionR).ToString();
  515. log.Info("X,Y-axis coordinates:(" + tbPositionX.Text + "," + tbPositionY.Text+")");
  516. }
  517. else
  518. {
  519. //配置结果提示
  520. ShowMessage(6);
  521. log.Error("Failed to obtain the X and Y coordinates");
  522. }
  523. }
  524. catch (Exception ex)
  525. {
  526. //记录日志信息(异常日志)
  527. log.Error(ex.Message.ToString());
  528. }
  529. }
  530. private void btnSPositionXYR_Click(object sender, EventArgs e)
  531. {
  532. try
  533. {
  534. //判断是否为空
  535. if (!IsNull(tbSPositionX))
  536. {
  537. this.Focus();
  538. return;
  539. }
  540. if (!IsType(tbSPositionX.Text, 2))
  541. {
  542. this.Focus();
  543. return;
  544. }
  545. if (!IsNull(tbSPositionY))
  546. {
  547. this.Focus();
  548. return;
  549. }
  550. if (!IsType(tbSPositionY.Text, 2))
  551. {
  552. this.Focus();
  553. return;
  554. }
  555. //if (!IsNull(tbSPositionR))
  556. //{
  557. // this.Focus();
  558. // return;
  559. //}
  560. //if (!IsType(tbSPositionR.Text, 2))
  561. //{
  562. // this.Focus();
  563. // return;
  564. //}
  565. //赋值
  566. double PositionX = Convert.ToDouble(tbSPositionX.Text);
  567. double PositionY = Convert.ToDouble(tbSPositionY.Text);
  568. double PositionR = Convert.ToDouble(tbSPositionR.Text);
  569. bool result = cfun.SetSemPositionXY(PositionX, PositionY, PositionR);
  570. if (result)
  571. {
  572. //配置结果提示
  573. ShowMessage(3);
  574. log.Info("Set successfully, current X and Y coordinates should be:(" + PositionX.ToString() + "," + PositionY.ToString() + ")");
  575. }
  576. else
  577. {
  578. ShowMessage(4);
  579. log.Error("Failed to set X and Y coordinates!");
  580. }
  581. }
  582. catch (Exception ex)
  583. {
  584. //记录日志信息
  585. log.Error(ex.Message.ToString());
  586. }
  587. }
  588. private void btnMoveSEMToPoint_Click(object sender, EventArgs e)
  589. {
  590. try
  591. {
  592. //判断是否为空
  593. if (!IsNull(tbSPositionX))
  594. {
  595. this.Focus();
  596. return;
  597. }
  598. if (!IsType(tbSPositionX.Text, 2))
  599. {
  600. this.Focus();
  601. return;
  602. }
  603. if (!IsNull(tbSPositionY))
  604. {
  605. this.Focus();
  606. return;
  607. }
  608. if (!IsType(tbSPositionY.Text, 2))
  609. {
  610. this.Focus();
  611. return;
  612. }
  613. if (!IsNull(tbSPositionR))
  614. {
  615. this.Focus();
  616. return;
  617. }
  618. if (!IsType(tbSPositionR.Text, 2))
  619. {
  620. this.Focus();
  621. return;
  622. }
  623. //赋值
  624. double PositionX = Convert.ToDouble(tbSPositionX.Text);
  625. double PositionY = Convert.ToDouble(tbSPositionY.Text);
  626. double PositionR = Convert.ToDouble(tbSPositionR.Text);
  627. bool result = cfun.MoveSEMToPoint(PositionX, PositionY, PositionR);
  628. }
  629. catch (Exception ex)
  630. {
  631. //记录日志信息
  632. log.Error(ex.Message.ToString());
  633. }
  634. }
  635. private void btnGBeamBlank_Click(object sender, EventArgs e)
  636. {
  637. try
  638. {
  639. int a_nBeamBlank = 0;
  640. //获取参数
  641. bool result = cfun.GetSemBeamBlank(ref a_nBeamBlank);
  642. if (result)
  643. {
  644. //赋值 显示
  645. tbBeamBlank.Text = Convert.ToString(a_nBeamBlank);
  646. log.Info("Beam baffle:" + tbBeamBlank.Text);
  647. }
  648. else
  649. {
  650. //配置结果提示
  651. ShowMessage(6);
  652. log.Error("Failed to obtain the Beam baffle!");
  653. }
  654. }
  655. catch (Exception ex)
  656. {
  657. //记录日志信息(异常日志)
  658. log.Error(ex.Message.ToString());
  659. }
  660. }
  661. private void btnSBeamBlank_Click(object sender, EventArgs e)
  662. {
  663. try
  664. {
  665. bool a_nBeamBlank = false;
  666. //判断是否为空与类型
  667. if (!IsNull(tbSBeamBlank))
  668. {
  669. tbSBeamBlank.Focus();
  670. return;
  671. }
  672. if (!IsType(tbSBeamBlank.Text, 1))
  673. {
  674. tbSBeamBlank.Focus();
  675. return;
  676. }
  677. //获取参数与设置参数
  678. a_nBeamBlank = Convert.ToBoolean(tbSBeamBlank.Text);
  679. bool result = cfun.SetSemBeamBlank(a_nBeamBlank);
  680. if (result)
  681. {
  682. //配置结果提示
  683. ShowMessage(3);
  684. log.Info("etting successful!The current beam baffle should be:" + tbSBeamBlank.Text);
  685. }
  686. else
  687. {
  688. ShowMessage(4);
  689. log.Error("Beam baffle setting failed!");
  690. }
  691. }
  692. catch (Exception ex)
  693. {
  694. //记录日志信息(异常日志)
  695. log.Error(ex.Message.ToString());
  696. }
  697. }
  698. private void btnGBrightness_Click(object sender, EventArgs e)
  699. {
  700. try
  701. {
  702. double a_dBrightness = 0;
  703. //获取参数
  704. bool result = cfun.GetSemBrightness(ref a_dBrightness);
  705. if (result)
  706. {
  707. //赋值 显示
  708. tbBrightness.Text = Convert.ToString(a_dBrightness);
  709. log.Info("Brightness:" + tbBrightness.Text);
  710. }
  711. else
  712. {
  713. //配置结果提示
  714. ShowMessage(6);
  715. log.Error("Failed to obtain the Brightness");
  716. }
  717. }
  718. catch (Exception ex)
  719. {
  720. //记录日志信息(异常日志)
  721. log.Error(ex.Message.ToString());
  722. }
  723. }
  724. private void btnSBrightness_Click(object sender, EventArgs e)
  725. {
  726. try
  727. {
  728. double a_dBrightness = 0;
  729. //判断是否为空与类型
  730. if (!IsNull(tbSBrightness))
  731. {
  732. tbSBrightness.Focus();
  733. return;
  734. }
  735. if (!IsType(tbSBrightness.Text, 2))
  736. {
  737. tbSBrightness.Focus();
  738. return;
  739. }
  740. //获取参数与设置参数
  741. a_dBrightness = Convert.ToInt32(tbSBrightness.Text);
  742. //获取参数
  743. bool result = cfun.SetSemBrightness(a_dBrightness);
  744. if (result)
  745. {
  746. //配置结果提示
  747. ShowMessage(3);
  748. log.Info("Setting successful!, the current brightness should be:" + tbSBrightness.Text);
  749. }
  750. else
  751. {
  752. ShowMessage(4);
  753. log.Error("Brightness setting failed!");
  754. }
  755. }
  756. catch (Exception ex)
  757. {
  758. //记录日志信息(异常日志)
  759. log.Error(ex.Message.ToString());
  760. }
  761. }
  762. private void btnGContrast_Click(object sender, EventArgs e)
  763. {
  764. try
  765. {
  766. double a_dContrast = 0;
  767. //获取参数
  768. bool result = cfun.GetSemContrast(ref a_dContrast);
  769. if (result)
  770. {
  771. //赋值 显示
  772. tbContrast.Text = Convert.ToString(a_dContrast);
  773. log.Info("Contrast:" + tbContrast.Text);
  774. }
  775. else
  776. {
  777. //配置结果提示
  778. ShowMessage(6);
  779. log.Error("Failed to obtain contrast!");
  780. }
  781. }
  782. catch (Exception ex)
  783. {
  784. //记录日志信息(异常日志)
  785. log.Error(ex.Message.ToString());
  786. }
  787. }
  788. private void btnSContrast_Click(object sender, EventArgs e)
  789. {
  790. try
  791. {
  792. double a_dContrast = 0;
  793. //判断是否为空与类型
  794. if (!IsNull(tbSContrast))
  795. {
  796. tbSContrast.Focus();
  797. return;
  798. }
  799. if (!IsType(tbSContrast.Text, 2))
  800. {
  801. tbSContrast.Focus();
  802. return;
  803. }
  804. //赋值
  805. a_dContrast = Convert.ToInt32(tbSContrast.Text);
  806. //获取结果参数
  807. bool result = cfun.SetSemContrast(a_dContrast);
  808. if (result)
  809. {
  810. //配置结果提示
  811. ShowMessage(3);
  812. log.Info("Set successfully, the current contrast should be:" + tbSContrast.Text);
  813. }
  814. else
  815. {
  816. ShowMessage(4);
  817. log.Error("Contrast setting failed!");
  818. }
  819. }
  820. catch (Exception ex)
  821. {
  822. //记录日志信息(异常日志)
  823. log.Error(ex.Message.ToString());
  824. }
  825. }
  826. private void btnGFWD_Click(object sender, EventArgs e)
  827. {
  828. try
  829. {
  830. double a_dWorkingDistance = 0;
  831. //获取参数
  832. bool result = cfun.GetSemWorkingDistance(ref a_dWorkingDistance);
  833. if (result)
  834. {
  835. //赋值 显示
  836. tbFWD.Text = Convert.ToString(a_dWorkingDistance);
  837. log.Info("WorkingDistance:" + tbFWD.Text);
  838. }
  839. else
  840. {
  841. //配置结果提示
  842. ShowMessage(6);
  843. log.Error("Fail to obtain the WorkingDistance!");
  844. }
  845. }
  846. catch (Exception ex)
  847. {
  848. //记录日志信息(异常日志)
  849. log.Error(ex.Message.ToString());
  850. }
  851. }
  852. private void btnSFWD_Click(object sender, EventArgs e)
  853. {
  854. try
  855. {
  856. double a_dWorkingDistance = 0;
  857. //判断是否为空与类型
  858. if (!IsNull(tbSFWD))
  859. {
  860. tbSFWD.Focus();
  861. return;
  862. }
  863. if (!IsType(tbSFWD.Text, 2))
  864. {
  865. tbSFWD.Focus();
  866. return;
  867. }
  868. //赋值
  869. a_dWorkingDistance = Convert.ToDouble(tbSFWD.Text);
  870. //获取结果参数
  871. bool result = cfun.SetSemWorkingDistance(a_dWorkingDistance);
  872. if (result)
  873. {
  874. //配置结果提示
  875. ShowMessage(3);
  876. log.Info("Setting successful!, the current working distance should be:"+ tbSFWD.Text);
  877. }
  878. else
  879. {
  880. ShowMessage(4);
  881. log.Error("Working distance setting failed!");
  882. }
  883. }
  884. catch (Exception ex)
  885. {
  886. //记录日志信息(异常日志)
  887. log.Error(ex.Message.ToString());
  888. }
  889. }
  890. private void btnGKV_Click(object sender, EventArgs e)
  891. {
  892. try
  893. {
  894. double a_dKV = 0;
  895. //获取参数
  896. bool result = cfun.GetSemHighTension(ref a_dKV);
  897. if (result)
  898. {
  899. //赋值 显示
  900. tbKV.Text = Convert.ToString(a_dKV);
  901. log.Info("Electron microscope voltage:" + tbKV.Text);
  902. }
  903. else
  904. {
  905. //配置结果提示
  906. ShowMessage(6);
  907. log.Error("Failed to obtain electron microscope voltage value!");
  908. }
  909. }
  910. catch (Exception ex)
  911. {
  912. //记录日志信息(异常日志)
  913. log.Error(ex.Message.ToString());
  914. }
  915. }
  916. private void btnSKV_Click(object sender, EventArgs e)
  917. {
  918. try
  919. {
  920. double a_dKV = 0;
  921. //判断是否为空与类型
  922. if (!IsNull(tbSKV))
  923. {
  924. tbSKV.Focus();
  925. return;
  926. }
  927. if (!IsType(tbSKV.Text, 2))
  928. {
  929. tbSKV.Focus();
  930. return;
  931. }
  932. //赋值
  933. a_dKV = Convert.ToInt32(tbSKV.Text);
  934. //获取结果参数
  935. bool result = cfun.SetSemHighTension(a_dKV);
  936. if (result)
  937. {
  938. //配置结果提示
  939. ShowMessage(3);
  940. log.Info("Setting successful!, the current voltage value should be:" + tbSKV.Text);
  941. }
  942. else
  943. {
  944. ShowMessage(4);
  945. log.Error("Voltage setting failed!");
  946. }
  947. }
  948. catch (Exception ex)
  949. {
  950. //记录日志信息(异常日志)
  951. log.Error(ex.Message.ToString());
  952. }
  953. }
  954. private void btnGMagnification_Click(object sender, EventArgs e)
  955. {
  956. try
  957. {
  958. double a_dMagnification = 0;
  959. //获取参数
  960. bool result = cfun.GetSemMagnification(ref a_dMagnification);
  961. if (result)
  962. {
  963. //赋值 显示
  964. tbMagnification.Text = Convert.ToString(a_dMagnification);
  965. log.Info("SemMagnification:" + tbMagnification.Text);
  966. }
  967. else
  968. {
  969. //配置结果提示
  970. ShowMessage(6);
  971. log.Error("Fail to obtain the SemMagnification!");
  972. }
  973. }
  974. catch (Exception ex)
  975. {
  976. //记录日志信息(异常日志)
  977. log.Error(ex.Message.ToString());
  978. }
  979. }
  980. private void btnSMagnification_Click(object sender, EventArgs e)
  981. {
  982. try
  983. {
  984. double a_dMagnification = 0;
  985. //判断是否为空与类型
  986. if (!IsNull(tbSMagnification))
  987. {
  988. tbSMagnification.Focus();
  989. return;
  990. }
  991. if (!IsType(tbSMagnification.Text, 2))
  992. {
  993. tbSMagnification.Focus();
  994. return;
  995. }
  996. //赋值
  997. a_dMagnification = Convert.ToInt32(tbSMagnification.Text);
  998. //获取结果参数
  999. bool result = cfun.SetSemMagnification(a_dMagnification);
  1000. if (result)
  1001. {
  1002. //配置结果提示
  1003. ShowMessage(3);
  1004. log.Info("Setting successful!, the current magnification should be:");
  1005. }
  1006. else
  1007. {
  1008. ShowMessage(4);
  1009. log.Error("Magnification setting failed!");
  1010. }
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. //记录日志信息(异常日志)
  1015. log.Error(ex.Message.ToString());
  1016. }
  1017. }
  1018. private void btnGSpotSize_Click(object sender, EventArgs e)
  1019. {
  1020. try
  1021. {
  1022. double a_dSpotSize = 0;
  1023. //获取参数
  1024. //记录日志信息(异常日志)
  1025. bool result = cfun.GetSemSpotSize(ref a_dSpotSize);
  1026. if (result)
  1027. {
  1028. //赋值 显示
  1029. tbSpotSize.Text = Convert.ToString(a_dSpotSize);
  1030. log.Info("Spot size:" + tbSpotSize.Text);
  1031. }
  1032. else
  1033. {
  1034. //配置结果提示
  1035. ShowMessage(6);
  1036. }
  1037. }
  1038. catch (Exception ex)
  1039. {
  1040. //记录日志信息(异常日志)
  1041. log.Error(ex.Message.ToString());
  1042. }
  1043. }
  1044. private void btnSSpotSize_Click(object sender, EventArgs e)
  1045. {
  1046. try
  1047. {
  1048. double a_dSpotSize = 0;
  1049. //判断是否为空与类型
  1050. if (!IsNull(tbSSpotSize))
  1051. {
  1052. tbSSpotSize.Focus();
  1053. return;
  1054. }
  1055. if (!IsType(tbSSpotSize.Text, 2))
  1056. {
  1057. tbSSpotSize.Focus();
  1058. return;
  1059. }
  1060. //赋值
  1061. a_dSpotSize = Convert.ToInt32(tbSSpotSize.Text);
  1062. //获取结果参数
  1063. bool result = cfun.SetSemSpotSize(a_dSpotSize);
  1064. if (result)
  1065. {
  1066. //配置结果提示
  1067. ShowMessage(3);
  1068. log.Info("Setting successful!, the current spot size should be:");
  1069. }
  1070. else
  1071. {
  1072. ShowMessage(4);
  1073. log.Error("Spot size setting failed!");
  1074. }
  1075. }
  1076. catch (Exception ex)
  1077. {
  1078. //记录日志信息(异常日志)
  1079. log.Error(ex.Message.ToString());
  1080. }
  1081. }
  1082. private void btnHT_Click(object sender, EventArgs e)
  1083. {
  1084. try
  1085. {
  1086. bool a_bHTValue = false;
  1087. //获取参数
  1088. bool result = cfun.GetSemHTOnOff(ref a_bHTValue);
  1089. if (result)
  1090. {
  1091. //赋值 显示
  1092. cbHT.Checked = Convert.ToBoolean(a_bHTValue);
  1093. log.Info("HT:" + cbHT.Checked.ToString());
  1094. }
  1095. else
  1096. {
  1097. //配置结果提示
  1098. ShowMessage(6);
  1099. log.Error("Fail to obtain the HT!");
  1100. }
  1101. }
  1102. catch (Exception ex)
  1103. {
  1104. //记录日志信息(异常日志)
  1105. log.Error(ex.Message.ToString());
  1106. }
  1107. }
  1108. private void btnSHT_Click(object sender, EventArgs e)
  1109. {
  1110. try
  1111. {bool a_bHTValue = false;
  1112. //判断是否为空与类型
  1113. //赋值
  1114. a_bHTValue = cbSHT.Checked;
  1115. //获取结果参数
  1116. bool result = cfun.SetSemHTOnOff(a_bHTValue);
  1117. if (result)
  1118. {
  1119. //配置结果提示
  1120. ShowMessage(3);
  1121. log.Info("Setting successful!, the current voltage should be:" + cbSHT.Checked.ToString());
  1122. }
  1123. else
  1124. {
  1125. ShowMessage(4);
  1126. log.Error("Voltage setting failed!");
  1127. }
  1128. }
  1129. catch (Exception ex)
  1130. {
  1131. //记录日志信息(异常日志)
  1132. log.Error(ex.Message.ToString());
  1133. }
  1134. }
  1135. private void btnGSemScanFieldXY_Click(object sender, EventArgs e)
  1136. {
  1137. try
  1138. {
  1139. //获取参数
  1140. Size result = cfun.GetSemScanField100();
  1141. if (result != null)
  1142. {
  1143. //赋值 显示
  1144. tbGSemScanFieldX.Text = Convert.ToDouble(result.Width).ToString();
  1145. tbSemScanFieldY.Text = Convert.ToDouble(result.Height).ToString();
  1146. log.Info("SemScanFieldX,SemScanFieldY:(" + tbGSemScanFieldX.Text + "," + tbSemScanFieldY.Text + ")");
  1147. }
  1148. else
  1149. {
  1150. //配置结果提示
  1151. ShowMessage(6);
  1152. log.Error("Fail to obtain the SemScanFieldX,SemScanFieldY!");
  1153. }
  1154. }
  1155. catch (Exception ex)
  1156. {
  1157. //记录日志信息(异常日志)
  1158. log.Error(ex.Message.ToString());
  1159. }
  1160. }
  1161. private void btnSSemScanFieldXY_Click(object sender, EventArgs e)
  1162. {
  1163. try
  1164. {
  1165. //判断是否为空
  1166. if (!IsNull(tbGSemScanFieldX))
  1167. {
  1168. return;
  1169. }
  1170. if (!IsNull(tbSemScanFieldY))
  1171. {
  1172. return;
  1173. }
  1174. Size xySize = new Size();
  1175. //赋值
  1176. xySize.Width = Convert.ToInt32(tbGSemScanFieldX.Text);
  1177. xySize.Height = Convert.ToInt32(tbSemScanFieldY.Text);
  1178. cfun.SetSemScanField100(xySize);
  1179. //配置结果提示
  1180. ShowMessage(3);
  1181. log.Info("etting successful!, the current scanning matrix X, the Y-axis should be:(" + tbGSemScanFieldX.Text + "," + tbSemScanFieldY.Text + ")");
  1182. }
  1183. catch (Exception ex)
  1184. {
  1185. //记录日志信息
  1186. log.Error(ex.Message.ToString());
  1187. }
  1188. }
  1189. private void btnGScanMode_Click(object sender, EventArgs e)
  1190. {
  1191. try
  1192. {
  1193. int a_nScanMode = 0;
  1194. //获取参数
  1195. bool result = cfun.GetSemScanMode(ref a_nScanMode);
  1196. if (result)
  1197. {
  1198. //赋值 显示
  1199. tbScanMode.Text = Convert.ToString(a_nScanMode);
  1200. }
  1201. else
  1202. {
  1203. //配置结果提示
  1204. ShowMessage(6);
  1205. }
  1206. }
  1207. catch (Exception ex)
  1208. {
  1209. //记录日志信息(异常日志)
  1210. log.Error(ex.Message.ToString());
  1211. }
  1212. }
  1213. private void btnScanMode_Click(object sender, EventArgs e)
  1214. {
  1215. try
  1216. {
  1217. int a_nScanMode = 0;
  1218. //判断是否为空与类型
  1219. if (!IsNull(tbSScanMode))
  1220. {
  1221. return;
  1222. }
  1223. //赋值
  1224. a_nScanMode = Convert.ToInt32(tbSScanMode.Text);
  1225. //获取结果参数
  1226. bool result = cfun.SetSemScanMode(a_nScanMode);
  1227. if (result)
  1228. {
  1229. //配置结果提示
  1230. ShowMessage(3);
  1231. }
  1232. else
  1233. {
  1234. ShowMessage(4);
  1235. }
  1236. }
  1237. catch (Exception ex)
  1238. {
  1239. //记录日志信息(异常日志)
  1240. log.Error(ex.Message.ToString());
  1241. }
  1242. }
  1243. #endregion
  1244. private void btnGLienTime_Click(object sender, EventArgs e)
  1245. {
  1246. }
  1247. private void bVoltageClose_Click(object sender, EventArgs e)
  1248. {
  1249. bool a_HTValue = true;
  1250. bool result = cfun.SetSemBeamCurrent(a_HTValue);
  1251. //bool result = cfun.SetSemBeamBlank(a_HTValue);
  1252. //bool result = cfun.SetSemHTOnOff(a_HTValue);
  1253. //MessageBox.Show("Whether the shutdown voltage was successful:" + Convert.ToBoolean(result).ToString());
  1254. }
  1255. private void bVoltageStatus_Click(object sender, EventArgs e)
  1256. {
  1257. bool a_HTValue = true;
  1258. //bool result = cfun.SetSemBeamCurrent(a_HTValue);
  1259. bool result = cfun.SetSemBeamBlank(a_HTValue);
  1260. //bool result = cfun.SetSemHTOnOff(a_HTValue);
  1261. //MessageBox.Show("Whether the shutdown voltage was successful:" + Convert.ToBoolean(result).ToString());
  1262. }
  1263. private void button1_Click(object sender, EventArgs e)
  1264. {
  1265. bool result = cfun.SetSemScanExternal(true);
  1266. if (!result)
  1267. {
  1268. MessageBox.Show("SetExternalOn failed!");
  1269. }
  1270. }
  1271. private void button2_Click(object sender, EventArgs e)
  1272. {
  1273. bool result = cfun.SetSemScanExternal(false);
  1274. if (!result)
  1275. {
  1276. MessageBox.Show("SetExternalOn failed!");
  1277. }
  1278. }
  1279. }
  1280. }