SemTestForms.cs 42 KB

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