ControllerSettingForm.cs 40 KB

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