123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- using NLog.Fluent;
- using OTSCLRINTERFACE;
- using OTSModelSharp.ServiceCenter;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- namespace OTSSysMgrApp
- {
- public partial class StageTest : 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();
- ISemController m_SemHardwareMgr = null;
- IEDSController m_EDSHardwareMgr = null;
- //图片
- Bitmap bitmap = null;
- //国际化
- Language lan;
- //国际化存储信息
- Hashtable table;
- public enum connectionEnumType
- {
- EDSOnlyPointXRay = 0,
- EDSMultiPointXRay = 1,
- EDSAreaXRay = 2,
- ScanImage = 3
- }
- #endregion
- public StageTest()
- {
- InitializeComponent();
- m_EDSHardwareMgr = EDSController.GetEDSController(1024, 768, 5000, true, "");
- m_SemHardwareMgr = SemController.GetSEMController();
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- if (!ConnectionState)
- {
- //和电镜建立通讯连接
- ConnectionState = m_SemHardwareMgr.Connect();
- ///获取当前电镜的ID号
- //SemType = cfun.GetSemType();
- if (!ConnectionState)
- {
- log.Error(table["message3"].ToString());
- }
- else
- {
- string str = table["str1"].ToString();
- log.Info("The energy spectrum is connected");
- }
- }
- else
- {
- string str = table["str2"].ToString();
- ConnectionState = false;
- }
- }
- private void btnGPositionXYR_Click(object sender, EventArgs e)
- {
- try
- {
- //赋值
- double PositionX = 0;
- double PositionY = 0;
- double PositionR = 0;
- //获取参数
- bool result = m_SemHardwareMgr.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
- if (result)
- {
- //赋值 显示
- tbPositionX.Text = Convert.ToDouble(PositionX).ToString();
- tbPositionY.Text = Convert.ToDouble(PositionY).ToString();
- tbPositionR.Text = Convert.ToDouble(PositionR).ToString();
- log.Info("X,Y-axis coordinates:(" + tbPositionX.Text + "," + tbPositionY.Text + ")");
- }
- else
- {
- //配置结果提示
- ShowMessage(6);
- log.Error("Failed to obtain the X and Y coordinates");
- }
- }
- catch (Exception ex)
- {
- //记录日志信息(异常日志)
- log.Error(ex.Message.ToString());
- }
- }
- private void btn_setpositionxyr_Click(object sender, EventArgs e)
- {
- try
- {
- if (!IsNull(tbSPositionX))
- {
- this.Focus();
- return;
- }
- if (!IsType(tbSPositionX.Text, 2))
- {
- this.Focus();
- return;
- }
- if (!IsNull(tbSPositionY))
- {
- this.Focus();
- return;
- }
- if (!IsType(tbSPositionY.Text, 2))
- {
- this.Focus();
- return;
- }
- if (!IsNull(tbSPositionR))
- {
- this.Focus();
- return;
- }
- if (!IsType(tbSPositionR.Text, 2))
- {
- this.Focus();
- return;
- }
- //赋值
- double PositionX = Convert.ToDouble(tbSPositionX.Text);
- double PositionY = Convert.ToDouble(tbSPositionY.Text);
- double PositionR = Convert.ToDouble(tbSPositionR.Text);
- bool result = m_SemHardwareMgr.MoveSEMToPoint(PositionX, PositionY, PositionR);
- if (result)
- {
- ShowMessage(3);
- log.Info("Set successfully, current X and Y coordinates should be:(" + PositionX.ToString() + "," + PositionY.ToString() + PositionR.ToString() + ")");
- }
- else
- {
- ShowMessage(4);
- log.Error("Failed to set X and Y coordinates!");
- }
- }
- catch (Exception ex)
- {
- //记录日志信息
- log.Error(ex.Message.ToString());
- }
- }
- private void btn_Recommendedconfiguration_Click(object sender, EventArgs e)
- {
- if (recommendedConfiguration == null || recommendedConfiguration.IsDisposed)
- {
- recommendedConfiguration = new RecommendedConfiguration(Language.ReadDefaultLanguage());
- recommendedConfiguration.Show();
- }
- else
- {
- recommendedConfiguration.Activate();
- }
- }
- 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();
- }
- }
- 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;
- }
- 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!");
- }
- }
- 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;
- }
- public bool ConnectionSem(connectionEnumType connectionType)
- {
- //连接电镜标识
- bool DisConnResult = false;
- //判断连接状态
- if (!ConnectionState)
- {
- //连接电镜设置
- DisConnResult = m_EDSHardwareMgr.Connect();
- }
- if (DisConnResult)
- {
- ConnectionState = true;
- }
- else
- {
- ConnectionState = false;
- }
- return DisConnResult;
- }
- #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;
- }
- }
- #endregion
- 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;
- }
- }
- private void StageTest_Load(object sender, EventArgs e)
- {
- Control.CheckForIllegalCrossThreadCalls = false;
- //m_EDSHardwareMgr = EDSController.GetEDSController(width, height, 5000, true, "");
- 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();
- }
- }
- }
|