ControllerSettingForm.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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 = Imagepro.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 = Imagepro.ToGrayBitmap(ImageByte, width, height);
  244. pbImage.Image = bitmap;
  245. btnSaveImage.Enabled = true;
  246. log.Info("Image capture success!\nImage resolution:" + tbRWidth.Text + "X" + tbRHeight.Text + ";");
  247. }
  248. else
  249. {
  250. MessageBox.Show(str2, "Tip");
  251. }
  252. }
  253. else
  254. {
  255. MessageBox.Show(str2, "Tip");
  256. }
  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. }
  949. catch (Exception ex)
  950. {
  951. //记录日志
  952. log.Error(ex.Message.ToString());
  953. }
  954. finally
  955. {
  956. string str = table["btnarearay"].ToString();
  957. btnPointXRay.Enabled = true;
  958. btnPointXRay.Refresh();
  959. btnDisplayXRay.Enabled = true;
  960. btnDisplayXRay.Refresh();
  961. btnAreaRay.Text = str;
  962. btnAreaRay.Enabled = true;
  963. btnAreaRay.Refresh();
  964. btnClearData.Enabled = true;
  965. btnClearData.Refresh();
  966. //EDS过程结束
  967. //cfun.EDSFinishedInstance();
  968. //关闭连接
  969. //DisConnectSem(connectionEnumType.EDSAreaXRay);
  970. }
  971. }
  972. private void btnClearData_Click(object sender, EventArgs e)
  973. {
  974. try
  975. {
  976. InitXRayData();
  977. }
  978. catch (Exception ex)
  979. {
  980. //记录日志
  981. log.Error(ex.Message.ToString());
  982. }
  983. }
  984. public void InitXRayData()
  985. {
  986. try
  987. {
  988. //图像数据
  989. uint[] a_XrayData = new uint[2000];
  990. uint a_Milliseconds = 0;
  991. //采集时间
  992. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  993. //采集XRay数据
  994. int[] XData = new int[2000];
  995. uint nXrayCount = 0;
  996. for (int i = 1; i <= 2000; i++)
  997. {
  998. XData[i - 1] = i;
  999. nXrayCount += a_XrayData[i - 1];
  1000. }
  1001. //绑定数据源
  1002. chartData(XData, a_XrayData);
  1003. //显示Xray计数
  1004. lbXrayCount.Text = nXrayCount.ToString();
  1005. chartXRay.Refresh();
  1006. //EDS过程结束
  1007. //cfun.EDSFinishedInstance();
  1008. ConnectionState = false;
  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. }