SemTestForms.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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. static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
  24. static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  25. SemController 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. //断开电镜连接
  455. //if (cfun.DisConnectSem())
  456. //{
  457. // log.Info(table["message10"].ToString());
  458. //}
  459. //else
  460. //{
  461. // //ShowMessage(9);
  462. //}
  463. BtnConnect.Text = str;
  464. ConnectionState = false;
  465. GetBtnState(false);
  466. }
  467. }
  468. private void SemTestForms_FormClosing(object sender, FormClosingEventArgs e)
  469. {
  470. m_SemHardwareMgr.DisConnect();
  471. }
  472. private void btnGPositionXYR_Click(object sender, EventArgs e)
  473. {
  474. try
  475. {
  476. //赋值
  477. double PositionX = 0;
  478. double PositionY = 0;
  479. double PositionR = 0;
  480. //获取参数
  481. bool result = m_SemHardwareMgr.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
  482. if (result)
  483. {
  484. //赋值 显示
  485. tbPositionX.Text = Convert.ToDouble(PositionX).ToString();
  486. tbPositionY.Text = Convert.ToDouble(PositionY).ToString();
  487. tbPositionR.Text = Convert.ToDouble(PositionR).ToString();
  488. log.Info("X,Y-axis coordinates:(" + tbPositionX.Text + "," + tbPositionY.Text+")");
  489. }
  490. else
  491. {
  492. //配置结果提示
  493. ShowMessage(6);
  494. log.Error("Failed to obtain the X and Y coordinates");
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. //记录日志信息(异常日志)
  500. log.Error(ex.Message.ToString());
  501. }
  502. }
  503. private void btnSPositionXYR_Click(object sender, EventArgs e)
  504. {
  505. try
  506. {
  507. //判断是否为空
  508. if (!IsNull(tbSPositionX))
  509. {
  510. this.Focus();
  511. return;
  512. }
  513. if (!IsType(tbSPositionX.Text, 2))
  514. {
  515. this.Focus();
  516. return;
  517. }
  518. if (!IsNull(tbSPositionY))
  519. {
  520. this.Focus();
  521. return;
  522. }
  523. if (!IsType(tbSPositionY.Text, 2))
  524. {
  525. this.Focus();
  526. return;
  527. }
  528. //if (!IsNull(tbSPositionR))
  529. //{
  530. // this.Focus();
  531. // return;
  532. //}
  533. //if (!IsType(tbSPositionR.Text, 2))
  534. //{
  535. // this.Focus();
  536. // return;
  537. //}
  538. //赋值
  539. double PositionX = Convert.ToDouble(tbSPositionX.Text);
  540. double PositionY = Convert.ToDouble(tbSPositionY.Text);
  541. //double PositionR = Convert.ToDouble(tbSPositionR.Text);
  542. bool result = m_SemHardwareMgr.MoveSEMToPoint(PositionX, PositionY);
  543. if (result)
  544. {
  545. //配置结果提示
  546. ShowMessage(3);
  547. log.Info("Set successfully, current X and Y coordinates should be:(" + PositionX.ToString() + "," + PositionY.ToString() + ")");
  548. }
  549. else
  550. {
  551. ShowMessage(4);
  552. log.Error("Failed to set X and Y coordinates!");
  553. }
  554. }
  555. catch (Exception ex)
  556. {
  557. //记录日志信息
  558. log.Error(ex.Message.ToString());
  559. }
  560. }
  561. private void btnMoveSEMToPoint_Click(object sender, EventArgs e)
  562. {
  563. try
  564. {
  565. //判断是否为空
  566. if (!IsNull(tbSPositionX))
  567. {
  568. this.Focus();
  569. return;
  570. }
  571. if (!IsType(tbSPositionX.Text, 2))
  572. {
  573. this.Focus();
  574. return;
  575. }
  576. if (!IsNull(tbSPositionY))
  577. {
  578. this.Focus();
  579. return;
  580. }
  581. if (!IsType(tbSPositionY.Text, 2))
  582. {
  583. this.Focus();
  584. return;
  585. }
  586. if (!IsNull(tbSPositionR))
  587. {
  588. this.Focus();
  589. return;
  590. }
  591. if (!IsType(tbSPositionR.Text, 2))
  592. {
  593. this.Focus();
  594. return;
  595. }
  596. //赋值
  597. double PositionX = Convert.ToDouble(tbSPositionX.Text);
  598. double PositionY = Convert.ToDouble(tbSPositionY.Text);
  599. double PositionR = Convert.ToDouble(tbSPositionR.Text);
  600. bool result = m_SemHardwareMgr.MoveSEMToPoint(PositionX, PositionY, PositionR);
  601. }
  602. catch (Exception ex)
  603. {
  604. //记录日志信息
  605. log.Error(ex.Message.ToString());
  606. }
  607. }
  608. private void btnGBeamBlank_Click(object sender, EventArgs e)
  609. {
  610. try
  611. {
  612. int a_nBeamBlank = 0;
  613. //获取参数
  614. bool result = m_SemHardwareMgr.GetSemBeamBlank(ref a_nBeamBlank);
  615. if (result)
  616. {
  617. //赋值 显示
  618. tbBeamBlank.Text = Convert.ToString(a_nBeamBlank);
  619. log.Info("Beam baffle:" + tbBeamBlank.Text);
  620. }
  621. else
  622. {
  623. //配置结果提示
  624. ShowMessage(6);
  625. log.Error("Failed to obtain the Beam baffle!");
  626. }
  627. }
  628. catch (Exception ex)
  629. {
  630. //记录日志信息(异常日志)
  631. log.Error(ex.Message.ToString());
  632. }
  633. }
  634. private void btnSBeamBlank_Click(object sender, EventArgs e)
  635. {
  636. try
  637. {
  638. bool a_nBeamBlank = false;
  639. //判断是否为空与类型
  640. if (!IsNull(tbSBeamBlank))
  641. {
  642. tbSBeamBlank.Focus();
  643. return;
  644. }
  645. if (!IsType(tbSBeamBlank.Text, 1))
  646. {
  647. tbSBeamBlank.Focus();
  648. return;
  649. }
  650. //获取参数与设置参数
  651. a_nBeamBlank = Convert.ToBoolean(tbSBeamBlank.Text);
  652. bool result = m_SemHardwareMgr.SetSemBeamBlank(a_nBeamBlank);
  653. if (result)
  654. {
  655. //配置结果提示
  656. ShowMessage(3);
  657. log.Info("etting successful!The current beam baffle should be:" + tbSBeamBlank.Text);
  658. }
  659. else
  660. {
  661. ShowMessage(4);
  662. log.Error("Beam baffle setting failed!");
  663. }
  664. }
  665. catch (Exception ex)
  666. {
  667. //记录日志信息(异常日志)
  668. log.Error(ex.Message.ToString());
  669. }
  670. }
  671. private void btnGBrightness_Click(object sender, EventArgs e)
  672. {
  673. try
  674. {
  675. double a_dBrightness = 0;
  676. //获取参数
  677. bool result = m_SemHardwareMgr.GetSemBrightness(ref a_dBrightness);
  678. if (result)
  679. {
  680. //赋值 显示
  681. tbBrightness.Text = Convert.ToString(a_dBrightness);
  682. log.Info("Brightness:" + tbBrightness.Text);
  683. }
  684. else
  685. {
  686. //配置结果提示
  687. ShowMessage(6);
  688. log.Error("Failed to obtain the Brightness");
  689. }
  690. }
  691. catch (Exception ex)
  692. {
  693. //记录日志信息(异常日志)
  694. log.Error(ex.Message.ToString());
  695. }
  696. }
  697. private void btnSBrightness_Click(object sender, EventArgs e)
  698. {
  699. try
  700. {
  701. double a_dBrightness = 0;
  702. //判断是否为空与类型
  703. if (!IsNull(tbSBrightness))
  704. {
  705. tbSBrightness.Focus();
  706. return;
  707. }
  708. if (!IsType(tbSBrightness.Text, 2))
  709. {
  710. tbSBrightness.Focus();
  711. return;
  712. }
  713. //获取参数与设置参数
  714. a_dBrightness = Convert.ToInt32(tbSBrightness.Text);
  715. //获取参数
  716. bool result = m_SemHardwareMgr.SetSemBrightness(a_dBrightness);
  717. if (result)
  718. {
  719. //配置结果提示
  720. ShowMessage(3);
  721. log.Info("Setting successful!, the current brightness should be:" + tbSBrightness.Text);
  722. }
  723. else
  724. {
  725. ShowMessage(4);
  726. log.Error("Brightness setting failed!");
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. //记录日志信息(异常日志)
  732. log.Error(ex.Message.ToString());
  733. }
  734. }
  735. private void btnGContrast_Click(object sender, EventArgs e)
  736. {
  737. try
  738. {
  739. double a_dContrast = 0;
  740. //获取参数
  741. bool result = m_SemHardwareMgr.GetSemContrast(ref a_dContrast);
  742. if (result)
  743. {
  744. //赋值 显示
  745. tbContrast.Text = Convert.ToString(a_dContrast);
  746. log.Info("Contrast:" + tbContrast.Text);
  747. }
  748. else
  749. {
  750. //配置结果提示
  751. ShowMessage(6);
  752. log.Error("Failed to obtain contrast!");
  753. }
  754. }
  755. catch (Exception ex)
  756. {
  757. //记录日志信息(异常日志)
  758. log.Error(ex.Message.ToString());
  759. }
  760. }
  761. private void btnSContrast_Click(object sender, EventArgs e)
  762. {
  763. try
  764. {
  765. double a_dContrast = 0;
  766. //判断是否为空与类型
  767. if (!IsNull(tbSContrast))
  768. {
  769. tbSContrast.Focus();
  770. return;
  771. }
  772. if (!IsType(tbSContrast.Text, 2))
  773. {
  774. tbSContrast.Focus();
  775. return;
  776. }
  777. //赋值
  778. a_dContrast = Convert.ToInt32(tbSContrast.Text);
  779. //获取结果参数
  780. bool result = m_SemHardwareMgr.SetSemContrast(a_dContrast);
  781. if (result)
  782. {
  783. //配置结果提示
  784. ShowMessage(3);
  785. log.Info("Set successfully, the current contrast should be:" + tbSContrast.Text);
  786. }
  787. else
  788. {
  789. ShowMessage(4);
  790. log.Error("Contrast setting failed!");
  791. }
  792. }
  793. catch (Exception ex)
  794. {
  795. //记录日志信息(异常日志)
  796. log.Error(ex.Message.ToString());
  797. }
  798. }
  799. private void btnGFWD_Click(object sender, EventArgs e)
  800. {
  801. try
  802. {
  803. double a_dWorkingDistance = 0;
  804. //获取参数
  805. bool result = m_SemHardwareMgr.GetWorkingDistance(ref a_dWorkingDistance);
  806. if (result)
  807. {
  808. //赋值 显示
  809. tbFWD.Text = Convert.ToString(a_dWorkingDistance);
  810. log.Info("WorkingDistance:" + tbFWD.Text);
  811. }
  812. else
  813. {
  814. //配置结果提示
  815. ShowMessage(6);
  816. log.Error("Fail to obtain the WorkingDistance!");
  817. }
  818. }
  819. catch (Exception ex)
  820. {
  821. //记录日志信息(异常日志)
  822. log.Error(ex.Message.ToString());
  823. }
  824. }
  825. private void btnSFWD_Click(object sender, EventArgs e)
  826. {
  827. try
  828. {
  829. double a_dWorkingDistance = 0;
  830. //判断是否为空与类型
  831. if (!IsNull(tbSFWD))
  832. {
  833. tbSFWD.Focus();
  834. return;
  835. }
  836. if (!IsType(tbSFWD.Text, 2))
  837. {
  838. tbSFWD.Focus();
  839. return;
  840. }
  841. //赋值
  842. a_dWorkingDistance = Convert.ToDouble(tbSFWD.Text);
  843. //获取结果参数
  844. bool result = m_SemHardwareMgr.SetWorkingDistance(a_dWorkingDistance);
  845. if (result)
  846. {
  847. //配置结果提示
  848. ShowMessage(3);
  849. log.Info("Setting successful!, the current working distance should be:"+ tbSFWD.Text);
  850. }
  851. else
  852. {
  853. ShowMessage(4);
  854. log.Error("Working distance setting failed!");
  855. }
  856. }
  857. catch (Exception ex)
  858. {
  859. //记录日志信息(异常日志)
  860. log.Error(ex.Message.ToString());
  861. }
  862. }
  863. private void btnGKV_Click(object sender, EventArgs e)
  864. {
  865. try
  866. {
  867. double a_dKV = 0;
  868. //获取参数
  869. bool result = m_SemHardwareMgr.GetSemHighTension(ref a_dKV);
  870. if (result)
  871. {
  872. //赋值 显示
  873. tbKV.Text = Convert.ToString(a_dKV);
  874. log.Info("Electron microscope voltage:" + tbKV.Text);
  875. }
  876. else
  877. {
  878. //配置结果提示
  879. ShowMessage(6);
  880. log.Error("Failed to obtain electron microscope voltage value!");
  881. }
  882. }
  883. catch (Exception ex)
  884. {
  885. //记录日志信息(异常日志)
  886. log.Error(ex.Message.ToString());
  887. }
  888. }
  889. private void btnSKV_Click(object sender, EventArgs e)
  890. {
  891. try
  892. {
  893. double a_dKV = 0;
  894. //判断是否为空与类型
  895. if (!IsNull(tbSKV))
  896. {
  897. tbSKV.Focus();
  898. return;
  899. }
  900. if (!IsType(tbSKV.Text, 2))
  901. {
  902. tbSKV.Focus();
  903. return;
  904. }
  905. //赋值
  906. a_dKV = Convert.ToInt32(tbSKV.Text);
  907. //获取结果参数
  908. bool result = m_SemHardwareMgr.SetSemHighTension(a_dKV);
  909. if (result)
  910. {
  911. //配置结果提示
  912. ShowMessage(3);
  913. log.Info("Setting successful!, the current voltage value should be:" + tbSKV.Text);
  914. }
  915. else
  916. {
  917. ShowMessage(4);
  918. log.Error("Voltage setting failed!");
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. //记录日志信息(异常日志)
  924. log.Error(ex.Message.ToString());
  925. }
  926. }
  927. private void btnGMagnification_Click(object sender, EventArgs e)
  928. {
  929. try
  930. {
  931. double a_dMagnification = 0;
  932. //获取参数
  933. bool result = m_SemHardwareMgr.GetMagnification(ref a_dMagnification);
  934. if (result)
  935. {
  936. //赋值 显示
  937. tbMagnification.Text = Convert.ToString(a_dMagnification);
  938. log.Info("SemMagnification:" + tbMagnification.Text);
  939. }
  940. else
  941. {
  942. //配置结果提示
  943. ShowMessage(6);
  944. log.Error("Fail to obtain the SemMagnification!");
  945. }
  946. }
  947. catch (Exception ex)
  948. {
  949. //记录日志信息(异常日志)
  950. log.Error(ex.Message.ToString());
  951. }
  952. }
  953. private void btnSMagnification_Click(object sender, EventArgs e)
  954. {
  955. try
  956. {
  957. double a_dMagnification = 0;
  958. //判断是否为空与类型
  959. if (!IsNull(tbSMagnification))
  960. {
  961. tbSMagnification.Focus();
  962. return;
  963. }
  964. if (!IsType(tbSMagnification.Text, 2))
  965. {
  966. tbSMagnification.Focus();
  967. return;
  968. }
  969. //赋值
  970. a_dMagnification = Convert.ToInt32(tbSMagnification.Text);
  971. //获取结果参数
  972. bool result = m_SemHardwareMgr.SetMagnification(a_dMagnification);
  973. if (result)
  974. {
  975. //配置结果提示
  976. ShowMessage(3);
  977. log.Info("Setting successful!, the current magnification should be:");
  978. }
  979. else
  980. {
  981. ShowMessage(4);
  982. log.Error("Magnification setting failed!");
  983. }
  984. }
  985. catch (Exception ex)
  986. {
  987. //记录日志信息(异常日志)
  988. log.Error(ex.Message.ToString());
  989. }
  990. }
  991. private void btnGSpotSize_Click(object sender, EventArgs e)
  992. {
  993. //try
  994. //{
  995. // double a_dSpotSize = 0;
  996. // //获取参数
  997. // //记录日志信息(异常日志)
  998. // bool result = cfun.GetSemSpotSize(ref a_dSpotSize);
  999. // if (result)
  1000. // {
  1001. // //赋值 显示
  1002. // tbSpotSize.Text = Convert.ToString(a_dSpotSize);
  1003. // log.Info("Spot size:" + tbSpotSize.Text);
  1004. // }
  1005. // else
  1006. // {
  1007. // //配置结果提示
  1008. // ShowMessage(6);
  1009. // }
  1010. //}
  1011. //catch (Exception ex)
  1012. //{
  1013. // //记录日志信息(异常日志)
  1014. // log.Error(ex.Message.ToString());
  1015. //}
  1016. }
  1017. private void btnSSpotSize_Click(object sender, EventArgs e)
  1018. {
  1019. //try
  1020. //{
  1021. // double a_dSpotSize = 0;
  1022. // //判断是否为空与类型
  1023. // if (!IsNull(tbSSpotSize))
  1024. // {
  1025. // tbSSpotSize.Focus();
  1026. // return;
  1027. // }
  1028. // if (!IsType(tbSSpotSize.Text, 2))
  1029. // {
  1030. // tbSSpotSize.Focus();
  1031. // return;
  1032. // }
  1033. // //赋值
  1034. // a_dSpotSize = Convert.ToInt32(tbSSpotSize.Text);
  1035. // //获取结果参数
  1036. // bool result = cfun.SetSemSpotSize(a_dSpotSize);
  1037. // if (result)
  1038. // {
  1039. // //配置结果提示
  1040. // ShowMessage(3);
  1041. // log.Info("Setting successful!, the current spot size should be:");
  1042. // }
  1043. // else
  1044. // {
  1045. // ShowMessage(4);
  1046. // log.Error("Spot size setting failed!");
  1047. // }
  1048. //}
  1049. //catch (Exception ex)
  1050. //{
  1051. // //记录日志信息(异常日志)
  1052. // log.Error(ex.Message.ToString());
  1053. //}
  1054. }
  1055. private void btnHT_Click(object sender, EventArgs e)
  1056. {
  1057. try
  1058. {
  1059. double a_bHTValue = 0;
  1060. //获取参数
  1061. bool result = m_SemHardwareMgr.GetSemHighTension(ref a_bHTValue);
  1062. if (a_bHTValue > 0)
  1063. {
  1064. //赋值 显示
  1065. cbHT.Checked = true;
  1066. log.Info("HT:" + cbHT.Checked.ToString());
  1067. }
  1068. else
  1069. {
  1070. //配置结果提示
  1071. ShowMessage(6);
  1072. log.Error("Fail to obtain the HT!");
  1073. }
  1074. }
  1075. catch (Exception ex)
  1076. {
  1077. //记录日志信息(异常日志)
  1078. log.Error(ex.Message.ToString());
  1079. }
  1080. }
  1081. private void btnSHT_Click(object sender, EventArgs e)
  1082. {
  1083. try
  1084. {bool a_bHTValue = false;
  1085. //判断是否为空与类型
  1086. //赋值
  1087. a_bHTValue = cbSHT.Checked;
  1088. //获取结果参数
  1089. bool result = m_SemHardwareMgr.SetSemBeamBlank(a_bHTValue);
  1090. if (result)
  1091. {
  1092. //配置结果提示
  1093. ShowMessage(3);
  1094. log.Info("Setting successful!, the current voltage should be:" + cbSHT.Checked.ToString());
  1095. }
  1096. else
  1097. {
  1098. ShowMessage(4);
  1099. log.Error("Voltage setting failed!");
  1100. }
  1101. }
  1102. catch (Exception ex)
  1103. {
  1104. //记录日志信息(异常日志)
  1105. log.Error(ex.Message.ToString());
  1106. }
  1107. }
  1108. private void btnGSemScanFieldXY_Click(object sender, EventArgs e)
  1109. {
  1110. try
  1111. {
  1112. //获取参数
  1113. double dScanFieldSizeX = 0;
  1114. double dScanFieldSizeY = 0;
  1115. m_SemHardwareMgr.GetScanFieldSize100(ref dScanFieldSizeX, ref dScanFieldSizeY);
  1116. if (dScanFieldSizeX != 0)
  1117. {
  1118. //赋值 显示
  1119. tbGSemScanFieldX.Text = dScanFieldSizeX.ToString();
  1120. tbSemScanFieldY.Text = dScanFieldSizeY.ToString();
  1121. log.Info("SemScanFieldX,SemScanFieldY:(" + tbGSemScanFieldX.Text + "," + tbSemScanFieldY.Text + ")");
  1122. }
  1123. else
  1124. {
  1125. //配置结果提示
  1126. ShowMessage(6);
  1127. log.Error("Fail to obtain the SemScanFieldX,SemScanFieldY!");
  1128. }
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. //记录日志信息(异常日志)
  1133. log.Error(ex.Message.ToString());
  1134. }
  1135. }
  1136. private void btnSSemScanFieldXY_Click(object sender, EventArgs e)
  1137. {
  1138. try
  1139. {
  1140. //判断是否为空
  1141. if (!IsNull(tbGSemScanFieldX))
  1142. {
  1143. return;
  1144. }
  1145. if (!IsNull(tbSemScanFieldY))
  1146. {
  1147. return;
  1148. }
  1149. Size xySize = new Size();
  1150. //赋值
  1151. xySize.Width = Convert.ToInt32(tbGSemScanFieldX.Text);
  1152. xySize.Height = Convert.ToInt32(tbSemScanFieldY.Text);
  1153. m_SemHardwareMgr.SetScanFieldSize100(xySize.Width, xySize.Height);
  1154. //配置结果提示
  1155. ShowMessage(3);
  1156. log.Info("etting successful!, the current scanning matrix X, the Y-axis should be:(" + tbGSemScanFieldX.Text + "," + tbSemScanFieldY.Text + ")");
  1157. }
  1158. catch (Exception ex)
  1159. {
  1160. //记录日志信息
  1161. log.Error(ex.Message.ToString());
  1162. }
  1163. }
  1164. private void btnGScanMode_Click(object sender, EventArgs e)
  1165. {
  1166. //try
  1167. //{
  1168. // int a_nScanMode = 0;
  1169. // //获取参数
  1170. // bool result = cfun.GetSemScanMode(ref a_nScanMode);
  1171. // if (result)
  1172. // {
  1173. // //赋值 显示
  1174. // tbScanMode.Text = Convert.ToString(a_nScanMode);
  1175. // }
  1176. // else
  1177. // {
  1178. // //配置结果提示
  1179. // ShowMessage(6);
  1180. // }
  1181. //}
  1182. //catch (Exception ex)
  1183. //{
  1184. // //记录日志信息(异常日志)
  1185. // log.Error(ex.Message.ToString());
  1186. //}
  1187. }
  1188. private void btnScanMode_Click(object sender, EventArgs e)
  1189. {
  1190. //try
  1191. //{
  1192. // int a_nScanMode = 0;
  1193. // //判断是否为空与类型
  1194. // if (!IsNull(tbSScanMode))
  1195. // {
  1196. // return;
  1197. // }
  1198. // //赋值
  1199. // a_nScanMode = Convert.ToInt32(tbSScanMode.Text);
  1200. // //获取结果参数
  1201. // bool result = cfun.SetSemScanMode(a_nScanMode);
  1202. // if (result)
  1203. // {
  1204. // //配置结果提示
  1205. // ShowMessage(3);
  1206. // }
  1207. // else
  1208. // {
  1209. // ShowMessage(4);
  1210. // }
  1211. //}
  1212. //catch (Exception ex)
  1213. //{
  1214. // //记录日志信息(异常日志)
  1215. // log.Error(ex.Message.ToString());
  1216. //}
  1217. }
  1218. #endregion
  1219. private void btnGLienTime_Click(object sender, EventArgs e)
  1220. {
  1221. }
  1222. private void bVoltageClose_Click(object sender, EventArgs e)
  1223. {
  1224. bool a_HTValue = true;
  1225. bool result = m_SemHardwareMgr.SetSemBeamCurrent(a_HTValue);
  1226. }
  1227. private void bVoltageStatus_Click(object sender, EventArgs e)
  1228. {
  1229. bool a_HTValue = true;
  1230. bool result = m_SemHardwareMgr.SetSemBeamBlank(a_HTValue);
  1231. }
  1232. private void button1_Click(object sender, EventArgs e)
  1233. {
  1234. bool result = m_SemHardwareMgr.SetScanExternal(true);
  1235. if (!result)
  1236. {
  1237. MessageBox.Show("SetExternalOn failed!");
  1238. }
  1239. }
  1240. private void button2_Click(object sender, EventArgs e)
  1241. {
  1242. bool result = m_SemHardwareMgr.SetScanExternal(false);
  1243. if (!result)
  1244. {
  1245. MessageBox.Show("SetExternalOn failed!");
  1246. }
  1247. }
  1248. private void label17_Click(object sender, EventArgs e)
  1249. {
  1250. }
  1251. }
  1252. }