ControllerSettingForm.cs 47 KB

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