SemTestForms.cs 41 KB

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