ControllerSettingForm.cs 49 KB

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