ControllerSettingForm.cs 49 KB

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