ControllerSettingForm.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Xml;
  5. using System.IO;
  6. using System.Windows.Forms.DataVisualization.Charting;
  7. using System.Threading;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using OTSCLRINTERFACE;
  11. using OTSModelSharp.ServiceCenter;
  12. using System.Drawing.Drawing2D;
  13. using OTSPeriodicTable;
  14. namespace OTSSysMgrApp
  15. {
  16. public partial class ControllerSettingForm : Form
  17. {
  18. #region 全部变量声明
  19. RecommendedConfiguration recommendedConfiguration;
  20. //连接状态
  21. bool ConnectionState = false;
  22. static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
  23. //日志路径
  24. static string LogPath = System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ConnectionString;
  25. static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  26. IEDSController m_EDSHardwareMgr = null;
  27. //图片
  28. Bitmap bitmap = null;
  29. //国际化
  30. Language lan;
  31. //国际化存储信息
  32. Hashtable table;
  33. #endregion
  34. public enum connectionEnumType
  35. {
  36. EDSOnlyPointXRay = 0,
  37. EDSMultiPointXRay = 1,
  38. EDSAreaXRay = 2,
  39. ScanImage = 3
  40. }
  41. #region 构造函数
  42. public ControllerSettingForm()
  43. {
  44. InitializeComponent();
  45. m_EDSHardwareMgr = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
  46. lan = new Language(this);
  47. table = lan.GetNameTable(this.Name);
  48. }
  49. /// <summary>
  50. /// 连接电镜
  51. /// </summary>
  52. /// <param name="connectionType"></param>
  53. public bool ConnectionSem(connectionEnumType connectionType)
  54. {
  55. //连接电镜标识
  56. bool DisConnResult = false;
  57. //判断连接状态
  58. if (!ConnectionState)
  59. {
  60. //连接电镜设置
  61. DisConnResult = m_EDSHardwareMgr.Connect();
  62. }
  63. if (DisConnResult)
  64. {
  65. ConnectionState = true;
  66. }
  67. else
  68. {
  69. ConnectionState = false;
  70. }
  71. return DisConnResult;
  72. }
  73. /// <summary>
  74. /// EDS初始化
  75. /// </summary>
  76. public bool EDSInit()
  77. {
  78. bool initResult = false;
  79. //线程调用 加载
  80. initResult = m_EDSHardwareMgr.Connect();
  81. return initResult;
  82. }
  83. #endregion
  84. #region 窗体中控件事件汇总
  85. private void btnClearXRay_Click(object sender, EventArgs e)
  86. {
  87. }
  88. private void btnCollectionTime_Click(object sender, EventArgs e)
  89. {
  90. try
  91. {
  92. int CollectionTime = 0;
  93. //判断是否为空与类型
  94. if (!IsNull(tbCollectionTime))
  95. {
  96. tbCollectionTime.Focus();
  97. return;
  98. }
  99. if (!IsType(tbCollectionTime.Text, 1))
  100. {
  101. tbCollectionTime.Focus();
  102. return;
  103. }
  104. //获取参数与设置参数
  105. CollectionTime = Convert.ToInt32(tbCollectionTime.Text);
  106. bool result = false;
  107. if (result)
  108. {
  109. //配置结果提示
  110. ShowMessage(3);
  111. }
  112. else
  113. {
  114. ShowMessage(4);
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. //记录日志信息(异常日志)
  120. log.Error(ex.Message.ToString());
  121. }
  122. }
  123. private void ControllerSettingForm_Load(object sender, EventArgs e)
  124. {
  125. //设置窗体图表
  126. Control.CheckForIllegalCrossThreadCalls = false;
  127. ddlDwellTime.SelectedIndex = 0;
  128. this.control_XRayTable1 = new Control_XRayTable();
  129. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  130. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.None;
  131. this.control_XRayTable1.List_ShowElementInfo = null;
  132. this.control_XRayTable1.Location = new System.Drawing.Point(groupBox1.Location.X, groupBox1.Location.Y);
  133. this.control_XRayTable1.Name = "control_XRayTable1";
  134. this.control_XRayTable1.ShowAnalysisXray = true;
  135. this.control_XRayTable1.Size = new System.Drawing.Size(groupBox1.Width-20, groupBox1.Height);
  136. this.control_XRayTable1.TabIndex = 6;
  137. this.control_XRayTable1.Visible = true;
  138. InitXRayData();
  139. int width = Convert.ToInt32(tbRWidth.Text);
  140. int height = Convert.ToInt32(tbRHeight.Text);
  141. m_EDSHardwareMgr = EDSController.GetEDSController(width, height, 5000,true,"");
  142. groupBox1.Controls.Add(this.control_XRayTable1);
  143. }
  144. Thread ScanThread = null;
  145. private void btnDisplay_Click(object sender, EventArgs e)
  146. {
  147. GetBSEDisplay();
  148. }
  149. private bool GetScanImage(int iWidth, int iHeigh, string DwellTime, ref byte[] bImageData)
  150. {
  151. //电镜设置对象
  152. var scan = ScanController.GetScanController();
  153. int GetImgCount = 0;
  154. try
  155. {
  156. //连接电镜
  157. bool IsConnec = scan.Init();
  158. if (!IsConnec)
  159. {
  160. return false;
  161. }
  162. #region 设置图像分辨率
  163. //设置宽度
  164. if (!scan.SetImageSize(iWidth, iHeigh))
  165. {
  166. return false;
  167. }
  168. #endregion
  169. #region 采集时间
  170. //采集时间
  171. DwellTimeLevel nDwellTime=DwellTimeLevel.Low;
  172. switch (DwellTime)
  173. {
  174. case "Low":
  175. nDwellTime = DwellTimeLevel.Low;
  176. break;
  177. case "Medium":
  178. nDwellTime = DwellTimeLevel.Medium;
  179. break;
  180. case "High":
  181. nDwellTime = DwellTimeLevel.High;
  182. break;
  183. }
  184. //设置采集时间
  185. if (!scan.SetDwellTime(nDwellTime))
  186. {
  187. return false;
  188. }
  189. #endregion
  190. int resultCount = iWidth * iHeigh;
  191. var img = scan.AcquireBSEImage();
  192. bImageData = img.GetImageDataPtr();
  193. }
  194. catch (Exception ex)
  195. {
  196. NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
  197. return false;
  198. }
  199. return true;
  200. }
  201. protected void GetBSEDisplay()
  202. {
  203. try
  204. {
  205. string str1 = table["str1"].ToString();
  206. btnDisplay.Text = str1;
  207. btnDisplay.Enabled = false;
  208. btnDisplay.Refresh();
  209. if (pbImage.Image != null)
  210. {
  211. pbImage.Image = null;
  212. pbImage.Refresh();
  213. }
  214. Thread.Sleep(100);
  215. //设置图像分辨率
  216. int width = 0;
  217. int height = 0;
  218. //获取宽度
  219. width = Convert.ToInt32(tbRWidth.Text);
  220. height = Convert.ToInt32(tbRHeight.Text);
  221. byte[] ImageByte = new byte[width * height];
  222. Bitmap bitmap = null;
  223. int iWidth = Convert.ToInt32(tbRWidth.Text);
  224. int iHeight = Convert.ToInt32(tbRHeight.Text);
  225. bool resultValue = GetScanImage(iWidth, iHeight, ddlDwellTime.Text, ref ImageByte);
  226. string str2 = table["str2"].ToString();
  227. if (resultValue )
  228. {
  229. if (ImageByte != null)
  230. {
  231. bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
  232. pbImage.Image = bitmap;
  233. btnSaveImage.Enabled = true;
  234. log.Info("Image capture success!\nImage resolution:" + tbRWidth.Text + "X" + tbRHeight.Text + ";");
  235. }
  236. else
  237. {
  238. MessageBox.Show(str2, "Tip");
  239. }
  240. }
  241. else
  242. {
  243. MessageBox.Show(str2, "Tip");
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. log.Error("ControllerSettingForm_btnDisplay_Click--错误信息:" + ex.ToString());
  249. }
  250. finally
  251. {
  252. string str = table["btndisplay"].ToString();
  253. btnDisplay.Text = str;
  254. btnDisplay.Enabled = true;
  255. btnDisplay.Refresh();
  256. }
  257. }
  258. private void btnClear_Click(object sender, EventArgs e)
  259. {
  260. pbImage.BackgroundImage = null;
  261. }
  262. Thread EDSThread = null;
  263. private void btnDisplayXRay_Click(object sender, EventArgs e)
  264. {
  265. try
  266. {
  267. string str1 = table["str1"].ToString();
  268. btnDisplayXRay.Text = str1;
  269. btnDisplayXRay.Enabled = false;
  270. btnDisplayXRay.Refresh();
  271. btnPointXRay.Enabled = false;
  272. btnPointXRay.Refresh();
  273. btnAreaRay.Enabled = false;
  274. btnAreaRay.Refresh();
  275. btnClearData.Enabled = false;
  276. btnClearData.Refresh();
  277. InitXRayData();
  278. if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
  279. {
  280. if (EDSInit())
  281. {
  282. //图像数据
  283. uint[] a_XrayData = new uint[2000];
  284. uint a_Milliseconds = 0;
  285. //采集时间
  286. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  287. //采集XRay数据
  288. bool result = m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  289. if (!result)
  290. {
  291. log.Info("CollectSpectrum failed!");
  292. }
  293. int[] XData = new int[2000];
  294. uint nXrayCount = 0;
  295. for (int i = 1; i <= 2000; i++)
  296. {
  297. XData[i - 1] = i;
  298. nXrayCount += a_XrayData[i - 1];
  299. }
  300. //绑定数据源
  301. chartData(XData, a_XrayData);
  302. //显示Xray计数
  303. lbXrayCount.Text = nXrayCount.ToString();
  304. }
  305. }
  306. log.Info("Single point collection succeeded!");
  307. }
  308. catch (Exception ex)
  309. {
  310. //记录日志
  311. log.Error(ex.Message.ToString());
  312. }
  313. finally
  314. {
  315. string str = table["btndisplayxray"].ToString();
  316. btnDisplayXRay.Text = str;
  317. btnDisplayXRay.Enabled = true;
  318. btnDisplayXRay.Refresh();
  319. btnPointXRay.Enabled = true;
  320. btnPointXRay.Refresh();
  321. btnAreaRay.Enabled = true;
  322. btnAreaRay.Refresh();
  323. btnClearData.Enabled = true;
  324. btnClearData.Refresh();
  325. }
  326. }
  327. public void RunEDSThread()
  328. {
  329. try
  330. {
  331. //图像数据
  332. uint[] a_XrayData = new uint[2000];
  333. uint a_Milliseconds = 0;
  334. //采集时间
  335. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  336. //采集XRay数据
  337. m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  338. int[] XData = new int[2000];
  339. for (int i = 1; i <= 2000; i++)
  340. {
  341. XData[i - 1] = i;
  342. }
  343. //绑定数据源
  344. chartData(XData, a_XrayData);
  345. }
  346. catch (Exception ex)
  347. {
  348. //记录日志
  349. log.Error(ex.Message.ToString());
  350. }
  351. }
  352. public void chartDataWithEle(uint[] YData, string elestr)
  353. {
  354. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  355. string[] ele = elestr.Split('\n');
  356. for (int i = 0; i < ele.Length-1; i++)
  357. {
  358. string[] inf = ele[i].Split(':');
  359. ShowElementInfo ls_sei = new ShowElementInfo();
  360. ls_sei.ElementName = inf[0];
  361. ls_sei.Percentage = Convert.ToDouble(inf[1]);
  362. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  363. double de_sx2 = 0;
  364. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  365. {
  366. de_sx2 = 0;
  367. }
  368. else
  369. {
  370. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  371. }
  372. ls_sei.dLF = de_sx2;
  373. list_showelementinfo.Add(ls_sei);
  374. }
  375. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  376. control_XRayTable1.SetXRayShowLineValue(YData, list_showelementinfo);
  377. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  378. Invalidate();
  379. }
  380. public void chartData(int[] XData, uint[] YData)
  381. {
  382. control_XRayTable1.Visible = true;
  383. control_XRayTable1.SetXRayShowLineValue(YData, null);
  384. Invalidate();
  385. }
  386. #endregion
  387. #region 设置按钮事件
  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.tabXRay.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. if (!IsNull(((TextBox)control)))
  415. {
  416. ((TextBox)control).Focus();
  417. return;
  418. }
  419. if (!IsType(((TextBox)control).Text, 1))
  420. {
  421. ((TextBox)control).Focus();
  422. return;
  423. }
  424. //获取节点名称与节点参数值
  425. Value = (control as TextBox).Text;
  426. SaveSetting(Name, Value);
  427. }
  428. }
  429. }
  430. //遍历tabHardwareSet标签中所有的TextBox控件
  431. foreach (Control control in this.tabImage.Controls)
  432. {
  433. //判断类型名称
  434. if (control is TextBox)
  435. {
  436. Name = (control as TextBox).Name.Substring(2);
  437. if (btnTest.Name.Contains(Name))
  438. {
  439. //判断是否为空与类型
  440. if (!IsNull(((TextBox)control)))
  441. {
  442. ((TextBox)control).Focus();
  443. return;
  444. }
  445. if (!IsType(((TextBox)control).Text, 1))
  446. {
  447. ((TextBox)control).Focus();
  448. return;
  449. }
  450. //获取节点名称与节点参数值
  451. Value = (control as TextBox).Text;
  452. SaveSetting(Name, Value);
  453. }
  454. }
  455. }
  456. }
  457. else
  458. {
  459. //如果文件不存在,则创建文件
  460. CreateFile(xmlFilePath);
  461. }
  462. }
  463. catch (Exception ex)
  464. {
  465. //记录日志信息
  466. log.Error(ex.Message.ToString());
  467. }
  468. }
  469. #endregion
  470. #region 保存设置
  471. /// <summary>
  472. /// 保存设置
  473. /// </summary>
  474. /// <param name="Name">节点名称</param>
  475. /// <param name="Value">节点参数值</param>
  476. public void SaveSetting(string Name, string Value)
  477. {
  478. try
  479. {
  480. //判断XML文件中是否存在
  481. if (!XMLOperationClass.ExistsXmlInfo(Name))
  482. {
  483. //调用添加XML节点功能
  484. XMLOperationClass.AddXmlInfo(Name, Value);
  485. }
  486. else
  487. {
  488. //调用修改XML节点功能
  489. XMLOperationClass.EditXmlInfo(Name, Value);
  490. }
  491. }
  492. catch (Exception ex)
  493. {
  494. //记录日志信息
  495. log.Error(ex.Message.ToString());
  496. }
  497. }
  498. #endregion
  499. #region 修改设置
  500. public void EditSetting(string Name, string Value)
  501. {
  502. try
  503. {
  504. //调用修改XML节点功能
  505. XMLOperationClass.EditXmlInfo(Name, Value);
  506. }
  507. catch (Exception ex)
  508. {
  509. //记录日志信息
  510. log.Error(ex.Message.ToString());
  511. }
  512. }
  513. #endregion
  514. #region 判断文件路径
  515. /// <summary>
  516. /// 判断文件路径
  517. /// </summary>
  518. /// <param name="path"></param>
  519. /// <returns></returns>
  520. public bool CreateFile(string path)
  521. {
  522. Directory.CreateDirectory(path);
  523. return false;
  524. }
  525. #endregion
  526. #region 判断文件是否存在
  527. /// <summary>
  528. /// 判断文件是否存在
  529. /// </summary>
  530. /// <param name="path">文件路径</param>
  531. /// <returns></returns>
  532. public bool ExistsFile(string path)
  533. {
  534. try
  535. {
  536. if (File.Exists(path))
  537. {
  538. return true;
  539. }
  540. return false;
  541. }
  542. catch (Exception ex)
  543. {
  544. //记录日志信息
  545. log.Error(ex.Message.ToString());
  546. return false;
  547. }
  548. }
  549. #endregion
  550. #region 获取窗体中所有参数
  551. /// <summary>
  552. /// 获取窗体中控件的所有参数
  553. /// </summary>
  554. public void GetWindowsControlValue()
  555. {
  556. try
  557. {
  558. XmlDocument doc = new XmlDocument();
  559. //加载Xml文件
  560. doc.Load(xmlFilePath);
  561. //获取根节点
  562. XmlElement root = doc.DocumentElement;
  563. //获取子节点集合
  564. XmlNodeList mainNodes = root.GetElementsByTagName("parameter");
  565. foreach (XmlNode node in mainNodes)
  566. {
  567. //获取Name属性值
  568. string text = ((XmlElement)node).GetAttribute("Name");
  569. string value = ((XmlElement)node).GetAttribute("Value");
  570. foreach (Control control in this.tabXRay.Controls)
  571. {
  572. //判断类型名称
  573. if (control.Name.Contains(text))
  574. {
  575. if (control is TextBox)
  576. {
  577. ((TextBox)control).Text = value;
  578. }
  579. else if (control is ComboBox)
  580. {
  581. ((ComboBox)control).SelectedValue = value;
  582. }
  583. else if (control is CheckBox)
  584. {
  585. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  586. }
  587. }
  588. }
  589. foreach (Control control in this.tabImage.Controls)
  590. {
  591. //判断类型名称
  592. if (control.Name.Contains(text))
  593. {
  594. if (control is TextBox)
  595. {
  596. ((TextBox)control).Text = value;
  597. }
  598. else if (control is ComboBox)
  599. {
  600. ((ComboBox)control).SelectedValue = value;
  601. }
  602. else if (control is CheckBox)
  603. {
  604. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  605. }
  606. }
  607. }
  608. }
  609. }
  610. catch (Exception ex)
  611. {
  612. //记录日志信息
  613. log.Error(ex.Message.ToString());
  614. }
  615. }
  616. #endregion
  617. #region 用户信息提示
  618. /// <summary>
  619. /// 提示
  620. /// </summary>
  621. /// <param name="Message"></param>
  622. private void ShowMessage(int MessageType)
  623. {
  624. string message1 = table["message1"].ToString();
  625. string message2 = table["message2"].ToString();
  626. string message3 = table["message3"].ToString();
  627. string message4 = table["message4"].ToString();
  628. string message5 = table["message5"].ToString();
  629. string message6 = table["message6"].ToString();
  630. string message7 = table["message7"].ToString();
  631. string message8 = table["message8"].ToString();
  632. string message9 = table["message9"].ToString();
  633. string message10 = table["message10"].ToString();
  634. string MessageInfo = string.Empty;
  635. switch (MessageType)
  636. {
  637. case 0:
  638. MessageInfo = message1;
  639. break;
  640. case 1:
  641. MessageInfo = message2;
  642. break;
  643. case 2:
  644. MessageInfo = message3;
  645. break;
  646. case 3:
  647. MessageInfo = message4;
  648. break;
  649. case 4:
  650. MessageInfo = message5;
  651. break;
  652. case 5:
  653. MessageInfo = message6;
  654. break;
  655. case 6:
  656. MessageInfo = message7;
  657. break;
  658. case 7:
  659. MessageInfo = message8;
  660. break;
  661. case 8:
  662. MessageInfo = message9;
  663. break;
  664. case 9:
  665. MessageInfo = message10;
  666. break;
  667. }
  668. MessageBox.Show(MessageInfo, "Tip");
  669. }
  670. #endregion
  671. #region 判断控制内容是否为空 与 判断输入的格式是否正确
  672. /// <summary>
  673. /// 判断控制内容是否为空
  674. /// </summary>
  675. /// <param name="tbContent"></param>
  676. /// <returns></returns>
  677. public bool IsNull(TextBox tbContent)
  678. {
  679. if (tbContent.Text.Trim().Equals(""))
  680. {
  681. //为空提示
  682. ShowMessage(0);
  683. //获取焦点
  684. tbContent.Focus();
  685. return false;
  686. }
  687. return true;
  688. }
  689. /// <summary>
  690. ///
  691. /// </summary>
  692. /// <param name="objValue"></param>
  693. /// <param name="objType"></param>
  694. /// <returns></returns>
  695. public bool IsType(object ObjValue, int ObjType)
  696. {
  697. try
  698. {
  699. switch (ObjType)
  700. {
  701. case 1:
  702. int intValue = Convert.ToInt32(ObjValue);
  703. break;
  704. case 2:
  705. double douValue = Convert.ToDouble(ObjValue);
  706. break;
  707. case 3:
  708. float floValue = Convert.ToSingle(ObjValue);
  709. break;
  710. }
  711. return true;
  712. }
  713. catch (Exception)
  714. {
  715. //为空提示
  716. ShowMessage(7);
  717. return false;
  718. }
  719. }
  720. /// <summary>
  721. /// 判断是否连接
  722. /// </summary>
  723. /// <returns></returns>
  724. public bool IsConnection()
  725. {
  726. if (ConnectionState)
  727. {
  728. return true;
  729. }
  730. return false;
  731. }
  732. #endregion
  733. private void ControllerSettingForm_FormClosing(object sender, FormClosingEventArgs e)
  734. {
  735. }
  736. private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
  737. {
  738. try
  739. {
  740. if (ScanThread != null)
  741. {
  742. ScanThread.Abort();
  743. }
  744. if (EDSThread != null)
  745. {
  746. EDSThread.Abort();
  747. }
  748. if (tabSetting.SelectedIndex == 0)
  749. {
  750. EDSInit();
  751. }
  752. }
  753. catch (Exception)
  754. {
  755. }
  756. }
  757. private void btnSaveImage_Click(object sender, EventArgs e)
  758. {
  759. if (bitmap != null)
  760. {
  761. string fileName = LogPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpeg";
  762. bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  763. }
  764. }
  765. private void btnPointXRay_Click(object sender, EventArgs e)
  766. {
  767. GetPointXRay();
  768. }
  769. protected void GetPointXRay()
  770. {
  771. try
  772. {
  773. string str = table["str1"].ToString();
  774. btnDisplayXRay.Enabled = false;
  775. btnDisplayXRay.Refresh();
  776. btnPointXRay.Text = str;
  777. btnPointXRay.Enabled = false;
  778. btnPointXRay.Refresh();
  779. btnAreaRay.Enabled = false;
  780. btnAreaRay.Refresh();
  781. btnClearData.Enabled = false;
  782. btnClearData.Refresh();
  783. InitXRayData();
  784. if (ConnectionSem(connectionEnumType.EDSMultiPointXRay))
  785. {
  786. if (EDSInit())
  787. {
  788. //图像数据
  789. uint[] a_XrayData = new uint[2000];
  790. uint a_Milliseconds = 0;
  791. //采集时间
  792. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  793. //采集XRay数据
  794. List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
  795. for (int i = 0; i < 5; i++)
  796. {
  797. COTSParticleClr cOTSParticle = new COTSParticleClr();
  798. CPosXrayClr cPosXray = new CPosXrayClr();
  799. cOTSParticle.SetXray(cPosXray);
  800. cOTSParticle.SetXRayPos(new Point(100 + i, 100 + i));
  801. cOTSParticleClrs.Add(cOTSParticle);
  802. }
  803. m_EDSHardwareMgr.SetResolution(int.Parse(tbRWidth.Text), int.Parse(tbRHeight.Text));
  804. bool result=m_EDSHardwareMgr.GetXRayByParts(cOTSParticleClrs, a_Milliseconds, false);
  805. if(!result)
  806. {
  807. log.Error("m_EDSHardwareMgr.GetXRayByPoints failed!");
  808. }
  809. int[] XData = new int[2000];
  810. uint nXrayCount = 0;
  811. for (int j = 0; j < 5; j++)
  812. {
  813. a_XrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
  814. for (int i = 1; i <= 2000; i++)
  815. {
  816. XData[i - 1] = i;
  817. nXrayCount += a_XrayData[i - 1];
  818. }
  819. }
  820. //绑定数据源
  821. chartData(XData, a_XrayData);
  822. //显示Xray计数
  823. lbXrayCount.Text = nXrayCount.ToString();
  824. }
  825. }
  826. log.Info("Multipoint collection succeeded!");
  827. }
  828. catch (Exception ex)
  829. {
  830. //记录日志
  831. log.Error(ex.Message.ToString());
  832. }
  833. finally
  834. {
  835. string str = table["btnpointxray"].ToString();
  836. btnPointXRay.Text = str;
  837. btnPointXRay.Enabled = true;
  838. btnPointXRay.Refresh();
  839. btnDisplayXRay.Enabled = true;
  840. btnDisplayXRay.Refresh();
  841. btnAreaRay.Enabled = true;
  842. btnAreaRay.Refresh();
  843. btnClearData.Enabled = true;
  844. btnClearData.Refresh();
  845. }
  846. }
  847. private void btnAreaRay_Click(object sender, EventArgs e)
  848. {
  849. try
  850. {
  851. string str = table["str1"].ToString();
  852. btnDisplayXRay.Enabled = false;
  853. btnDisplayXRay.Refresh();
  854. btnPointXRay.Enabled = false;
  855. btnPointXRay.Refresh();
  856. btnAreaRay.Text = str;
  857. btnAreaRay.Enabled = false;
  858. btnAreaRay.Refresh();
  859. btnClearData.Enabled = false;
  860. btnClearData.Refresh();
  861. InitXRayData();
  862. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  863. {
  864. if (EDSInit())
  865. {
  866. //图像数据
  867. uint[] a_XrayData = new uint[2000];
  868. uint a_Milliseconds = 0;
  869. //采集时间
  870. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  871. //采集XRay数据
  872. var fea = new COTSFeatureClr();
  873. var segs = new List<COTSSegmentClr>();
  874. segs.Add(new COTSSegmentClr(5, 10, 12));
  875. segs.Add(new COTSSegmentClr(6, 10, 12));
  876. segs.Add(new COTSSegmentClr(7, 10, 12));
  877. fea.SetSegmentsList(segs, false);
  878. string ele = "";
  879. //设置图像分辨率
  880. int width = 0;
  881. int height = 0;
  882. //获取宽度
  883. //width = Convert.ToInt32(tbRWidth.Text);
  884. //height = Convert.ToInt32(tbRHeight.Text);
  885. //m_EDSHardwareMgr.SetResolution(width, height);
  886. bool isTrue = GetXRayBySingleFeature(a_Milliseconds, fea, ref a_XrayData,ref ele, false);
  887. int[] XData = new int[2000];
  888. uint nXrayCount = 0;
  889. for (int i = 1; i <= 2000; i++)
  890. {
  891. XData[i - 1] = i;
  892. nXrayCount += a_XrayData[i - 1];
  893. }
  894. //绑定数据源
  895. chartData(XData, a_XrayData);
  896. //显示Xray计数
  897. lbXrayCount.Text = nXrayCount.ToString();
  898. }
  899. }
  900. }
  901. catch (Exception ex)
  902. {
  903. //记录日志
  904. log.Error(ex.Message.ToString());
  905. }
  906. finally
  907. {
  908. string str = table["btnarearay"].ToString();
  909. btnPointXRay.Enabled = true;
  910. btnPointXRay.Refresh();
  911. btnDisplayXRay.Enabled = true;
  912. btnDisplayXRay.Refresh();
  913. btnAreaRay.Text = str;
  914. btnAreaRay.Enabled = true;
  915. btnAreaRay.Refresh();
  916. btnClearData.Enabled = true;
  917. btnClearData.Refresh();
  918. }
  919. }
  920. public bool GetXRayBySingleFeature(uint a_nXRayAQTime, COTSFeatureClr fea, ref uint[] a_XrayData, ref string ele, bool a_bElementInfo)
  921. {
  922. var eds = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text),Convert.ToInt32(tbRHeight.Text),5000,true,"");
  923. var part = new COTSParticleClr();
  924. part.SetFeature(fea);
  925. var parts = new List<COTSParticleClr>();
  926. parts.Add(part);
  927. eds.GetXRayByFeatures(parts, a_nXRayAQTime, a_bElementInfo);
  928. a_XrayData = parts[0].GetXray().GetXrayData();
  929. ele = parts[0].GetXray().GetQuantifiedElementsStr();
  930. return true;
  931. }
  932. private void btnClearData_Click(object sender, EventArgs e)
  933. {
  934. try
  935. {
  936. InitXRayData();
  937. }
  938. catch (Exception ex)
  939. {
  940. //记录日志
  941. log.Error(ex.Message.ToString());
  942. }
  943. }
  944. public void InitXRayData()
  945. {
  946. try
  947. {
  948. //图像数据
  949. uint[] a_XrayData = new uint[2000];
  950. uint a_Milliseconds = 0;
  951. //采集时间
  952. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  953. //采集XRay数据
  954. int[] XData = new int[2000];
  955. uint nXrayCount = 0;
  956. for (int i = 1; i <= 2000; i++)
  957. {
  958. XData[i - 1] = i;
  959. nXrayCount += a_XrayData[i - 1];
  960. }
  961. //绑定数据源
  962. chartData(XData, a_XrayData);
  963. //显示Xray计数
  964. lbXrayCount.Text = nXrayCount.ToString();
  965. ConnectionState = false;
  966. log.Info("Cleared successfully!");
  967. }
  968. catch (Exception ex)
  969. {
  970. //记录日志
  971. log.Error(ex.Message.ToString());
  972. }
  973. }
  974. #region 获取元素分析
  975. private void btnEanalysis_Click(object sender, EventArgs e)
  976. {
  977. try
  978. {
  979. string str = table["str1"].ToString();
  980. btnDisplayXRay.Enabled = false;
  981. btnDisplayXRay.Refresh();
  982. btnPointXRay.Enabled = false;
  983. btnPointXRay.Refresh();
  984. btnAreaRay.Enabled = false;
  985. btnAreaRay.Refresh();
  986. btnEanalysis.Text = str;
  987. btnEanalysis.Enabled = false;
  988. btnEanalysis.Refresh();
  989. btnClearData.Enabled = false;
  990. btnClearData.Refresh();
  991. InitXRayData();
  992. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  993. {
  994. if (EDSInit())
  995. {
  996. //图像数据
  997. uint[] a_XrayData = new uint[2000];
  998. uint a_Milliseconds = 0;
  999. //采集时间
  1000. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  1001. //采集元素分析数据
  1002. ValueType a_nElementNum = 0;
  1003. string a_strResult = string.Empty;
  1004. try
  1005. {
  1006. GetXRayElements(a_Milliseconds, ref a_XrayData, ref a_nElementNum, ref a_strResult);
  1007. }
  1008. catch (Exception ex)
  1009. {
  1010. log.Error("ControllerSettingForm_btnEanalysis_Click:--GetXRayElements()_Exception" + ex.Message.ToString());
  1011. }
  1012. uint[] XData = new uint[2000];
  1013. uint nXrayCount = 0;
  1014. for (int i = 1; i <= 2000; i++)
  1015. {
  1016. XData[i - 1] = (uint)i;
  1017. nXrayCount += a_XrayData[i - 1];
  1018. }
  1019. //绑定数据源
  1020. chartDataWithEle(a_XrayData, a_strResult);
  1021. //显示Xray计数
  1022. lbXrayCount.Text = nXrayCount.ToString();
  1023. //显示元素分析结果内容
  1024. ShowXRayElementResultForm showXRayElementResultForm = new ShowXRayElementResultForm((int)a_nElementNum, a_strResult);
  1025. showXRayElementResultForm.ShowDialog();
  1026. }
  1027. }
  1028. log.Info("Element analysis success!");
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. //记录日志
  1033. log.Error(ex.Message.ToString());
  1034. }
  1035. finally
  1036. {
  1037. string str = table["btneanalysis"].ToString();
  1038. btnPointXRay.Enabled = true;
  1039. btnPointXRay.Refresh();
  1040. btnDisplayXRay.Enabled = true;
  1041. btnDisplayXRay.Refresh();
  1042. btnAreaRay.Enabled = true;
  1043. btnAreaRay.Refresh();
  1044. btnEanalysis.Text = str;
  1045. btnEanalysis.Enabled = true;
  1046. btnEanalysis.Refresh();
  1047. btnClearData.Enabled = true;
  1048. btnClearData.Refresh();
  1049. }
  1050. }
  1051. public bool GetXRayElements(uint a_nXRayAQTime, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
  1052. {
  1053. var eds = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
  1054. var part = new COTSParticleClr();
  1055. var pos = new Point(10, 10);
  1056. part.SetXRayPos(pos);
  1057. var parts = new List<COTSParticleClr>();
  1058. parts.Add(part);
  1059. eds.GetXRayByParts(parts, a_nXRayAQTime, true);
  1060. a_XrayData = parts[0].GetXray().GetXrayData();
  1061. a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
  1062. a_nElementNum = parts[0].GetXray().GetElementQuantifyData().Count;
  1063. return true;
  1064. }
  1065. #endregion
  1066. bool ReadConfigXml(string xmlpath,ref string xAxisDir,ref string yAxisDir,ref string scanFieldSize)
  1067. {
  1068. try
  1069. {
  1070. XmlDocument xmlDocument = new XmlDocument();
  1071. xmlDocument.Load(xmlpath);
  1072. XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
  1073. foreach (XmlNode xn in nodeList)
  1074. {
  1075. XmlElement xe = (XmlElement)xn;
  1076. if (xe.GetAttribute("RegName") == "StageData")
  1077. {
  1078. scanFieldSize=xe.GetAttribute("scanFieldSize");
  1079. xAxisDir=xe.GetAttribute("xAxisDir");
  1080. yAxisDir=xe.GetAttribute("yAxisDir");
  1081. break;
  1082. }
  1083. }
  1084. }
  1085. catch (Exception ex)
  1086. {
  1087. MessageBox.Show(ex.ToString());
  1088. return false;
  1089. }
  1090. return true;
  1091. }
  1092. bool SaveConfigXml(string xmlpath, string xAxisDir, string yAxisDir, string scanFieldSize)
  1093. {
  1094. try
  1095. {
  1096. XmlDocument xmlDocument = new XmlDocument();
  1097. xmlDocument.Load(xmlpath);
  1098. XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
  1099. foreach (XmlNode xn in nodeList)
  1100. {
  1101. XmlElement xe = (XmlElement)xn;
  1102. if (xe.GetAttribute("RegName") == "StageData")
  1103. {
  1104. xe.SetAttribute("scanFieldSize", scanFieldSize);
  1105. xe.SetAttribute("xAxisDir", xAxisDir);
  1106. xe.SetAttribute("yAxisDir", yAxisDir);
  1107. break;
  1108. }
  1109. }
  1110. xmlDocument.Save(xmlpath);
  1111. }
  1112. catch (Exception ex)
  1113. {
  1114. MessageBox.Show(ex.ToString());
  1115. return false;
  1116. }
  1117. return true;
  1118. }
  1119. }
  1120. }