ControllerSettingForm.cs 41 KB

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