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