SemTestForms.cs 43 KB

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