ControllerSettingForm.cs 40 KB

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