SemTestForms.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. private void label17_Click(object sender, EventArgs e)
  1280. {
  1281. }
  1282. }
  1283. }