ControllerSettingForm.cs 41 KB

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