ControllerSettingForm.cs 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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. if (!m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData))
  307. {
  308. log.Info("CollectSpectrum failed!");
  309. }
  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. m_EDSHardwareMgr.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. m_EDSHardwareMgr.DisConnect();
  776. }
  777. catch (Exception ex)
  778. {
  779. //记录日志信息
  780. log.Error(ex.ToString());
  781. }
  782. }
  783. private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
  784. {
  785. try
  786. {
  787. if (ScanThread != null)
  788. {
  789. ScanThread.Abort();
  790. }
  791. if (EDSThread != null)
  792. {
  793. EDSThread.Abort();
  794. }
  795. if (tabSetting.SelectedIndex == 0)
  796. {
  797. //线程调用 关闭Scan EDSInit初始化
  798. //cfun.ScanFinishedInstance();
  799. EDSInit();
  800. }
  801. else if (tabSetting.SelectedIndex == 1)
  802. {
  803. //线程调用 关闭EDS ScanInit初始化
  804. //cfun.EDSFinishedInstance();
  805. ScanInit();
  806. }
  807. }
  808. catch (Exception)
  809. {
  810. }
  811. }
  812. private void btnSaveImage_Click(object sender, EventArgs e)
  813. {
  814. if (bitmap != null)
  815. {
  816. string fileName = LogPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpeg";
  817. bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  818. }
  819. }
  820. private void btnPointXRay_Click(object sender, EventArgs e)
  821. {
  822. GetPointXRay();
  823. //var act = new Action(GetPointXRay);
  824. //act.BeginInvoke(ar => act.EndInvoke(ar), null);
  825. }
  826. protected void GetPointXRay()
  827. {
  828. try
  829. {
  830. string str = table["str1"].ToString();
  831. btnDisplayXRay.Enabled = false;
  832. btnDisplayXRay.Refresh();
  833. btnPointXRay.Text = str;
  834. btnPointXRay.Enabled = false;
  835. btnPointXRay.Refresh();
  836. btnAreaRay.Enabled = false;
  837. btnAreaRay.Refresh();
  838. btnClearData.Enabled = false;
  839. btnClearData.Refresh();
  840. InitXRayData();
  841. if (ConnectionSem(connectionEnumType.EDSMultiPointXRay))
  842. {
  843. if (EDSInit())
  844. {
  845. //图像数据
  846. uint[] a_XrayData = new uint[2000];
  847. uint a_Milliseconds = 0;
  848. //采集时间
  849. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  850. //采集XRay数据
  851. List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
  852. for (int i = 0; i < 5; i++)
  853. {
  854. COTSParticleClr cOTSParticle = new COTSParticleClr();
  855. CPosXrayClr cPosXray = new CPosXrayClr();
  856. cOTSParticle.SetXray(cPosXray);
  857. cOTSParticle.SetXRayPos(new Point(100 + i, 100 + i));
  858. cOTSParticleClrs.Add(cOTSParticle);
  859. }
  860. m_EDSHardwareMgr.SetResolution(int.Parse(tbRWidth.Text), int.Parse(tbRHeight.Text));
  861. m_EDSHardwareMgr.GetXRayByPoints(cOTSParticleClrs, a_Milliseconds, false);
  862. int[] XData = new int[2000];
  863. uint nXrayCount = 0;
  864. for (int j = 0; j < 5; j++)
  865. {
  866. a_XrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
  867. for (int i = 1; i <= 2000; i++)
  868. {
  869. XData[i - 1] = i;
  870. nXrayCount += a_XrayData[i - 1];
  871. }
  872. }
  873. //绑定数据源
  874. chartData(XData, a_XrayData);
  875. //显示Xray计数
  876. lbXrayCount.Text = nXrayCount.ToString();
  877. }
  878. }
  879. log.Info("Multipoint collection succeeded!");
  880. }
  881. catch (Exception ex)
  882. {
  883. //记录日志
  884. log.Error(ex.Message.ToString());
  885. }
  886. finally
  887. {
  888. string str = table["btnpointxray"].ToString();
  889. btnPointXRay.Text = str;
  890. btnPointXRay.Enabled = true;
  891. btnPointXRay.Refresh();
  892. btnDisplayXRay.Enabled = true;
  893. btnDisplayXRay.Refresh();
  894. btnAreaRay.Enabled = true;
  895. btnAreaRay.Refresh();
  896. btnClearData.Enabled = true;
  897. btnClearData.Refresh();
  898. //EDS过程结束
  899. //cfun.EDSFinishedInstance();
  900. //关闭连接
  901. DisConnectSem(connectionEnumType.EDSMultiPointXRay);
  902. }
  903. }
  904. private void btnAreaRay_Click(object sender, EventArgs e)
  905. {
  906. GetAreaRay();
  907. }
  908. protected void GetAreaRay()
  909. {
  910. try
  911. {
  912. string str = table["str1"].ToString();
  913. btnDisplayXRay.Enabled = false;
  914. btnDisplayXRay.Refresh();
  915. btnPointXRay.Enabled = false;
  916. btnPointXRay.Refresh();
  917. btnAreaRay.Text = str;
  918. btnAreaRay.Enabled = false;
  919. btnAreaRay.Refresh();
  920. btnClearData.Enabled = false;
  921. btnClearData.Refresh();
  922. InitXRayData();
  923. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  924. {
  925. if (EDSInit())
  926. {
  927. //图像数据
  928. uint[] a_XrayData = new uint[2000];
  929. uint a_Milliseconds = 0;
  930. //采集时间
  931. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  932. //采集XRay数据
  933. var fea = new COTSFeatureClr();
  934. var segs = new List<COTSSegmentClr>();
  935. segs.Add(new COTSSegmentClr(5, 10, 12));
  936. segs.Add(new COTSSegmentClr(6, 10, 12));
  937. segs.Add(new COTSSegmentClr(7, 10, 12));
  938. fea.SetSegmentsList(segs,false);
  939. string ele = "";
  940. //设置图像分辨率
  941. int width = 0;
  942. int height = 0;
  943. //获取宽度
  944. width = Convert.ToInt32(tbRWidth.Text);
  945. height = Convert.ToInt32(tbRHeight.Text);
  946. m_EDSHardwareMgr.SetResolution(width, height);
  947. bool isTrue = m_EDSHardwareMgr.GetXRayBySingleFeature(a_Milliseconds, fea, ref a_XrayData,ref ele, false);
  948. int[] XData = new int[2000];
  949. uint nXrayCount = 0;
  950. for (int i = 1; i <= 2000; i++)
  951. {
  952. XData[i - 1] = i;
  953. nXrayCount += a_XrayData[i - 1];
  954. }
  955. //绑定数据源
  956. chartData(XData, a_XrayData);
  957. //显示Xray计数
  958. lbXrayCount.Text = nXrayCount.ToString();
  959. }
  960. }
  961. }
  962. catch (Exception ex)
  963. {
  964. //记录日志
  965. log.Error(ex.Message.ToString());
  966. }
  967. finally
  968. {
  969. string str = table["btnarearay"].ToString();
  970. btnPointXRay.Enabled = true;
  971. btnPointXRay.Refresh();
  972. btnDisplayXRay.Enabled = true;
  973. btnDisplayXRay.Refresh();
  974. btnAreaRay.Text = str;
  975. btnAreaRay.Enabled = true;
  976. btnAreaRay.Refresh();
  977. btnClearData.Enabled = true;
  978. btnClearData.Refresh();
  979. //EDS过程结束
  980. //cfun.EDSFinishedInstance();
  981. //关闭连接
  982. DisConnectSem(connectionEnumType.EDSAreaXRay);
  983. }
  984. }
  985. private void btnClearData_Click(object sender, EventArgs e)
  986. {
  987. try
  988. {
  989. InitXRayData();
  990. }
  991. catch (Exception ex)
  992. {
  993. //记录日志
  994. log.Error(ex.Message.ToString());
  995. }
  996. }
  997. public void InitXRayData()
  998. {
  999. try
  1000. {
  1001. //图像数据
  1002. uint[] a_XrayData = new uint[2000];
  1003. uint a_Milliseconds = 0;
  1004. //采集时间
  1005. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  1006. //采集XRay数据
  1007. int[] XData = new int[2000];
  1008. uint nXrayCount = 0;
  1009. for (int i = 1; i <= 2000; i++)
  1010. {
  1011. XData[i - 1] = i;
  1012. nXrayCount += a_XrayData[i - 1];
  1013. }
  1014. //绑定数据源
  1015. chartData(XData, a_XrayData);
  1016. //显示Xray计数
  1017. lbXrayCount.Text = nXrayCount.ToString();
  1018. chartXRay.Refresh();
  1019. //EDS过程结束
  1020. //cfun.EDSFinishedInstance();
  1021. ConnectionState = false;
  1022. log.Info("Cleared successfully!");
  1023. }
  1024. catch (Exception ex)
  1025. {
  1026. //记录日志
  1027. log.Error(ex.Message.ToString());
  1028. }
  1029. }
  1030. #region 获取元素分析
  1031. private void btnEanalysis_Click(object sender, EventArgs e)
  1032. {
  1033. GetEanalysis();
  1034. }
  1035. protected void GetEanalysis()
  1036. {
  1037. try
  1038. {
  1039. string str = table["str1"].ToString();
  1040. btnDisplayXRay.Enabled = false;
  1041. btnDisplayXRay.Refresh();
  1042. btnPointXRay.Enabled = false;
  1043. btnPointXRay.Refresh();
  1044. btnAreaRay.Enabled = false;
  1045. btnAreaRay.Refresh();
  1046. btnEanalysis.Text = str;
  1047. btnEanalysis.Enabled = false;
  1048. btnEanalysis.Refresh();
  1049. btnClearData.Enabled = false;
  1050. btnClearData.Refresh();
  1051. InitXRayData();
  1052. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  1053. {
  1054. if (EDSInit())
  1055. {
  1056. //图像数据
  1057. uint[] a_XrayData = new uint[2000];
  1058. uint a_Milliseconds = 0;
  1059. //采集时间
  1060. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  1061. //采集元素分析数据
  1062. ValueType a_nElementNum = 0;
  1063. string a_strResult = string.Empty;
  1064. try
  1065. {
  1066. m_EDSHardwareMgr.GetXRayElements(a_Milliseconds, ref a_XrayData, ref a_nElementNum, ref a_strResult);
  1067. }
  1068. catch (Exception ex)
  1069. {
  1070. log.Error("ControllerSettingForm_btnEanalysis_Click:--GetXRayElements()_Exception" + ex.Message.ToString());
  1071. }
  1072. int[] XData = new int[2000];
  1073. uint nXrayCount = 0;
  1074. for (int i = 1; i <= 2000; i++)
  1075. {
  1076. XData[i - 1] = i;
  1077. nXrayCount += a_XrayData[i - 1];
  1078. }
  1079. //绑定数据源
  1080. chartData(XData, a_XrayData);
  1081. //显示Xray计数
  1082. lbXrayCount.Text = nXrayCount.ToString();
  1083. //显示元素分析结果内容
  1084. ShowXRayElementResultForm showXRayElementResultForm = new ShowXRayElementResultForm((int)a_nElementNum, a_strResult);
  1085. showXRayElementResultForm.ShowDialog();
  1086. }
  1087. }
  1088. log.Info("Element analysis success!");
  1089. }
  1090. catch (Exception ex)
  1091. {
  1092. //记录日志
  1093. log.Error(ex.Message.ToString());
  1094. }
  1095. finally
  1096. {
  1097. string str = table["btneanalysis"].ToString();
  1098. btnPointXRay.Enabled = true;
  1099. btnPointXRay.Refresh();
  1100. btnDisplayXRay.Enabled = true;
  1101. btnDisplayXRay.Refresh();
  1102. btnAreaRay.Enabled = true;
  1103. btnAreaRay.Refresh();
  1104. btnEanalysis.Text = str;
  1105. btnEanalysis.Enabled = true;
  1106. btnEanalysis.Refresh();
  1107. btnClearData.Enabled = true;
  1108. btnClearData.Refresh();
  1109. //EDS过程结束
  1110. //cfun.EDSFinishedInstance();
  1111. //关闭连接
  1112. DisConnectSem(connectionEnumType.EDSAreaXRay);
  1113. }
  1114. }
  1115. #endregion
  1116. }
  1117. }