123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Xml;
- using System.IO;
- using System.Windows.Forms.DataVisualization.Charting;
- using System.Threading;
- using System.Collections;
- using System.Collections.Generic;
- using OTSCLRINTERFACE;
- using OTSModelSharp.ServiceCenter;
- using System.Drawing.Drawing2D;
- using OTSPeriodicTable;
- namespace OTSSysMgrApp
- {
- public partial class ControllerSettingForm : Form
- {
- #region 全部变量声明
- RecommendedConfiguration recommendedConfiguration;
- //连接状态
- bool ConnectionState = false;
- static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
- //日志路径
- static string LogPath = System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ConnectionString;
- static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
-
- IEDSController m_EDSHardwareMgr = null;
- //图片
- Bitmap bitmap = null;
- //国际化
- Language lan;
- //国际化存储信息
- Hashtable table;
- #endregion
- public enum connectionEnumType
- {
- EDSOnlyPointXRay = 0,
- EDSMultiPointXRay = 1,
- EDSAreaXRay = 2,
- ScanImage = 3
- }
- #region 构造函数
- public ControllerSettingForm()
- {
- InitializeComponent();
- m_EDSHardwareMgr = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- }
-
- /// <summary>
- /// 连接电镜
- /// </summary>
- /// <param name="connectionType"></param>
- public bool ConnectionSem(connectionEnumType connectionType)
- {
-
-
- //连接电镜标识
- bool DisConnResult = false;
- //判断连接状态
- if (!ConnectionState)
- {
- //连接电镜设置
- DisConnResult = m_EDSHardwareMgr.Connect();
- }
- if (DisConnResult)
- {
- ConnectionState = true;
- }
- else
- {
- ConnectionState = false;
- }
- return DisConnResult;
- }
-
- /// <summary>
- /// EDS初始化
- /// </summary>
- public bool EDSInit()
- {
- bool initResult = false;
- //线程调用 加载
- initResult = m_EDSHardwareMgr.Connect();
- return initResult;
- }
-
- #endregion
- #region 窗体中控件事件汇总
- private void btnClearXRay_Click(object sender, EventArgs e)
- {
-
- }
- private void btnCollectionTime_Click(object sender, EventArgs e)
- {
- try
- {
- int CollectionTime = 0;
- //判断是否为空与类型
- if (!IsNull(tbCollectionTime))
- {
- tbCollectionTime.Focus();
- return;
- }
- if (!IsType(tbCollectionTime.Text, 1))
- {
- tbCollectionTime.Focus();
- return;
- }
- //获取参数与设置参数
- CollectionTime = Convert.ToInt32(tbCollectionTime.Text);
- bool result = false;
- if (result)
- {
- //配置结果提示
- ShowMessage(3);
- }
- else
- {
- ShowMessage(4);
- }
- }
- catch (Exception ex)
- {
- //记录日志信息(异常日志)
- log.Error(ex.Message.ToString());
- }
- }
- private void ControllerSettingForm_Load(object sender, EventArgs e)
- {
- //设置窗体图表
- Control.CheckForIllegalCrossThreadCalls = false;
- ddlDwellTime.SelectedIndex = 0;
- this.control_XRayTable1 = new Control_XRayTable();
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.None;
- this.control_XRayTable1.List_ShowElementInfo = null;
- this.control_XRayTable1.Location = new System.Drawing.Point(groupBox1.Location.X, groupBox1.Location.Y);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.Size = new System.Drawing.Size(groupBox1.Width-20, groupBox1.Height);
- this.control_XRayTable1.TabIndex = 6;
- this.control_XRayTable1.Visible = true;
- InitXRayData();
- int width = Convert.ToInt32(tbRWidth.Text);
- int height = Convert.ToInt32(tbRHeight.Text);
- m_EDSHardwareMgr = EDSController.GetEDSController(width, height, 5000,true,"");
- groupBox1.Controls.Add(this.control_XRayTable1);
- }
- Thread ScanThread = null;
- private void btnDisplay_Click(object sender, EventArgs e)
- {
- GetBSEDisplay();
- }
- private bool GetScanImage(int iWidth, int iHeigh, string DwellTime, ref byte[] bImageData)
- {
-
- //电镜设置对象
- var scan = ScanController.GetScanController();
- int GetImgCount = 0;
- try
- {
- //连接电镜
- bool IsConnec = scan.Init();
- if (!IsConnec)
- {
- return false;
- }
-
- #region 设置图像分辨率
- //设置宽度
- if (!scan.SetImageSize(iWidth, iHeigh))
- {
- return false;
- }
- #endregion
- #region 采集时间
- //采集时间
- DwellTimeLevel nDwellTime=DwellTimeLevel.Low;
- switch (DwellTime)
- {
- case "Low":
- nDwellTime = DwellTimeLevel.Low;
- break;
- case "Medium":
- nDwellTime = DwellTimeLevel.Medium;
- break;
- case "High":
- nDwellTime = DwellTimeLevel.High;
- break;
-
- }
- //设置采集时间
- if (!scan.SetDwellTime(nDwellTime))
- {
- return false;
- }
- #endregion
- int resultCount = iWidth * iHeigh;
- var img = scan.AcquireBSEImage();
- bImageData = img.GetImageDataPtr();
- }
- catch (Exception ex)
- {
- NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
- return false;
- }
- return true;
-
- }
- protected void GetBSEDisplay()
- {
- try
- {
- string str1 = table["str1"].ToString();
- btnDisplay.Text = str1;
- btnDisplay.Enabled = false;
- btnDisplay.Refresh();
- if (pbImage.Image != null)
- {
- pbImage.Image = null;
- pbImage.Refresh();
- }
- Thread.Sleep(100);
-
- //设置图像分辨率
- int width = 0;
- int height = 0;
- //获取宽度
- width = Convert.ToInt32(tbRWidth.Text);
- height = Convert.ToInt32(tbRHeight.Text);
- byte[] ImageByte = new byte[width * height];
- Bitmap bitmap = null;
- int iWidth = Convert.ToInt32(tbRWidth.Text);
- int iHeight = Convert.ToInt32(tbRHeight.Text);
- bool resultValue = GetScanImage(iWidth, iHeight, ddlDwellTime.Text, ref ImageByte);
- string str2 = table["str2"].ToString();
- if (resultValue )
- {
- if (ImageByte != null)
- {
- bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
- pbImage.Image = bitmap;
- btnSaveImage.Enabled = true;
- log.Info("Image capture success!\nImage resolution:" + tbRWidth.Text + "X" + tbRHeight.Text + ";");
- }
- else
- {
- MessageBox.Show(str2, "Tip");
- }
- }
- else
- {
- MessageBox.Show(str2, "Tip");
- }
-
-
- }
- catch (Exception ex)
- {
- log.Error("ControllerSettingForm_btnDisplay_Click--错误信息:" + ex.ToString());
- }
- finally
- {
- string str = table["btndisplay"].ToString();
- btnDisplay.Text = str;
- btnDisplay.Enabled = true;
- btnDisplay.Refresh();
- }
- }
- private void btnClear_Click(object sender, EventArgs e)
- {
- pbImage.BackgroundImage = null;
- }
- Thread EDSThread = null;
- private void btnDisplayXRay_Click(object sender, EventArgs e)
- {
- try
- {
- string str1 = table["str1"].ToString();
- btnDisplayXRay.Text = str1;
- btnDisplayXRay.Enabled = false;
- btnDisplayXRay.Refresh();
- btnPointXRay.Enabled = false;
- btnPointXRay.Refresh();
- btnAreaRay.Enabled = false;
- btnAreaRay.Refresh();
- btnClearData.Enabled = false;
- btnClearData.Refresh();
- InitXRayData();
- if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
- {
- if (EDSInit())
- {
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集XRay数据
- bool result = m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
- if (!result)
- {
- log.Info("CollectSpectrum failed!");
- }
- int[] XData = new int[2000];
- uint nXrayCount = 0;
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = i;
- nXrayCount += a_XrayData[i - 1];
- }
- //绑定数据源
- chartData(XData, a_XrayData);
- //显示Xray计数
- lbXrayCount.Text = nXrayCount.ToString();
- }
- }
- log.Info("Single point collection succeeded!");
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- finally
- {
- string str = table["btndisplayxray"].ToString();
- btnDisplayXRay.Text = str;
- btnDisplayXRay.Enabled = true;
- btnDisplayXRay.Refresh();
- btnPointXRay.Enabled = true;
- btnPointXRay.Refresh();
- btnAreaRay.Enabled = true;
- btnAreaRay.Refresh();
- btnClearData.Enabled = true;
- btnClearData.Refresh();
-
- }
- }
-
-
- public void RunEDSThread()
- {
- try
- {
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集XRay数据
- m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
- int[] XData = new int[2000];
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = i;
- }
- //绑定数据源
- chartData(XData, a_XrayData);
-
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- }
-
-
-
- public void chartDataWithEle(uint[] YData, string elestr)
- {
- List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
- string[] ele = elestr.Split('\n');
- for (int i = 0; i < ele.Length-1; i++)
- {
- string[] inf = ele[i].Split(':');
- ShowElementInfo ls_sei = new ShowElementInfo();
- ls_sei.ElementName = inf[0];
- ls_sei.Percentage = Convert.ToDouble(inf[1]);
- ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
- double de_sx2 = 0;
- if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
- {
- de_sx2 = 0;
- }
- else
- {
- de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
- }
- ls_sei.dLF = de_sx2;
- list_showelementinfo.Add(ls_sei);
- }
- list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
-
- control_XRayTable1.SetXRayShowLineValue(YData, list_showelementinfo);
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- Invalidate();
- }
- public void chartData(int[] XData, uint[] YData)
- {
- control_XRayTable1.Visible = true;
- control_XRayTable1.SetXRayShowLineValue(YData, null);
- Invalidate();
- }
- #endregion
- #region 设置按钮事件
- private void btnSetInfo_Click(object sender, EventArgs e)
- {
- if (!IsConnection())
- {
- //return;
- }
- //获取响应按钮
- Button btnTest = (Button)sender;
- try
- {
- //节点名称与节点参数值
- string Name = string.Empty;
- string Value = string.Empty;
- //判断本地中是否存在文件路径
- if (ExistsFile(xmlFilePath))
- {
- //遍历tabHardwareSet标签中所有的TextBox控件
- foreach (Control control in this.tabXRay.Controls)
- {
- //判断类型名称
- if (control is TextBox)
- {
- Name = (control as TextBox).Name.Substring(2);
- if (btnTest.Name.Contains(Name))
- {
- //判断是否为空与类型
- if (!IsNull(((TextBox)control)))
- {
- ((TextBox)control).Focus();
- return;
- }
- if (!IsType(((TextBox)control).Text, 1))
- {
- ((TextBox)control).Focus();
- return;
- }
- //获取节点名称与节点参数值
- Value = (control as TextBox).Text;
- SaveSetting(Name, Value);
- }
- }
- }
- //遍历tabHardwareSet标签中所有的TextBox控件
- foreach (Control control in this.tabImage.Controls)
- {
- //判断类型名称
- if (control is TextBox)
- {
- Name = (control as TextBox).Name.Substring(2);
- if (btnTest.Name.Contains(Name))
- {
- //判断是否为空与类型
- if (!IsNull(((TextBox)control)))
- {
- ((TextBox)control).Focus();
- return;
- }
- if (!IsType(((TextBox)control).Text, 1))
- {
- ((TextBox)control).Focus();
- return;
- }
- //获取节点名称与节点参数值
- Value = (control as TextBox).Text;
- SaveSetting(Name, Value);
- }
- }
- }
- }
- else
- {
- //如果文件不存在,则创建文件
- CreateFile(xmlFilePath);
- }
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- }
- }
- #endregion
- #region 保存设置
- /// <summary>
- /// 保存设置
- /// </summary>
- /// <param name="Name">节点名称</param>
- /// <param name="Value">节点参数值</param>
- public void SaveSetting(string Name, string Value)
- {
- try
- {
- //判断XML文件中是否存在
- if (!XMLOperationClass.ExistsXmlInfo(Name))
- {
- //调用添加XML节点功能
- XMLOperationClass.AddXmlInfo(Name, Value);
- }
- else
- {
- //调用修改XML节点功能
- XMLOperationClass.EditXmlInfo(Name, Value);
- }
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- }
- }
- #endregion
- #region 修改设置
- public void EditSetting(string Name, string Value)
- {
- try
- {
- //调用修改XML节点功能
- XMLOperationClass.EditXmlInfo(Name, Value);
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- }
- }
- #endregion
- #region 判断文件路径
- /// <summary>
- /// 判断文件路径
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- public bool CreateFile(string path)
- {
- Directory.CreateDirectory(path);
- return false;
- }
- #endregion
- #region 判断文件是否存在
- /// <summary>
- /// 判断文件是否存在
- /// </summary>
- /// <param name="path">文件路径</param>
- /// <returns></returns>
- public bool ExistsFile(string path)
- {
- try
- {
- if (File.Exists(path))
- {
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- return false;
- }
- }
- #endregion
- #region 获取窗体中所有参数
- /// <summary>
- /// 获取窗体中控件的所有参数
- /// </summary>
- public void GetWindowsControlValue()
- {
- try
- {
- XmlDocument doc = new XmlDocument();
- //加载Xml文件
- doc.Load(xmlFilePath);
- //获取根节点
- XmlElement root = doc.DocumentElement;
- //获取子节点集合
- XmlNodeList mainNodes = root.GetElementsByTagName("parameter");
- foreach (XmlNode node in mainNodes)
- {
- //获取Name属性值
- string text = ((XmlElement)node).GetAttribute("Name");
- string value = ((XmlElement)node).GetAttribute("Value");
- foreach (Control control in this.tabXRay.Controls)
- {
- //判断类型名称
- if (control.Name.Contains(text))
- {
- if (control is TextBox)
- {
- ((TextBox)control).Text = value;
- }
- else if (control is ComboBox)
- {
- ((ComboBox)control).SelectedValue = value;
- }
- else if (control is CheckBox)
- {
- ((CheckBox)control).Checked = text.Equals("1") ? true : false;
- }
- }
- }
- foreach (Control control in this.tabImage.Controls)
- {
- //判断类型名称
- if (control.Name.Contains(text))
- {
- if (control is TextBox)
- {
- ((TextBox)control).Text = value;
- }
- else if (control is ComboBox)
- {
- ((ComboBox)control).SelectedValue = value;
- }
- else if (control is CheckBox)
- {
- ((CheckBox)control).Checked = text.Equals("1") ? true : false;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- }
- }
- #endregion
- #region 用户信息提示
- /// <summary>
- /// 提示
- /// </summary>
- /// <param name="Message"></param>
- private void ShowMessage(int MessageType)
- {
- string message1 = table["message1"].ToString();
- string message2 = table["message2"].ToString();
- string message3 = table["message3"].ToString();
- string message4 = table["message4"].ToString();
- string message5 = table["message5"].ToString();
- string message6 = table["message6"].ToString();
- string message7 = table["message7"].ToString();
- string message8 = table["message8"].ToString();
- string message9 = table["message9"].ToString();
- string message10 = table["message10"].ToString();
- string MessageInfo = string.Empty;
- switch (MessageType)
- {
- case 0:
- MessageInfo = message1;
- break;
- case 1:
- MessageInfo = message2;
- break;
- case 2:
- MessageInfo = message3;
- break;
- case 3:
- MessageInfo = message4;
- break;
- case 4:
- MessageInfo = message5;
- break;
- case 5:
- MessageInfo = message6;
- break;
- case 6:
- MessageInfo = message7;
- break;
- case 7:
- MessageInfo = message8;
- break;
- case 8:
- MessageInfo = message9;
- break;
- case 9:
- MessageInfo = message10;
- break;
- }
- MessageBox.Show(MessageInfo, "Tip");
- }
- #endregion
- #region 判断控制内容是否为空 与 判断输入的格式是否正确
- /// <summary>
- /// 判断控制内容是否为空
- /// </summary>
- /// <param name="tbContent"></param>
- /// <returns></returns>
- public bool IsNull(TextBox tbContent)
- {
- if (tbContent.Text.Trim().Equals(""))
- {
- //为空提示
- ShowMessage(0);
- //获取焦点
- tbContent.Focus();
- return false;
- }
- return true;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="objValue"></param>
- /// <param name="objType"></param>
- /// <returns></returns>
- public bool IsType(object ObjValue, int ObjType)
- {
- try
- {
- switch (ObjType)
- {
- case 1:
- int intValue = Convert.ToInt32(ObjValue);
- break;
- case 2:
- double douValue = Convert.ToDouble(ObjValue);
- break;
- case 3:
- float floValue = Convert.ToSingle(ObjValue);
- break;
- }
- return true;
- }
- catch (Exception)
- {
- //为空提示
- ShowMessage(7);
- return false;
- }
- }
- /// <summary>
- /// 判断是否连接
- /// </summary>
- /// <returns></returns>
- public bool IsConnection()
- {
-
- if (ConnectionState)
- {
- return true;
- }
- return false;
-
- }
- #endregion
- private void ControllerSettingForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- if (ScanThread != null)
- {
- ScanThread.Abort();
- }
- if (EDSThread != null)
- {
- EDSThread.Abort();
- }
- if (tabSetting.SelectedIndex == 0)
- {
-
- EDSInit();
- }
-
- }
- catch (Exception)
- {
- }
- }
- private void btnSaveImage_Click(object sender, EventArgs e)
- {
- if (bitmap != null)
- {
- string fileName = LogPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpeg";
- bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- private void btnPointXRay_Click(object sender, EventArgs e)
- {
- GetPointXRay();
- }
- protected void GetPointXRay()
- {
- try
- {
- string str = table["str1"].ToString();
- btnDisplayXRay.Enabled = false;
- btnDisplayXRay.Refresh();
- btnPointXRay.Text = str;
- btnPointXRay.Enabled = false;
- btnPointXRay.Refresh();
- btnAreaRay.Enabled = false;
- btnAreaRay.Refresh();
- btnClearData.Enabled = false;
- btnClearData.Refresh();
- InitXRayData();
-
- if (ConnectionSem(connectionEnumType.EDSMultiPointXRay))
- {
- if (EDSInit())
- {
-
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集XRay数据
- List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
- for (int i = 0; i < 5; i++)
- {
- COTSParticleClr cOTSParticle = new COTSParticleClr();
- CPosXrayClr cPosXray = new CPosXrayClr();
- cOTSParticle.SetXray(cPosXray);
- cOTSParticle.SetXRayPos(new Point(100 + i, 100 + i));
- cOTSParticleClrs.Add(cOTSParticle);
- }
- m_EDSHardwareMgr.SetResolution(int.Parse(tbRWidth.Text), int.Parse(tbRHeight.Text));
- bool result=m_EDSHardwareMgr.GetXRayByParts(cOTSParticleClrs, a_Milliseconds, false);
- if(!result)
- {
- log.Error("m_EDSHardwareMgr.GetXRayByPoints failed!");
- }
- int[] XData = new int[2000];
- uint nXrayCount = 0;
- for (int j = 0; j < 5; j++)
- {
- a_XrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = i;
- nXrayCount += a_XrayData[i - 1];
- }
- }
- //绑定数据源
- chartData(XData, a_XrayData);
- //显示Xray计数
- lbXrayCount.Text = nXrayCount.ToString();
- }
- }
- log.Info("Multipoint collection succeeded!");
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- finally
- {
- string str = table["btnpointxray"].ToString();
- btnPointXRay.Text = str;
- btnPointXRay.Enabled = true;
- btnPointXRay.Refresh();
- btnDisplayXRay.Enabled = true;
- btnDisplayXRay.Refresh();
- btnAreaRay.Enabled = true;
- btnAreaRay.Refresh();
- btnClearData.Enabled = true;
- btnClearData.Refresh();
-
- }
- }
- private void btnAreaRay_Click(object sender, EventArgs e)
- {
- try
- {
- string str = table["str1"].ToString();
- btnDisplayXRay.Enabled = false;
- btnDisplayXRay.Refresh();
- btnPointXRay.Enabled = false;
- btnPointXRay.Refresh();
- btnAreaRay.Text = str;
- btnAreaRay.Enabled = false;
- btnAreaRay.Refresh();
- btnClearData.Enabled = false;
- btnClearData.Refresh();
- InitXRayData();
- if (ConnectionSem(connectionEnumType.EDSAreaXRay))
- {
- if (EDSInit())
- {
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集XRay数据
- var fea = new COTSFeatureClr();
- var segs = new List<COTSSegmentClr>();
- segs.Add(new COTSSegmentClr(5, 10, 12));
- segs.Add(new COTSSegmentClr(6, 10, 12));
- segs.Add(new COTSSegmentClr(7, 10, 12));
- fea.SetSegmentsList(segs, false);
- string ele = "";
- //设置图像分辨率
- int width = 0;
- int height = 0;
- //获取宽度
- //width = Convert.ToInt32(tbRWidth.Text);
- //height = Convert.ToInt32(tbRHeight.Text);
- //m_EDSHardwareMgr.SetResolution(width, height);
- bool isTrue = GetXRayBySingleFeature(a_Milliseconds, fea, ref a_XrayData,ref ele, false);
- int[] XData = new int[2000];
- uint nXrayCount = 0;
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = i;
- nXrayCount += a_XrayData[i - 1];
- }
- //绑定数据源
- chartData(XData, a_XrayData);
- //显示Xray计数
- lbXrayCount.Text = nXrayCount.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- finally
- {
- string str = table["btnarearay"].ToString();
- btnPointXRay.Enabled = true;
- btnPointXRay.Refresh();
- btnDisplayXRay.Enabled = true;
- btnDisplayXRay.Refresh();
- btnAreaRay.Text = str;
- btnAreaRay.Enabled = true;
- btnAreaRay.Refresh();
- btnClearData.Enabled = true;
- btnClearData.Refresh();
- }
- }
- public bool GetXRayBySingleFeature(uint a_nXRayAQTime, COTSFeatureClr fea, ref uint[] a_XrayData, ref string ele, bool a_bElementInfo)
- {
-
- var eds = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text),Convert.ToInt32(tbRHeight.Text),5000,true,"");
- var part = new COTSParticleClr();
- part.SetFeature(fea);
- var parts = new List<COTSParticleClr>();
- parts.Add(part);
- eds.GetXRayByFeatures(parts, a_nXRayAQTime, a_bElementInfo);
- a_XrayData = parts[0].GetXray().GetXrayData();
- ele = parts[0].GetXray().GetQuantifiedElementsStr();
- return true;
- }
-
- private void btnClearData_Click(object sender, EventArgs e)
- {
- try
- {
- InitXRayData();
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- }
- public void InitXRayData()
- {
- try
- {
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集XRay数据
- int[] XData = new int[2000];
- uint nXrayCount = 0;
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = i;
- nXrayCount += a_XrayData[i - 1];
- }
- //绑定数据源
- chartData(XData, a_XrayData);
- //显示Xray计数
- lbXrayCount.Text = nXrayCount.ToString();
-
- ConnectionState = false;
- log.Info("Cleared successfully!");
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- }
- #region 获取元素分析
- private void btnEanalysis_Click(object sender, EventArgs e)
- {
- try
- {
- string str = table["str1"].ToString();
- btnDisplayXRay.Enabled = false;
- btnDisplayXRay.Refresh();
- btnPointXRay.Enabled = false;
- btnPointXRay.Refresh();
- btnAreaRay.Enabled = false;
- btnAreaRay.Refresh();
- btnEanalysis.Text = str;
- btnEanalysis.Enabled = false;
- btnEanalysis.Refresh();
- btnClearData.Enabled = false;
- btnClearData.Refresh();
- InitXRayData();
- if (ConnectionSem(connectionEnumType.EDSAreaXRay))
- {
- if (EDSInit())
- {
- //图像数据
- uint[] a_XrayData = new uint[2000];
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
- //采集元素分析数据
- ValueType a_nElementNum = 0;
- string a_strResult = string.Empty;
- try
- {
- GetXRayElements(a_Milliseconds, ref a_XrayData, ref a_nElementNum, ref a_strResult);
- }
- catch (Exception ex)
- {
- log.Error("ControllerSettingForm_btnEanalysis_Click:--GetXRayElements()_Exception" + ex.Message.ToString());
- }
- uint[] XData = new uint[2000];
- uint nXrayCount = 0;
- for (int i = 1; i <= 2000; i++)
- {
- XData[i - 1] = (uint)i;
- nXrayCount += a_XrayData[i - 1];
- }
- //绑定数据源
- chartDataWithEle(a_XrayData, a_strResult);
- //显示Xray计数
- lbXrayCount.Text = nXrayCount.ToString();
- //显示元素分析结果内容
- ShowXRayElementResultForm showXRayElementResultForm = new ShowXRayElementResultForm((int)a_nElementNum, a_strResult);
- showXRayElementResultForm.ShowDialog();
- }
- }
- log.Info("Element analysis success!");
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- finally
- {
- string str = table["btneanalysis"].ToString();
- btnPointXRay.Enabled = true;
- btnPointXRay.Refresh();
- btnDisplayXRay.Enabled = true;
- btnDisplayXRay.Refresh();
- btnAreaRay.Enabled = true;
- btnAreaRay.Refresh();
- btnEanalysis.Text = str;
- btnEanalysis.Enabled = true;
- btnEanalysis.Refresh();
- btnClearData.Enabled = true;
- btnClearData.Refresh();
-
- }
- }
- public bool GetXRayElements(uint a_nXRayAQTime, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
- {
-
- var eds = EDSController.GetEDSController(Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
- var part = new COTSParticleClr();
- var pos = new Point(10, 10);
- part.SetXRayPos(pos);
- var parts = new List<COTSParticleClr>();
- parts.Add(part);
- eds.GetXRayByParts(parts, a_nXRayAQTime, true);
- a_XrayData = parts[0].GetXray().GetXrayData();
- a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
- a_nElementNum = parts[0].GetXray().GetElementQuantifyData().Count;
- return true;
- }
- #endregion
-
- bool ReadConfigXml(string xmlpath,ref string xAxisDir,ref string yAxisDir,ref string scanFieldSize)
- {
- try
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load(xmlpath);
- XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
- foreach (XmlNode xn in nodeList)
- {
- XmlElement xe = (XmlElement)xn;
- if (xe.GetAttribute("RegName") == "StageData")
- {
- scanFieldSize=xe.GetAttribute("scanFieldSize");
- xAxisDir=xe.GetAttribute("xAxisDir");
- yAxisDir=xe.GetAttribute("yAxisDir");
- break;
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return false;
- }
- return true;
- }
- bool SaveConfigXml(string xmlpath, string xAxisDir, string yAxisDir, string scanFieldSize)
- {
- try
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load(xmlpath);
- XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
- foreach (XmlNode xn in nodeList)
- {
- XmlElement xe = (XmlElement)xn;
- if (xe.GetAttribute("RegName") == "StageData")
- {
- xe.SetAttribute("scanFieldSize", scanFieldSize);
- xe.SetAttribute("xAxisDir", xAxisDir);
- xe.SetAttribute("yAxisDir", yAxisDir);
- break;
- }
- }
- xmlDocument.Save(xmlpath);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return false;
- }
- return true;
- }
- }
- }
|