1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480 |
- 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;
- 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);
- 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)
- {
- chartXRay.Series.RemoveAt(0);
- }
- 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;
- InitXRayData();
- int width = Convert.ToInt32(tbRWidth.Text);
- int height = Convert.ToInt32(tbRHeight.Text);
- m_EDSHardwareMgr = EDSController.GetEDSController(width, height, 5000);
- cb_Xdirection.Items.Add("LEFT_TOWARD");
- cb_Xdirection.Items.Add("RIGHT_TOWARD");
- cb_Ydirection.Items.Add("UP_TOWARD");
- cb_Ydirection.Items.Add("DOWN_TOWARD");
- tB_scanFieldSize100.Text = "1270";
- cb_imageresolution.Items.Add("1024*768");
- cb_imageresolution.Items.Add("1024*704");
- cb_imageresolution.Items.Add("1536*1024");
- string xmlpath = Application.StartupPath + @"\Config\SysData\OTSProgMgrParam.pmf";
- string xAxisDir = "";
- string yAxisDir = "";
- string scanFieldSize = "";
- ReadConfigXml(xmlpath, ref xAxisDir, ref yAxisDir, ref scanFieldSize);
- if (xAxisDir.Split(':')[1] == "LEFT_TOWARD")
- {
- cb_Xdirection.SelectedIndex = 0;
- }
- else
- {
- cb_Xdirection.SelectedIndex = 1;
- }
- if (yAxisDir.Split(':')[1] == "UP_TOWARD")
- {
- cb_Ydirection.SelectedIndex = 0;
- }
- else
- {
- cb_Ydirection.SelectedIndex = 1;
- }
- tB_scanFieldSize100.Text = scanFieldSize;
- cb_imageresolution.SelectedIndex = 0;
- InitEvent();
- }
- 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 采集时间
- //采集时间
- int nDwellTime = Convert.ToInt32(DwellTime);
- //设置采集时间
- 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 chartData(int[] XData, uint[] YData)
- {
- //chartXRay = new Chart();
- //背景
- if (chartXRay.ChartAreas.Count == 0)
- {
- chartXRay.ChartAreas.Add(new ChartArea() { Name = "" }); //背景框
- }
- chartXRay.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
- chartXRay.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
- chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //网格类型 短横线
- chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Gray;
- chartXRay.ChartAreas[0].Axes[0].MajorTickMark.Enabled = false; // x轴上突出的小点
- chartXRay.ChartAreas[0].Axes[1].MajorTickMark.Enabled = false; //
- chartXRay.ChartAreas[0].Axes[1].MajorGrid.LineWidth = 1;
- //图表数据区,有多个重叠则循环添加
- if (chartXRay.Series.Count == 0)
- {
- chartXRay.Series.Add(new Series() { Name = "" });
- }
- chartXRay.Series[0].ChartType = SeriesChartType.Line; //图类型(折线)
- chartXRay.Series[0].Points.DataBindXY(XData, YData); //添加数据
- chartXRay.Series[0].Label = "";
- chartXRay.Series[0].LegendText = "";
- //折线段配置
- chartXRay.Series[0].Color = Color.Blue; //线条颜色
- chartXRay.Series[0].BorderWidth = 1; //线条粗细
- chartXRay.Series[0].MarkerBorderColor = Color.Red; //标记点边框颜色
- chartXRay.Series[0].MarkerBorderWidth = 1; //标记点边框大小
- chartXRay.Series[0].MarkerColor = Color.Red; //标记点中心颜色
- chartXRay.Series[0].MarkerSize = 0; //标记点大小
- //chartXRay.Series[0].BorderWidth = 500;
- //另外
- //饼图说明设置,这用来设置饼图每一块的信息显示在什么地方
- chartXRay.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
- chartXRay.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
- //柱状图其他设置
- chartXRay.Series[0]["DrawingStyle"] = "Emboss"; //设置柱状平面形状
- chartXRay.Series[0]["PointWidth"] = "0.1"; //设置柱状大小
- }
- #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);
- 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();
- chartXRay.Refresh();
-
- 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());
- }
- 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();
- //显示元素分析结果内容
- 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);
- 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
- private void btn_continuousshot_Click(object sender, EventArgs e)
- {
- btn_continuousshot.Enabled = false;
- btn_confirm.Enabled = false;
- this.Refresh();
- Graphics g = panel2.CreateGraphics();
- //g.SmoothingMode = SmoothingMode.HighSpeed;
- //g.CompositingQuality = CompositingQuality.HighSpeed;
- g.PixelOffsetMode = PixelOffsetMode.HighQuality;//高质量低速度呈现
- g.SmoothingMode = SmoothingMode.HighQuality;// 指定高质量、低速度呈现。
- g.InterpolationMode = InterpolationMode.NearestNeighbor;
- ISemController m_Sem = SemController.GetSEMController();
- bool flag = m_Sem.Connect();
- //电镜设置对象
- var cfun = ScanController.GetScanController();
- bool IsConnec = cfun.Init();
- double Magnification = 0;
- m_Sem.GetMagnification(ref Magnification);
- //double a_dScanFieldSizeX = 0;
- //double a_dScanFieldSizeY = 0;
- //m_Sem.GetScanFieldSize(ref a_dScanFieldSizeX,ref a_dScanFieldSizeY);
- double scanFieldSize100 = 0;
- double.TryParse(tB_scanFieldSize100.Text, out scanFieldSize100);
- double scanFieldSize = scanFieldSize100 * 100 / Magnification;
- double PositionX = 0;
- double PositionY = 0;
- double PositionR = 0;
- m_Sem.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
- double PositionXO = PositionX;
- double PositionYO = PositionY;
- //double PositionR0 = PositionR;
- int width = 1024;
- int height = 768;
- //设置图像分辨率
- if (cb_imageresolution.Text.Trim() == "")
- {
- MessageBox.Show("imageresolution cannot be null!");
- return;
- }
- else
- {
- width = Convert.ToInt32(cb_imageresolution.Text.Split('*')[0]);
- height = Convert.ToInt32(cb_imageresolution.Text.Split('*')[1]);
- }
- this.Refresh();
- double scanFieldSizeH = scanFieldSize * height / width;
- m_Sem.SetScanExternal(true);
- try
- {
- for (int i = 0; i < 4; i++)
- {
- if (i == 0)
- {
- }
- else if (i == 1)
- {
- switch (cb_Xdirection.SelectedItem.ToString())
- {
- case "RIGHT_TOWARD": PositionX += scanFieldSize; break;
- default: PositionX -= scanFieldSize; break;
- }
- m_Sem.MoveSEMToPoint(PositionX, PositionY);
- }
- else if (i == 2)
- {
- switch (cb_Ydirection.SelectedItem.ToString())
- {
- case "UP_TOWARD": PositionY -= scanFieldSizeH; break;
- default: PositionY += scanFieldSizeH; break;
- }
- m_Sem.MoveSEMToPoint(PositionX, PositionY);
- }
- else
- {
- switch (cb_Xdirection.SelectedItem.ToString())
- {
- case "RIGHT_TOWARD": PositionX -= scanFieldSize; break;
- default: PositionX += scanFieldSize; break;
- }
- m_Sem.MoveSEMToPoint(PositionX, PositionY);
- }
- //Thread.Sleep(50);
- byte[] ImageByte = new byte[width * height];
- bool resultValue = GetScanImage(width, height, "2", ref ImageByte);
- Size size = new Size(panel2.Width / 2, panel2.Height / 2);
- if (resultValue)
- {
- if (ImageByte != null)
- {
- var bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
- switch (i)
- {
- case 0:
- Point point0 = new Point(0,0);
- Rectangle rect0 = new Rectangle(point0,size);
- g.DrawImage(bitmap,rect0);
- break;
- case 1:
- Point point1 = new Point(panel2.Width / 2, 0);
- Rectangle rect1 = new Rectangle(point1, size);
- g.DrawImage(bitmap, rect1);
- break;
- case 2:
- Point point2 = new Point(panel2.Width/2, panel2.Height / 2);
- Rectangle rect2 = new Rectangle(point2, size);
- g.DrawImage(bitmap, rect2);
- break;
- case 3:
- Point point3 = new Point(0, panel2.Height / 2);
- Rectangle rect3 = new Rectangle(point3, size);
- g.DrawImage(bitmap, rect3);
- break;
- }
- //this.Refresh();
- }
- }
- }
- m_Sem.MoveSEMToPoint(PositionXO, PositionYO);
- }
- catch (Exception ex)
- {
- log.Error("continuousshot--错误信息:" + ex.ToString());
- }
- finally
- {
- m_Sem.SetScanExternal(false);
-
- btn_continuousshot.Enabled = true;
- btn_confirm.Enabled = true;
- btn_continuousshot.Refresh();
- g.Dispose();
- }
- }
- 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;
- }
- private void btn_confirm_Click(object sender, EventArgs e)
- {
- double dscanFieldSize100 = 0;
- if (cb_Xdirection.Text.Trim() != null && cb_imageresolution.Text.Trim() != null && cb_Ydirection.Text.Trim() != null && double.TryParse(tB_scanFieldSize100.Text, out dscanFieldSize100))
- {
- string xmlpath = Application.StartupPath + @"\Config\SysData\OTSProgMgrParam.pmf";
- string xAxisDir = "";
- string yAxisDir = "";
- switch (cb_Xdirection.SelectedItem.ToString())
- {
- case "LEFT_TOWARD":
- xAxisDir = "0:LEFT_TOWARD";
- break;
- default:
- xAxisDir = "1:RIGHT_TOWARD";
- break;
- }
- switch(cb_Ydirection.Text)
- {
- case "UP_TOWARD":
- yAxisDir="0:" + cb_Ydirection.Text;
- break;
- default:
- yAxisDir = "1:DOWN_TOWARD";
- break;
- }
- SaveConfigXml(xmlpath, xAxisDir, yAxisDir, tB_scanFieldSize100.Text);
- }
- else
- {
- MessageBox.Show("Please check params!");
- }
- }
- private void btn_Recommendedconfiguration_Click(object sender, EventArgs e)
- {
- if (recommendedConfiguration == null || recommendedConfiguration.IsDisposed)
- {
- recommendedConfiguration = new RecommendedConfiguration(Language.ReadDefaultLanguage());
- recommendedConfiguration.Show();
- }
- else
- {
- recommendedConfiguration.Activate();
- }
- }
- void DrawFrames()
- {
- Graphics g = panel2.CreateGraphics();
- g.SmoothingMode = SmoothingMode.HighQuality;
- Pen pen = new Pen(Color.Black);
- g.DrawLine(pen,new Point(panel2.Width/2,0),new Point(panel2.Width / 2, panel2.Height));
- g.DrawLine(pen, new Point(0, panel2.Height/2), new Point(panel2.Width, panel2.Height/2));
- pen.Dispose();
- g.Dispose();
- }
- private void panel2_Paint(object sender, PaintEventArgs e)
- {
- DrawFrames();
- }
- void InitEvent()
- {
- string edsType = FileHelper.GetXMLInformations("EDSName");
- string SemType = FileHelper.GetXMLInformations("SemControllerName");
- if (SemType == "FEI")
- {
- if (edsType == "FEI")
- {
- cb_imageresolution.SelectedIndex = 2;
- }
- else if (edsType == "Oxford")
- {
- cb_imageresolution.SelectedIndex = 0;
- }
- else if (edsType == "Bruker")
- {
- cb_imageresolution.SelectedIndex = 1;
- }
- else if (edsType == "OffLine")
- {
- cb_imageresolution.SelectedIndex = 1;
- }
- cb_Xdirection.SelectedIndex = 1;
- cb_Ydirection.SelectedIndex = 0;
- }
- }
- }
- }
|