ControllerSettingForm.cs 43 KB

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