SemTestForms.cs 42 KB

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