ControllerSettingForm.cs 40 KB

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