SemTestForms.cs 42 KB

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