ControllerSettingForm.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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.ServiceInterface;
  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:" + tbRWidth.Text + "X" + tbRHeight.Text + ";");
  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. m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  307. int[] XData = new int[2000];
  308. uint nXrayCount = 0;
  309. for (int i = 1; i <= 2000; i++)
  310. {
  311. XData[i - 1] = i;
  312. nXrayCount += a_XrayData[i - 1];
  313. }
  314. //绑定数据源
  315. chartData(XData, a_XrayData);
  316. //显示Xray计数
  317. lbXrayCount.Text = nXrayCount.ToString();
  318. }
  319. }
  320. log.Info("Single point collection succeeded!");
  321. }
  322. catch (Exception ex)
  323. {
  324. //记录日志
  325. log.Error(ex.Message.ToString());
  326. }
  327. finally
  328. {
  329. string str = table["btndisplayxray"].ToString();
  330. btnDisplayXRay.Text = str;
  331. btnDisplayXRay.Enabled = true;
  332. btnDisplayXRay.Refresh();
  333. btnPointXRay.Enabled = true;
  334. btnPointXRay.Refresh();
  335. btnAreaRay.Enabled = true;
  336. btnAreaRay.Refresh();
  337. btnClearData.Enabled = true;
  338. btnClearData.Refresh();
  339. //EDS过程结束
  340. //cfun.EDSFinishedInstance();
  341. //关闭连接
  342. DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
  343. }
  344. }
  345. public void RunEDSThread()
  346. {
  347. try
  348. {
  349. //图像数据
  350. uint[] a_XrayData = new uint[2000];
  351. uint a_Milliseconds = 0;
  352. //采集时间
  353. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  354. //采集XRay数据
  355. m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  356. int[] XData = new int[2000];
  357. for (int i = 1; i <= 2000; i++)
  358. {
  359. XData[i - 1] = i;
  360. }
  361. //绑定数据源
  362. chartData(XData, a_XrayData);
  363. //EDS过程结束
  364. //cfun.EDSFinishedInstance();
  365. }
  366. catch (Exception ex)
  367. {
  368. //记录日志
  369. log.Error(ex.Message.ToString());
  370. }
  371. }
  372. public void chartData(int[] XData, uint[] YData)
  373. {
  374. //chartXRay = new Chart();
  375. //背景
  376. if (chartXRay.ChartAreas.Count == 0)
  377. {
  378. chartXRay.ChartAreas.Add(new ChartArea() { Name = "" }); //背景框
  379. }
  380. chartXRay.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
  381. chartXRay.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
  382. chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //网格类型 短横线
  383. chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Gray;
  384. chartXRay.ChartAreas[0].Axes[0].MajorTickMark.Enabled = false; // x轴上突出的小点
  385. chartXRay.ChartAreas[0].Axes[1].MajorTickMark.Enabled = false; //
  386. chartXRay.ChartAreas[0].Axes[1].MajorGrid.LineWidth = 1;
  387. //图表数据区,有多个重叠则循环添加
  388. if (chartXRay.Series.Count == 0)
  389. {
  390. chartXRay.Series.Add(new Series() { Name = "" });
  391. }
  392. chartXRay.Series[0].ChartType = SeriesChartType.Line; //图类型(折线)
  393. chartXRay.Series[0].Points.DataBindXY(XData, YData); //添加数据
  394. chartXRay.Series[0].Label = "";
  395. chartXRay.Series[0].LegendText = "";
  396. //折线段配置
  397. chartXRay.Series[0].Color = Color.Blue; //线条颜色
  398. chartXRay.Series[0].BorderWidth = 1; //线条粗细
  399. chartXRay.Series[0].MarkerBorderColor = Color.Red; //标记点边框颜色
  400. chartXRay.Series[0].MarkerBorderWidth = 1; //标记点边框大小
  401. chartXRay.Series[0].MarkerColor = Color.Red; //标记点中心颜色
  402. chartXRay.Series[0].MarkerSize = 0; //标记点大小
  403. //chartXRay.Series[0].BorderWidth = 500;
  404. //另外
  405. //饼图说明设置,这用来设置饼图每一块的信息显示在什么地方
  406. chartXRay.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
  407. chartXRay.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
  408. //柱状图其他设置
  409. chartXRay.Series[0]["DrawingStyle"] = "Emboss"; //设置柱状平面形状
  410. chartXRay.Series[0]["PointWidth"] = "0.1"; //设置柱状大小
  411. }
  412. #endregion
  413. #region 设置按钮事件
  414. private void btnSetInfo_Click(object sender, EventArgs e)
  415. {
  416. if (!IsConnection())
  417. {
  418. //return;
  419. }
  420. //获取响应按钮
  421. Button btnTest = (Button)sender;
  422. try
  423. {
  424. //节点名称与节点参数值
  425. string Name = string.Empty;
  426. string Value = string.Empty;
  427. //判断本地中是否存在文件路径
  428. if (ExistsFile(xmlFilePath))
  429. {
  430. //遍历tabHardwareSet标签中所有的TextBox控件
  431. foreach (Control control in this.tabXRay.Controls)
  432. {
  433. //判断类型名称
  434. if (control is TextBox)
  435. {
  436. Name = (control as TextBox).Name.Substring(2);
  437. if (btnTest.Name.Contains(Name))
  438. {
  439. //判断是否为空与类型
  440. if (!IsNull(((TextBox)control)))
  441. {
  442. ((TextBox)control).Focus();
  443. return;
  444. }
  445. if (!IsType(((TextBox)control).Text, 1))
  446. {
  447. ((TextBox)control).Focus();
  448. return;
  449. }
  450. //获取节点名称与节点参数值
  451. Value = (control as TextBox).Text;
  452. SaveSetting(Name, Value);
  453. }
  454. }
  455. }
  456. //遍历tabHardwareSet标签中所有的TextBox控件
  457. foreach (Control control in this.tabImage.Controls)
  458. {
  459. //判断类型名称
  460. if (control is TextBox)
  461. {
  462. Name = (control as TextBox).Name.Substring(2);
  463. if (btnTest.Name.Contains(Name))
  464. {
  465. //判断是否为空与类型
  466. if (!IsNull(((TextBox)control)))
  467. {
  468. ((TextBox)control).Focus();
  469. return;
  470. }
  471. if (!IsType(((TextBox)control).Text, 1))
  472. {
  473. ((TextBox)control).Focus();
  474. return;
  475. }
  476. //获取节点名称与节点参数值
  477. Value = (control as TextBox).Text;
  478. SaveSetting(Name, Value);
  479. }
  480. }
  481. }
  482. }
  483. else
  484. {
  485. //如果文件不存在,则创建文件
  486. CreateFile(xmlFilePath);
  487. }
  488. }
  489. catch (Exception ex)
  490. {
  491. //记录日志信息
  492. log.Error(ex.Message.ToString());
  493. }
  494. }
  495. #endregion
  496. #region 保存设置
  497. /// <summary>
  498. /// 保存设置
  499. /// </summary>
  500. /// <param name="Name">节点名称</param>
  501. /// <param name="Value">节点参数值</param>
  502. public void SaveSetting(string Name, string Value)
  503. {
  504. try
  505. {
  506. //判断XML文件中是否存在
  507. if (!XMLOperationClass.ExistsXmlInfo(Name))
  508. {
  509. //调用添加XML节点功能
  510. XMLOperationClass.AddXmlInfo(Name, Value);
  511. }
  512. else
  513. {
  514. //调用修改XML节点功能
  515. XMLOperationClass.EditXmlInfo(Name, Value);
  516. }
  517. }
  518. catch (Exception ex)
  519. {
  520. //记录日志信息
  521. log.Error(ex.Message.ToString());
  522. }
  523. }
  524. #endregion
  525. #region 修改设置
  526. public void EditSetting(string Name, string Value)
  527. {
  528. try
  529. {
  530. //调用修改XML节点功能
  531. XMLOperationClass.EditXmlInfo(Name, Value);
  532. }
  533. catch (Exception ex)
  534. {
  535. //记录日志信息
  536. log.Error(ex.Message.ToString());
  537. }
  538. }
  539. #endregion
  540. #region 判断文件路径
  541. /// <summary>
  542. /// 判断文件路径
  543. /// </summary>
  544. /// <param name="path"></param>
  545. /// <returns></returns>
  546. public bool CreateFile(string path)
  547. {
  548. Directory.CreateDirectory(path);
  549. return false;
  550. }
  551. #endregion
  552. #region 判断文件是否存在
  553. /// <summary>
  554. /// 判断文件是否存在
  555. /// </summary>
  556. /// <param name="path">文件路径</param>
  557. /// <returns></returns>
  558. public bool ExistsFile(string path)
  559. {
  560. try
  561. {
  562. if (File.Exists(path))
  563. {
  564. return true;
  565. }
  566. return false;
  567. }
  568. catch (Exception ex)
  569. {
  570. //记录日志信息
  571. log.Error(ex.Message.ToString());
  572. return false;
  573. }
  574. }
  575. #endregion
  576. #region 获取窗体中所有参数
  577. /// <summary>
  578. /// 获取窗体中控件的所有参数
  579. /// </summary>
  580. public void GetWindowsControlValue()
  581. {
  582. try
  583. {
  584. XmlDocument doc = new XmlDocument();
  585. //加载Xml文件
  586. doc.Load(xmlFilePath);
  587. //获取根节点
  588. XmlElement root = doc.DocumentElement;
  589. //获取子节点集合
  590. XmlNodeList mainNodes = root.GetElementsByTagName("parameter");
  591. foreach (XmlNode node in mainNodes)
  592. {
  593. //获取Name属性值
  594. string text = ((XmlElement)node).GetAttribute("Name");
  595. string value = ((XmlElement)node).GetAttribute("Value");
  596. foreach (Control control in this.tabXRay.Controls)
  597. {
  598. //判断类型名称
  599. if (control.Name.Contains(text))
  600. {
  601. if (control is TextBox)
  602. {
  603. ((TextBox)control).Text = value;
  604. }
  605. else if (control is ComboBox)
  606. {
  607. ((ComboBox)control).SelectedValue = value;
  608. }
  609. else if (control is CheckBox)
  610. {
  611. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  612. }
  613. }
  614. }
  615. foreach (Control control in this.tabImage.Controls)
  616. {
  617. //判断类型名称
  618. if (control.Name.Contains(text))
  619. {
  620. if (control is TextBox)
  621. {
  622. ((TextBox)control).Text = value;
  623. }
  624. else if (control is ComboBox)
  625. {
  626. ((ComboBox)control).SelectedValue = value;
  627. }
  628. else if (control is CheckBox)
  629. {
  630. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  631. }
  632. }
  633. }
  634. }
  635. }
  636. catch (Exception ex)
  637. {
  638. //记录日志信息
  639. log.Error(ex.Message.ToString());
  640. }
  641. }
  642. #endregion
  643. #region 用户信息提示
  644. /// <summary>
  645. /// 提示
  646. /// </summary>
  647. /// <param name="Message"></param>
  648. private void ShowMessage(int MessageType)
  649. {
  650. string message1 = table["message1"].ToString();
  651. string message2 = table["message2"].ToString();
  652. string message3 = table["message3"].ToString();
  653. string message4 = table["message4"].ToString();
  654. string message5 = table["message5"].ToString();
  655. string message6 = table["message6"].ToString();
  656. string message7 = table["message7"].ToString();
  657. string message8 = table["message8"].ToString();
  658. string message9 = table["message9"].ToString();
  659. string message10 = table["message10"].ToString();
  660. string MessageInfo = string.Empty;
  661. switch (MessageType)
  662. {
  663. case 0:
  664. MessageInfo = message1;
  665. break;
  666. case 1:
  667. MessageInfo = message2;
  668. break;
  669. case 2:
  670. MessageInfo = message3;
  671. break;
  672. case 3:
  673. MessageInfo = message4;
  674. break;
  675. case 4:
  676. MessageInfo = message5;
  677. break;
  678. case 5:
  679. MessageInfo = message6;
  680. break;
  681. case 6:
  682. MessageInfo = message7;
  683. break;
  684. case 7:
  685. MessageInfo = message8;
  686. break;
  687. case 8:
  688. MessageInfo = message9;
  689. break;
  690. case 9:
  691. MessageInfo = message10;
  692. break;
  693. }
  694. MessageBox.Show(MessageInfo, "Tip");
  695. }
  696. #endregion
  697. #region 判断控制内容是否为空 与 判断输入的格式是否正确
  698. /// <summary>
  699. /// 判断控制内容是否为空
  700. /// </summary>
  701. /// <param name="tbContent"></param>
  702. /// <returns></returns>
  703. public bool IsNull(TextBox tbContent)
  704. {
  705. if (tbContent.Text.Trim().Equals(""))
  706. {
  707. //为空提示
  708. ShowMessage(0);
  709. //获取焦点
  710. tbContent.Focus();
  711. return false;
  712. }
  713. return true;
  714. }
  715. /// <summary>
  716. ///
  717. /// </summary>
  718. /// <param name="objValue"></param>
  719. /// <param name="objType"></param>
  720. /// <returns></returns>
  721. public bool IsType(object ObjValue, int ObjType)
  722. {
  723. try
  724. {
  725. switch (ObjType)
  726. {
  727. case 1:
  728. int intValue = Convert.ToInt32(ObjValue);
  729. break;
  730. case 2:
  731. double douValue = Convert.ToDouble(ObjValue);
  732. break;
  733. case 3:
  734. float floValue = Convert.ToSingle(ObjValue);
  735. break;
  736. }
  737. return true;
  738. }
  739. catch (Exception)
  740. {
  741. //为空提示
  742. ShowMessage(7);
  743. return false;
  744. }
  745. }
  746. /// <summary>
  747. /// 判断是否连接
  748. /// </summary>
  749. /// <returns></returns>
  750. public bool IsConnection()
  751. {
  752. try
  753. {
  754. if (ConnectionState)
  755. {
  756. return true;
  757. }
  758. return false;
  759. }
  760. catch (Exception)
  761. {
  762. //为空提示
  763. ShowMessage(7);
  764. return false;
  765. }
  766. }
  767. #endregion
  768. private void ControllerSettingForm_FormClosing(object sender, FormClosingEventArgs e)
  769. {
  770. try
  771. {
  772. m_EDSHardwareMgr.DisConnect();
  773. }
  774. catch (Exception ex)
  775. {
  776. //记录日志信息
  777. log.Error(ex.ToString());
  778. }
  779. }
  780. private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
  781. {
  782. try
  783. {
  784. if (ScanThread != null)
  785. {
  786. ScanThread.Abort();
  787. }
  788. if (EDSThread != null)
  789. {
  790. EDSThread.Abort();
  791. }
  792. if (tabSetting.SelectedIndex == 0)
  793. {
  794. //线程调用 关闭Scan EDSInit初始化
  795. //cfun.ScanFinishedInstance();
  796. EDSInit();
  797. }
  798. else if (tabSetting.SelectedIndex == 1)
  799. {
  800. //线程调用 关闭EDS ScanInit初始化
  801. //cfun.EDSFinishedInstance();
  802. ScanInit();
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. }
  808. }
  809. private void btnSaveImage_Click(object sender, EventArgs e)
  810. {
  811. if (bitmap != null)
  812. {
  813. string fileName = LogPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpeg";
  814. bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  815. }
  816. }
  817. private void btnPointXRay_Click(object sender, EventArgs e)
  818. {
  819. GetPointXRay();
  820. //var act = new Action(GetPointXRay);
  821. //act.BeginInvoke(ar => act.EndInvoke(ar), null);
  822. }
  823. protected void GetPointXRay()
  824. {
  825. try
  826. {
  827. string str = table["str1"].ToString();
  828. btnDisplayXRay.Enabled = false;
  829. btnDisplayXRay.Refresh();
  830. btnPointXRay.Text = str;
  831. btnPointXRay.Enabled = false;
  832. btnPointXRay.Refresh();
  833. btnAreaRay.Enabled = false;
  834. btnAreaRay.Refresh();
  835. btnClearData.Enabled = false;
  836. btnClearData.Refresh();
  837. InitXRayData();
  838. if (ConnectionSem(connectionEnumType.EDSMultiPointXRay))
  839. {
  840. if (EDSInit())
  841. {
  842. //图像数据
  843. uint[] a_XrayData = new uint[2000];
  844. uint a_Milliseconds = 0;
  845. //采集时间
  846. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  847. //采集XRay数据
  848. List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
  849. for (int i = 0; i < 5; i++)
  850. {
  851. COTSParticleClr cOTSParticle = new COTSParticleClr();
  852. CPosXrayClr cPosXray = new CPosXrayClr();
  853. cOTSParticle.SetXray(cPosXray);
  854. cOTSParticle.SetXRayPos(new Point(100 + i, 100 + i));
  855. cOTSParticleClrs.Add(cOTSParticle);
  856. }
  857. m_EDSHardwareMgr.SetResolution(int.Parse(tbRWidth.Text), int.Parse(tbRHeight.Text));
  858. m_EDSHardwareMgr.GetXRayByPoints(cOTSParticleClrs, a_Milliseconds, false);
  859. int[] XData = new int[2000];
  860. uint nXrayCount = 0;
  861. for (int j = 0; j < 5; j++)
  862. {
  863. a_XrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
  864. for (int i = 1; i <= 2000; i++)
  865. {
  866. XData[i - 1] = i;
  867. nXrayCount += a_XrayData[i - 1];
  868. }
  869. }
  870. //绑定数据源
  871. chartData(XData, a_XrayData);
  872. //显示Xray计数
  873. lbXrayCount.Text = nXrayCount.ToString();
  874. }
  875. }
  876. log.Info("Multipoint collection succeeded!");
  877. }
  878. catch (Exception ex)
  879. {
  880. //记录日志
  881. log.Error(ex.Message.ToString());
  882. }
  883. finally
  884. {
  885. string str = table["btnpointxray"].ToString();
  886. btnPointXRay.Text = str;
  887. btnPointXRay.Enabled = true;
  888. btnPointXRay.Refresh();
  889. btnDisplayXRay.Enabled = true;
  890. btnDisplayXRay.Refresh();
  891. btnAreaRay.Enabled = true;
  892. btnAreaRay.Refresh();
  893. btnClearData.Enabled = true;
  894. btnClearData.Refresh();
  895. //EDS过程结束
  896. //cfun.EDSFinishedInstance();
  897. //关闭连接
  898. DisConnectSem(connectionEnumType.EDSMultiPointXRay);
  899. }
  900. }
  901. private void btnAreaRay_Click(object sender, EventArgs e)
  902. {
  903. GetAreaRay();
  904. }
  905. protected void GetAreaRay()
  906. {
  907. try
  908. {
  909. string str = table["str1"].ToString();
  910. btnDisplayXRay.Enabled = false;
  911. btnDisplayXRay.Refresh();
  912. btnPointXRay.Enabled = false;
  913. btnPointXRay.Refresh();
  914. btnAreaRay.Text = str;
  915. btnAreaRay.Enabled = false;
  916. btnAreaRay.Refresh();
  917. btnClearData.Enabled = false;
  918. btnClearData.Refresh();
  919. InitXRayData();
  920. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  921. {
  922. if (EDSInit())
  923. {
  924. //图像数据
  925. uint[] a_XrayData = new uint[2000];
  926. uint a_Milliseconds = 0;
  927. //采集时间
  928. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  929. //采集XRay数据
  930. var fea = new COTSFeatureClr();
  931. var segs = new List<COTSSegmentClr>();
  932. segs.Add(new COTSSegmentClr(5, 10, 12));
  933. segs.Add(new COTSSegmentClr(6, 10, 12));
  934. segs.Add(new COTSSegmentClr(7, 10, 12));
  935. fea.SetSegmentsList(segs,false);
  936. string ele = "";
  937. bool isTrue = m_EDSHardwareMgr.GetXRayBySingleFeature(a_Milliseconds, fea, ref a_XrayData,ref ele, false);
  938. int[] XData = new int[2000];
  939. uint nXrayCount = 0;
  940. for (int i = 1; i <= 2000; i++)
  941. {
  942. XData[i - 1] = i;
  943. nXrayCount += a_XrayData[i - 1];
  944. }
  945. //绑定数据源
  946. chartData(XData, a_XrayData);
  947. //显示Xray计数
  948. lbXrayCount.Text = nXrayCount.ToString();
  949. }
  950. }
  951. }
  952. catch (Exception ex)
  953. {
  954. //记录日志
  955. log.Error(ex.Message.ToString());
  956. }
  957. finally
  958. {
  959. string str = table["btnarearay"].ToString();
  960. btnPointXRay.Enabled = true;
  961. btnPointXRay.Refresh();
  962. btnDisplayXRay.Enabled = true;
  963. btnDisplayXRay.Refresh();
  964. btnAreaRay.Text = str;
  965. btnAreaRay.Enabled = true;
  966. btnAreaRay.Refresh();
  967. btnClearData.Enabled = true;
  968. btnClearData.Refresh();
  969. //EDS过程结束
  970. //cfun.EDSFinishedInstance();
  971. //关闭连接
  972. DisConnectSem(connectionEnumType.EDSAreaXRay);
  973. }
  974. }
  975. private void btnClearData_Click(object sender, EventArgs e)
  976. {
  977. try
  978. {
  979. InitXRayData();
  980. }
  981. catch (Exception ex)
  982. {
  983. //记录日志
  984. log.Error(ex.Message.ToString());
  985. }
  986. }
  987. public void InitXRayData()
  988. {
  989. try
  990. {
  991. //图像数据
  992. uint[] a_XrayData = new uint[2000];
  993. uint a_Milliseconds = 0;
  994. //采集时间
  995. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  996. //采集XRay数据
  997. int[] XData = new int[2000];
  998. uint nXrayCount = 0;
  999. for (int i = 1; i <= 2000; i++)
  1000. {
  1001. XData[i - 1] = i;
  1002. nXrayCount += a_XrayData[i - 1];
  1003. }
  1004. //绑定数据源
  1005. chartData(XData, a_XrayData);
  1006. //显示Xray计数
  1007. lbXrayCount.Text = nXrayCount.ToString();
  1008. chartXRay.Refresh();
  1009. //EDS过程结束
  1010. //cfun.EDSFinishedInstance();
  1011. ConnectionState = false;
  1012. log.Info("Cleared successfully!");
  1013. }
  1014. catch (Exception ex)
  1015. {
  1016. //记录日志
  1017. log.Error(ex.Message.ToString());
  1018. }
  1019. }
  1020. #region 获取元素分析
  1021. private void btnEanalysis_Click(object sender, EventArgs e)
  1022. {
  1023. GetEanalysis();
  1024. }
  1025. protected void GetEanalysis()
  1026. {
  1027. try
  1028. {
  1029. string str = table["str1"].ToString();
  1030. btnDisplayXRay.Enabled = false;
  1031. btnDisplayXRay.Refresh();
  1032. btnPointXRay.Enabled = false;
  1033. btnPointXRay.Refresh();
  1034. btnAreaRay.Enabled = false;
  1035. btnAreaRay.Refresh();
  1036. btnEanalysis.Text = str;
  1037. btnEanalysis.Enabled = false;
  1038. btnEanalysis.Refresh();
  1039. btnClearData.Enabled = false;
  1040. btnClearData.Refresh();
  1041. InitXRayData();
  1042. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  1043. {
  1044. if (EDSInit())
  1045. {
  1046. //图像数据
  1047. uint[] a_XrayData = new uint[2000];
  1048. uint a_Milliseconds = 0;
  1049. //采集时间
  1050. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  1051. //采集元素分析数据
  1052. ValueType a_nElementNum = 0;
  1053. string a_strResult = string.Empty;
  1054. try
  1055. {
  1056. m_EDSHardwareMgr.GetXRayElements(a_Milliseconds, ref a_XrayData, ref a_nElementNum, ref a_strResult);
  1057. }
  1058. catch (Exception ex)
  1059. {
  1060. log.Error("ControllerSettingForm_btnEanalysis_Click:--GetXRayElements()_Exception" + ex.Message.ToString());
  1061. }
  1062. int[] XData = new int[2000];
  1063. uint nXrayCount = 0;
  1064. for (int i = 1; i <= 2000; i++)
  1065. {
  1066. XData[i - 1] = i;
  1067. nXrayCount += a_XrayData[i - 1];
  1068. }
  1069. //绑定数据源
  1070. chartData(XData, a_XrayData);
  1071. //显示Xray计数
  1072. lbXrayCount.Text = nXrayCount.ToString();
  1073. //显示元素分析结果内容
  1074. ShowXRayElementResultForm showXRayElementResultForm = new ShowXRayElementResultForm((int)a_nElementNum, a_strResult);
  1075. showXRayElementResultForm.ShowDialog();
  1076. }
  1077. }
  1078. log.Info("Element analysis success!");
  1079. }
  1080. catch (Exception ex)
  1081. {
  1082. //记录日志
  1083. log.Error(ex.Message.ToString());
  1084. }
  1085. finally
  1086. {
  1087. string str = table["btneanalysis"].ToString();
  1088. btnPointXRay.Enabled = true;
  1089. btnPointXRay.Refresh();
  1090. btnDisplayXRay.Enabled = true;
  1091. btnDisplayXRay.Refresh();
  1092. btnAreaRay.Enabled = true;
  1093. btnAreaRay.Refresh();
  1094. btnEanalysis.Text = str;
  1095. btnEanalysis.Enabled = true;
  1096. btnEanalysis.Refresh();
  1097. btnClearData.Enabled = true;
  1098. btnClearData.Refresh();
  1099. //EDS过程结束
  1100. //cfun.EDSFinishedInstance();
  1101. //关闭连接
  1102. DisConnectSem(connectionEnumType.EDSAreaXRay);
  1103. }
  1104. }
  1105. #endregion
  1106. }
  1107. }