12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163 |
- using System;
- /*
- --创建人:韩维柏
- --创建日期:2017-06-20
- --修改人:
- --修改日期:
- --说明:Xray设置
- */
- 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.ServiceInterface;
- namespace OTSSysMgrApp
- {
- public partial class ControllerSettingForm : Form
- {
- #region 全部变量声明
- //连接状态
- 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();
- //电镜设置对象
- //COTSControlFunExport cfun = null;
- EDSController 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();
- //控制类对象初始化
- //if (cfun == null)
- //{
- // cfun = COTSControlFunExport.GetControllerInstance();
- //}
- m_EDSHardwareMgr = EDSController.GetEDSController();
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- }
- private string GetConnectionType(connectionEnumType connectionType)
- {
- string connString = string.Empty;
- switch (connectionType)
- {
- //设置单点采集文字内容
- case connectionEnumType.EDSOnlyPointXRay:
- connString = "OnlyPointXRay";
- break;
- //设置多点采集文字内容
- case connectionEnumType.EDSMultiPointXRay:
- connString = "MultiPointXRay";
- break;
- //设置面采集文字内容
- case connectionEnumType.EDSAreaXRay:
- connString = "AreaXRay";
- break;
- //设置图片
- case connectionEnumType.ScanImage:
- connString = "Image";
- break;
- default: break;
- }
- return connString;
- }
- /// <summary>
- /// 连接电镜
- /// </summary>
- /// <param name="connectionType"></param>
- public bool ConnectionSem(connectionEnumType connectionType)
- {
- //获取连接电镜类型
- string connTypeStr = GetConnectionType(connectionType);
- //连接电镜标识
- bool DisConnResult = false;
- //判断连接状态
- if (!ConnectionState)
- {
- //连接电镜设置
- DisConnResult = m_EDSHardwareMgr.Connect();
- }
- if (DisConnResult)
- {
- ConnectionState = true;
- }
- else
- {
- ConnectionState = false;
- }
- return DisConnResult;
- }
- /// <summary>
- /// 关闭电镜
- /// </summary>
- /// <param name="disConnectType"></param>
- public bool DisConnectSem(connectionEnumType disConnectType)
- {
- //获取关闭电镜类型
- string connTypeStr = GetConnectionType(disConnectType);
- bool DisConnResult = false;
- //if (ConnectionState)
- // {
- // DisConnResult = cfun.DisConnectSem();
- // }
- // if (DisConnResult)
- // {
- // ConnectionState = false;
- // }
- // else
- // {
- // ConnectionState = true;
- // }
- return DisConnResult;
- }
- /// <summary>
- /// EDS初始化
- /// </summary>
- public bool EDSInit()
- {
- bool initResult = false;
- //线程调用 加载
- initResult = m_EDSHardwareMgr.Init();
- return initResult;
- }
- /// <summary>
- /// Scan初始化
- /// </summary>
- public bool ScanInit()
- {
- bool initResult = false;
- //线程调用 加载
- initResult = m_EDSHardwareMgr.ScanInit();
- 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 = 2;
- InitXRayData();
- m_EDSHardwareMgr = EDSController.GetEDSController();
- }
- Thread ScanThread = null;
- private void btnDisplay_Click(object sender, EventArgs e)
- {
- GetBSEDisplay();
- }
- 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);
- try
- {
- //设置图像分辨率
- 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);
- int resultValue = ScanController.GetScanImage(iWidth, iHeight, ddlDwellTime.Text, ref ImageByte);
- string str2 = table["str2"].ToString();
- if (resultValue > 0)
- {
- 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_GetScanImage()_Exception:-----" + ex.ToString() + "------");
- }
- }
- 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)
- {
- GetDisplayXRay();
- }
- protected void GetDisplayXRay()
- {
- 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数据
- if (!m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData))
- {
- 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();
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
- }
- }
- 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);
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- }
- 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()
- {
- try
- {
- if (ConnectionState)
- {
- return true;
- }
- return false;
- }
- catch (Exception)
- {
- //为空提示
- ShowMessage(7);
- return false;
- }
- }
- #endregion
- private void ControllerSettingForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- m_EDSHardwareMgr.DisConnect();
-
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.ToString());
- }
- }
- private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- if (ScanThread != null)
- {
- ScanThread.Abort();
- }
- if (EDSThread != null)
- {
- EDSThread.Abort();
- }
- if (tabSetting.SelectedIndex == 0)
- {
- //线程调用 关闭Scan EDSInit初始化
- //cfun.ScanFinishedInstance();
- EDSInit();
- }
- else if (tabSetting.SelectedIndex == 1)
- {
- //线程调用 关闭EDS ScanInit初始化
- //cfun.EDSFinishedInstance();
- ScanInit();
- }
- }
- 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();
- //var act = new Action(GetPointXRay);
- //act.BeginInvoke(ar => act.EndInvoke(ar), null);
- }
- 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));
- m_EDSHardwareMgr.GetXRayByPoints(cOTSParticleClrs, a_Milliseconds, false);
- 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();
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSMultiPointXRay);
- }
- }
- private void btnAreaRay_Click(object sender, EventArgs e)
- {
- GetAreaRay();
- }
- protected void GetAreaRay()
- {
- 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 = m_EDSHardwareMgr.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();
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSAreaXRay);
- }
- }
- 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();
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- ConnectionState = false;
- log.Info("Cleared successfully!");
- }
- catch (Exception ex)
- {
- //记录日志
- log.Error(ex.Message.ToString());
- }
- }
- #region 获取元素分析
- private void btnEanalysis_Click(object sender, EventArgs e)
- {
- GetEanalysis();
- }
- protected void GetEanalysis()
- {
- 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
- {
- m_EDSHardwareMgr.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();
- //EDS过程结束
- //cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSAreaXRay);
- }
- }
- #endregion
- }
- }
|