12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646 |
- //时间:
- //作者:
- //功能:单元测试功能
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Configuration;
- using System.IO;
- using SmartSEMControl;
- using FileManager;
- using System.Xml;
- using MeasureData;
- using WebManager;
- namespace HOZProject
- {
- public partial class FormUnitControl : Form
- {
- #region 系统参数
- //全局只有一个fatorySEM
- static FactoryHardware factorySEM = FactoryHardware.Instance;
- ISEMControl iSEM = factorySEM.ISEM;
- public XmlManager xmg = new XmlManager();
-
- private String path = Directory.GetCurrentDirectory();
- private int st_flag = 0;
- WebResult wr = new WebResult("127.0.0.1", "18080","");
- String[] sT;
- String[] firms;
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- #endregion
- #region 构造函数
- public FormUnitControl()
- {
- InitializeComponent();
- Control.CheckForIllegalCrossThreadCalls = false;
- if(iSEM.ConnectStatus())
- {
- float ret = iSEM.GetFIBIMAGING();
- if(ret==0)
- {
- btnSEM.BackColor = Color.Lime;
- }
- else if(ret==1)
- {
- btnFIB.BackColor = Color.Lime;
- panelFIB.Visible = true;
- }
- else if(ret==2)
- {
- btnMILL.BackColor = Color.Lime;
- }
- }
- //Calling Notification for updated status
- //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
- //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
- //加载参数
- }
- #endregion
-
- #region 缩放Get
- private void btnenlargeGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetMagnification();
- if (float.IsNaN(ret))
- {
- txtenlargeSet.Text = "NaN";
- txtenlargeSet.Enabled = false;
- btnenlargeSet.Enabled = false;
- }
- else
- {
- txtenlargeSet.Text = ret.ToString();
- btnenlargeSet.Enabled = true;
- }
- }
- #endregion
- #region 缩放Set
- private void btnenlargeSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtenlargeSet.Text, out set))
- {
- iSEM.SetMagnification(set);
- }
- }
- #endregion
- #region 焦距Get
- private void btnWDGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetWorkingDistance();
- if (float.IsNaN(ret))
- {
- txtWDSet.Text = "NaN";
- txtWDSet.Enabled = false;
- btnWDSet.Enabled = false;
- }
- else
- {
- txtWDSet.Text = ret.ToString();
- btnWDSet.Enabled = true;
- }
- }
- #endregion
- #region 焦距Set
- private void btnWDSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtWDSet.Text, out set))
- {
- iSEM.SetWorkingDistance(set);
- }
- }
- #endregion
- #region 亮度Get
- private void btnBrightnessGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetBrightness();
- if (float.IsNaN(ret))
- {
- txtBrightnessSet.Text = "NaN";
- txtBrightnessSet.Enabled = false;
- btnBrightnessSet.Enabled = false;
- }
- else
- {
- txtBrightnessSet.Text = ret.ToString();
- btnBrightnessSet.Enabled = true;
- }
- }
- #endregion
- #region 亮度Set
- private void btnBrightnessSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtBrightnessSet.Text, out set))
- {
- iSEM.SetBrightness(set);
- }
- }
- #endregion
- #region 对比度Get
- private void btnContrastGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetContrast();
- if (float.IsNaN(ret))
- {
- txtContrastSet.Text = "NaN";
- txtContrastSet.Enabled = false;
- btnContrastSet.Enabled = false;
- }
- else
- {
- txtContrastSet.Text = ret.ToString();
- btnContrastSet.Enabled = true;
- }
- }
- #endregion
- #region 对比度Set
- private void btnContrastSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtContrastSet.Text, out set))
- {
- iSEM.SetContrast(set);
- }
- }
- #endregion
- #region 消像散X Get
- private void btnAstigmatismXGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetAstigmatismX();
- if (float.IsNaN(ret))
- {
- txtAstigmatismXSet.Text = "NaN";
- txtAstigmatismXSet.Enabled = false;
- btnAstigmatismXSet.Enabled = false;
- }
- else
- {
- txtAstigmatismXSet.Text = ret.ToString();
- btnAstigmatismXSet.Enabled = true;
- }
- }
- #endregion
- #region 消像散X Set
- private void btnAstigmatismXSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtAstigmatismXSet.Text, out set))
- {
- iSEM.SetAstigmatismX(set);
- }
- }
- #endregion
- #region 消像散Y Get
- private void btnAstigmatismYGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetAstigmatismY();
- if (float.IsNaN(ret))
- {
- txtAstigmatismYSet.Text = "NaN";
- txtAstigmatismYSet.Enabled = false;
- btnAstigmatismYSet.Enabled = false;
- }
- else
- {
- txtAstigmatismYSet.Text = ret.ToString();
- btnAstigmatismYSet.Enabled = true;
- }
- }
- #endregion
- #region 消像散Y Set
- private void btnAstigmatismYSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtAstigmatismYSet.Text, out set))
- {
- iSEM.SetAstigmatismY(set);
- }
- }
- #endregion
- #region 角度补偿Get
- private void btnTiltAngleGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetTiltAngle();
- if (float.IsNaN(ret))
- {
- txtTiltAngleSet.Text = "NaN";
- txtTiltAngleSet.Enabled = false;
- btnTiltAngleSet.Enabled = false;
- }
- else
- {
- txtTiltAngleSet.Text = ret.ToString();
- btnTiltAngleSet.Enabled = true;
- }
- }
- #endregion
- #region 角度补偿Set
- private void btnTiltAngleSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtTiltAngleSet.Text, out set))
- {
- //iSEM.SetTiltAngleOn();
- iSEM.SetTiltAngle(set);
- }
- }
- #endregion
- #region 抓取图像
- private void btnGrabImage_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Title = "图像保存位置:";
- sfd.FileName = "test.tif";
- sfd.Filter = "TIF文件|*.tif";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string fn = sfd.FileName;
- iSEM.GrabImage(fn, 0, 0, 1024, 768, 0);
- }
- }
- #endregion
- #region ScanRotate Get
- private void btnScanRotationGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetScanRotation();
- if (float.IsNaN(ret))
- {
- txtScanRotationSet.Text = "NaN";
- txtScanRotationSet.Enabled = false;
- btnScanRotationSet.Enabled = false;
- }
- else
- {
- txtScanRotationSet.Text = ret.ToString();
- btnScanRotationSet.Enabled = true;
- }
- }
- #endregion
- #region ScanRotate Set
- private void btnScanRotationSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtScanRotationSet.Text, out set))
- {
- //iSEM.SetScanRotationOn();
- iSEM.SetScanRotation(set);
- }
- }
- #endregion
- #region PixelSize Get
- private void btnPixelSizeGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetPixelSize();
- if (float.IsNaN(ret))
- {
- lblPixelSizeGet.Text = "NaN";
- }
- else
- {
- lblPixelSizeGet.Text = ret.ToString();
- }
- }
- #endregion
- #region 电子束
- private void btnTiltCorrXGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetBeamShiftX();
- if (float.IsNaN(ret))
- {
- txtTiltCorrX.Text = "NaN";
- txtTiltCorrX.Enabled = false;
- btnTiltCorrXSet.Enabled = false;
- }
- else
- {
- txtTiltCorrX.Text = ret.ToString();
- btnTiltCorrXSet.Enabled = true;
- }
- }
- private void btnTiltCorrXSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtTiltCorrX.Text, out set))
- {
- iSEM.SetBeamShiftX(set);
- }
- }
- private void btnTiltCorrYGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetBeamShiftY();
- if (float.IsNaN(ret))
- {
- txtTiltCorrY.Text = "NaN";
- txtTiltCorrY.Enabled = false;
- btnTiltCorrYSet.Enabled = false;
- }
- else
- {
- txtTiltCorrY.Text = ret.ToString();
- btnTiltCorrYSet.Enabled = true;
- }
- }
- private void btnTiltCorrYSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtTiltCorrY.Text, out set))
- {
- iSEM.SetBeamShiftY(set);
- }
- }
- #endregion
- #region 开启电压
- private void btnOpenVoltage_Click(object sender, EventArgs e)
- {
- iSEM.CmdOpenVoltage();
- }
- #endregion
- #region 关闭电压
- private void btnCloseVoltage_Click(object sender, EventArgs e)
- {
- iSEM.CmdCloseVoltage();
- }
- #endregion
- #region 电子束校正
- private void btnTiltCorr_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetTiltCorrection();
- if (float.IsNaN(ret))
- {
- btnTiltCorr.BackColor = Color.Red;
- }
- else
- {
- if(ret==0)
- {
- btnTiltCorr.BackColor = Color.Blue;
- iSEM.SetTiltCorrectionOn();
- btnTiltCorr.Text = "电子束状态:On";
- }
- else
- {
- btnTiltCorr.BackColor = Color.Lime;
- iSEM.SetTiltCorrectionOff();
- btnTiltCorr.Text = "电子束状态:Off";
- }
- }
- }
- #endregion
- #region 样品台位置获取
- private void btnStageGetX_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtX();
- if (float.IsNaN(ret))
- {
- lblStageX.Text = "NaN";
- }
- else
- {
- lblStageX.Text = ret.ToString();
- }
- }
- private void btnStageGetY_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtY();
- if (float.IsNaN(ret))
- {
- lblStageY.Text = "NaN";
- }
- else
- {
- lblStageY.Text = ret.ToString();
- }
- }
- private void btnStageGetZ_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtZ();
- if (float.IsNaN(ret))
- {
- lblStageZ.Text = "NaN";
- }
- else
- {
- lblStageZ.Text = ret.ToString();
- }
- }
- private void btnStageGetT_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtT();
- if (float.IsNaN(ret))
- {
- lblStageT.Text = "NaN";
- }
- else
- {
- lblStageT.Text = ret.ToString();
- }
- }
- private void btnStageGetR_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtR();
- if (float.IsNaN(ret))
- {
- lblStageR.Text = "NaN";
- }
- else
- {
- lblStageR.Text = ret.ToString();
- }
- }
- private void btnStageGetM_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetStageAtM();
- if (float.IsNaN(ret))
- {
- lblStageM.Text = "NaN";
- }
- else
- {
- lblStageM.Text = ret.ToString();
- }
- }
- #endregion
- #region 样品台位置设置
- private void btnStageSetX_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageX.Text, out set))
- {
- iSEM.SetStageGotoX(set);
- }
- }
- private void btnStageSetY_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageY.Text, out set))
- {
- iSEM.SetStageGotoY(set);
- }
- }
- private void btnStageSetZ_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageZ.Text, out set))
- {
- iSEM.SetStageGotoZ(set);
- }
- }
- private void btnStageSetT_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageT.Text, out set))
- {
- iSEM.SetStageGotoT(set);
- }
- }
- private void btnStageSetR_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageR.Text, out set))
- {
- iSEM.SetStageGotoR(set);
- }
- }
- private void btnStageSetM_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtStageM.Text, out set))
- {
- iSEM.SetStageGotoM(set);
- }
- }
- #endregion
- #region 获取样品台位置数组
- private void btnGetStagePosition_Click(object sender, EventArgs e)
- {
- float[] pt = iSEM.GetStagePosition();
- if (!float.IsNaN(pt[0]))
- {
- lblStageX.Text = pt[0].ToString();
- }
- if (!float.IsNaN(pt[1]))
- {
- lblStageY.Text = pt[1].ToString();
- }
- if (!float.IsNaN(pt[2]))
- {
- lblStageZ.Text = pt[2].ToString();
- }
- if (!float.IsNaN(pt[3]))
- {
- lblStageT.Text = pt[3].ToString();
- }
- if (!float.IsNaN(pt[4]))
- {
- lblStageR.Text = pt[4].ToString();
- }
- if (!float.IsNaN(pt[5]))
- {
- lblStageM.Text = pt[5].ToString();
- }
- }
- #endregion
- #region 窗体关闭
- private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
- {
- if(iSEM!=null)
- {
- iSEM.Dispose();
- }
- }
- #endregion
- #region 宏文件
- private void btnCMDMCF_Click(object sender, EventArgs e)
- {
- iSEM.CMDMCFFilename("OPTON");
- }
- #endregion
- #region 读取Xml文件
- private void btnReadXml_Click(object sender, EventArgs e)
- {
- MeasureFile mf = new MeasureFile();
- XmlDocument doc = new XmlDocument();
- doc.Load("test_opton.msf");//载入xml文件
- XmlNode root = doc.SelectSingleNode("XMLData");
- mf.Serialize(false, doc, root);
- doc.Save("test_opton.msf");
- }
- #endregion
- #region 写入Xml文件
- private void btnWriteXml_Click(object sender, EventArgs e)
- {
- MeasureFile mf = new MeasureFile();
- mf.FileName = path + "\\test_opton.msf";
- mf.FilePath = path;
- CutHole ch = new CutHole();
- ch.OPT = Operation.Image;
- ch.START = System.DateTime.Now;
- ch.END = System.DateTime.Now.AddHours(2);
- ch.STATE = State.Success;
- ch.SWITCH = true;
- SemPosition sp = new SemPosition();
- sp.X = 11;
- sp.Y = 22;
- sp.Z = 33;
- sp.T = 44;
- sp.R = 55;
- sp.M = 66;
- ch.Position = sp;
- mf.ListCutHole.Add(ch);
- ch = new CutHole();
- ch.OPT = Operation.Image;
- ch.START = System.DateTime.Now;
- ch.END = System.DateTime.Now.AddHours(2);
- ch.STATE = State.Success;
- ch.SWITCH = true;
- sp = new SemPosition();
- sp.X = 12;
- sp.Y = 34;
- sp.Z = 56;
- sp.T = 78;
- sp.R = 90;
- sp.M = 55;
- ch.Position = sp;
- mf.ListCutHole.Add(ch);
- MeasureParam md = new MeasureParam();
- md.SampleName = "aaaaaa";
- md.PT = true;
- md.PTTemp = "bbbbb";
- md.FIBTemp = "cccc";
- md.FocusMode = 2;
- mf.MParam = md;
- mf.New();
- //XmlDocument doc = new XmlDocument();
- //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
- //XmlNode root = doc.SelectSingleNode("XMLData");
- //mf.Serialize(true, doc, root);
- //doc.Save("test.aaa");
- }
- #endregion
- #region SEM模式
- private void btnSEM_Click(object sender, EventArgs e)
- {
- if(iSEM.CmdFIBModeSEM())
- {
- btnFIB.BackColor = SystemColors.Control;
- btnSEM.BackColor = Color.Lime;
- btnMILL.BackColor = SystemColors.Control;
- panelFIB.Visible = false;
- }
- }
- #endregion
- #region FIB模式
- private void btnFIB_Click(object sender, EventArgs e)
- {
- if(iSEM.CmdFIBModeFIB())
- {
- btnFIB.BackColor = Color.Lime;
- btnSEM.BackColor = SystemColors.Control;
- btnMILL.BackColor = SystemColors.Control;
- panelFIB.Visible = true;
- }
- }
- #endregion
- #region MILL模式
- private void btnMILL_Click(object sender, EventArgs e)
- {
- if(iSEM.CmdFIBModeMILL())
- {
- btnFIB.BackColor = SystemColors.Control;
- btnSEM.BackColor = SystemColors.Control;
- btnMILL.BackColor = Color.Lime;
- }
- }
- #endregion
- #region 自动对焦1
- private void btnAutoFocus1_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.CmdAutoFocusCoarse();
- btnAutoFocus1.BackColor = Color.Red;
- st_flag = 1;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- #endregion
- #region 自动函数监测线程
- private void AutoFunction()
- {
- float ret = 111;
- Boolean state = false;
- while(true)
- {
- Thread.Sleep(1000);
- ret = iSEM.GetAutoFunction();
- if(ret==0)
- {
- if (st_flag == 1 && state == true)
- {
- btnAutoFocus1.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if(st_flag==2 && state)
- {
- btnAutoFocus2.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if (st_flag == 3)
- {
- btnAutoBrightness.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if (st_flag == 4)
- {
- btnAutoContrast.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if (st_flag == 5)
- {
- btnAutoBrightness.BackColor = Color.Lime;
- btnAutoContrast.BackColor = Color.Lime;
- btnAutoBC.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if (st_flag == 6 && state)
- {
- btnAutoBCCancle.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- else if (st_flag == 7 && state)
- {
- btnAutoStig.BackColor = Color.Lime;
- Thread.Sleep(1000);
- //抓图1
- iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test2.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- pictureBox2.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- break;
- }
- ////抓图1
- //iSEM.GrabImage(path + "\\test2.tif", 0, 0, 1024, 768, 0);
- //if (File.Exists(path + "\\test2.tif"))
- //{
- // FileStream fileStream = new FileStream(path + "\\test2.tif", FileMode.Open, FileAccess.Read);
- // pictureBox2.Image = Image.FromStream(fileStream);
- // fileStream.Close();
- // fileStream.Dispose();
- //}
-
- }
- else if(ret>0 && ret<12)
- {
- state = true;
- }
- }
- }
- #endregion
- #region 自动对焦2
- private void btnAutoFocus2_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.CmdAutoFocusFine();
- btnAutoFocus2.BackColor = Color.Red;
- st_flag = 2;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- #endregion
- #region 自动亮度、对比度
- private void btnAutoBrightness_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.SetAutoVideoBrightness();
- btnAutoBrightness.BackColor = Color.Red;
- st_flag = 3;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- private void btnAutoContrast_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.SetAutoVideoContrast();
- btnAutoContrast.BackColor = Color.Red;
- st_flag = 4;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- private void btnAutoBC_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.SetAutoVideoBrightnessAndContrast();
- btnAutoBrightness.BackColor = Color.Red;
- btnAutoContrast.BackColor = Color.Red;
- btnAutoBC.BackColor = Color.Red;
- st_flag = 5;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- private void btnAutoBCCancle_Click(object sender, EventArgs e)
- {
- iSEM.SetAutoVideoOff();
- btnAutoBCCancle.BackColor = Color.Red;
- st_flag = 6;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- #endregion
- #region 自动消像散
- private void btnAutoStig_Click(object sender, EventArgs e)
- {
- //抓图1
- iSEM.GrabImage(path + "\\test1.tif", 0, 0, 1024, 768, 0);
- if (File.Exists(path + "\\test1.tif"))
- {
- FileStream fileStream = new FileStream(path + "\\test1.tif", FileMode.Open, FileAccess.Read);
- pictureBox1.Image = Image.FromStream(fileStream);
- fileStream.Close();
- fileStream.Dispose();
- }
- Thread.Sleep(1000);
- iSEM.CmdAutoStig();
- btnAutoStig.BackColor = Color.Red;
- st_flag = 7;
- Thread.Sleep(1000);
- Thread thread = new Thread(AutoFunction);
- thread.Start();
- }
- #endregion
- #region FIB缩放Get
- private void btnFIBMagGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBMagnification();
- if (float.IsNaN(ret))
- {
- txtFIBMag.Text = "NaN";
- txtFIBMag.Enabled = false;
- btnFIBMagSet.Enabled = false;
- }
- else
- {
- txtFIBMag.Text = ret.ToString();
- btnFIBMagSet.Enabled = true;
- }
- }
- #endregion
- #region FIB缩放Set
- private void btnFIBMagSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBMag.Text, out set))
- {
- iSEM.SetFIBMagnification(set);
- }
- }
- #endregion
- #region FIB焦距Get
- private void btnFIBWDGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBObjectivePotential();
- if (float.IsNaN(ret))
- {
- txtFIBWD.Text = "NaN";
- txtFIBWD.Enabled = false;
- btnFIBWDSet.Enabled = false;
- }
- else
- {
- txtFIBWD.Text = ret.ToString();
- btnFIBWDSet.Enabled = true;
- }
- }
- #endregion
- #region FIB焦距Set
- private void btnFIBWDSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBWD.Text, out set))
- {
- iSEM.SetFIBObjectivePotential(set);
- }
- }
- #endregion
- #region FIB电子束移动
- private void btnFIBBeamShiftXGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBBeamShiftX();
- if (float.IsNaN(ret))
- {
- txtFIBBeamShiftX.Text = "NaN";
- txtFIBBeamShiftX.Enabled = false;
- btnFIBBeamShiftXSet.Enabled = false;
- }
- else
- {
- txtFIBBeamShiftX.Text = ret.ToString();
- btnFIBBeamShiftXSet.Enabled = true;
- }
- }
- private void btnFIBBeamShiftXSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBBeamShiftX.Text, out set))
- {
- iSEM.SetFIBBeamShiftX(set);
- }
- }
- private void btnFIBBeamShiftYGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBBeamShiftY();
- if (float.IsNaN(ret))
- {
- txtFIBBeamShiftY.Text = "NaN";
- txtFIBBeamShiftY.Enabled = false;
- btnFIBBeamShiftYSet.Enabled = false;
- }
- else
- {
- txtFIBBeamShiftY.Text = ret.ToString();
- btnFIBBeamShiftYSet.Enabled = true;
- }
- }
- private void btnFIBBeamShiftYSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBBeamShiftY.Text, out set))
- {
- iSEM.SetFIBBeamShiftY(set);
- }
- }
- #endregion
- #region 执行宏文件
- private void btnMCF_Click(object sender, EventArgs e)
- {
- OpenFileDialog sfd = new OpenFileDialog();
- sfd.Title = "选择宏文件:";
- sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
- sfd.Filter = "MLF文件|*.MLF";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- //string fn = Path.GetFileNameWithoutExtension(sfd.FileName).ToUpper();
- iSEM.CMDMCFFilename(sfd.FileName);
- }
- }
- #endregion
- #region FIB消像散
- private void btnFIBAstigmatismXGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBAstigmatismX();
- if (float.IsNaN(ret))
- {
- txtFIBAstigmatismX.Text = "NaN";
- txtFIBAstigmatismX.Enabled = false;
- btnFIBAstigmatismXSet.Enabled = false;
- }
- else
- {
- txtFIBAstigmatismX.Text = ret.ToString();
- btnFIBAstigmatismXSet.Enabled = true;
- }
- }
- private void btnFIBAstigmatismXSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBAstigmatismX.Text, out set))
- {
- iSEM.SetFIBAstigmatismX(set);
- }
- }
- private void btnFIBAstigmatismYGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetFIBAstigmatismY();
- if (float.IsNaN(ret))
- {
- txtFIBAstigmatismY.Text = "NaN";
- txtFIBAstigmatismY.Enabled = false;
- btnFIBAstigmatismYSet.Enabled = false;
- }
- else
- {
- txtFIBAstigmatismY.Text = ret.ToString();
- btnFIBAstigmatismYSet.Enabled = true;
- }
- }
- private void btnFIBAstigmatismYSet_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtFIBAstigmatismY.Text, out set))
- {
- iSEM.SetFIBAstigmatismY(set);
- }
- }
- #endregion
- #region 移动样品台XY
- private void btnMoveXY_Click(object sender, EventArgs e)
- {
- float setx = 0;
- float sety = 0;
- if (!float.TryParse(txtStageX.Text, out setx))
- {
- return;
- }
- if(!float.TryParse(txtStageY.Text,out sety))
- {
- return;
- }
- btnMoveXY.BackColor = Color.Red;
- iSEM.MoveStageXY(setx, sety);
- Thread.Sleep(500);
- Thread th = new Thread(MoveStagexy);
- th.Start();
- }
- private void MoveStagexy()
- {
- float ret = 111;
- while(true)
- {
- ret = iSEM.GetStageIs();
- if(ret==0)
- {
- btnMoveXY.BackColor = Color.Lime;
- break;
- }
- }
- }
- #endregion
- #region 获取分辨率
- private void btnImageStoreGet_Click(object sender, EventArgs e)
- {
- int[] ret = iSEM.GetImageStore();
- lblImageStore.Text = ret[0].ToString() + "*" + ret[1].ToString();
- }
- #endregion
- #region 设置分辨率
- private void btnImageStoreSet_Click(object sender, EventArgs e)
- {
- if (cmbImageStore.SelectedIndex > -1 && cmbImageStore.SelectedIndex < 12)
- {
- iSEM.SetImageStore(cmbImageStore.SelectedIndex);
- }
- }
- #endregion
- #region 样品台急停
- private void btnAbort_Click(object sender, EventArgs e)
- {
- iSEM.CmdStageAbort();
- }
- #endregion
- private void btnLive_Click(object sender, EventArgs e)
- {
- iSEM.ImageLive();
- }
- private void btnFrozen_Click(object sender, EventArgs e)
- {
- iSEM.ImageFrozen();
- }
- private void btnExeEly_Click(object sender, EventArgs e)
- {
- OpenFileDialog sfd = new OpenFileDialog();
- sfd.Title = "选择ELY文件:";
- //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
- sfd.Filter = "ELY文件|*.ELY";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- iSEM.CmdFIBLoadELY(sfd.FileName);
- }
- }
- private void btnExeEly2_Click(object sender, EventArgs e)
- {
- iSEM.CmdFIBEXPOSUREELY();
- }
- private void btnFIBStatus_Click(object sender, EventArgs e)
- {
- btnFIBStatus.Text = iSEM.GetFIBMode().ToString();
- }
- private void btnPost1_Click(object sender, EventArgs e)
- {
- double degree = 0;
- int direction = 0;
- int state = 0;
- wr.Img_OffsetAngle_Direction("D:/aaaa.jpg",1,"LG", out degree, out direction, out state);
- lbldegree1.Text = degree.ToString("0.0");
- lbldirection1.Text = direction.ToString();
- lblstate1.Text = state.ToString();
- }
- private void btnPost2_Click(object sender, EventArgs e)
- {
- double offsetx = 0;
- double offsety = 0;
- int state = 0;
- //wr.Img_Cut_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
- lbllocationx.Text = offsetx.ToString("0.0");
- lbllocationy.Text = offsety.ToString("0.0");
- lblstate2.Text = state.ToString();
- }
- private void btnPost3_Click(object sender, EventArgs e)
- {
- int state = 0;
- wr.Img_Cut_Success("D:/aaaa.jpg", "D:/bbbb.jpg", out state);
- lblstate3.Text = state.ToString();
- }
- private void btnPost4_Click(object sender, EventArgs e)
- {
- double offsetx = 0;
- double offsety = 0;
- int state = 0;
- wr.Img_Trapezoid_Top_Center_Position("D:/aaaa.jpg", out offsetx, out offsety, out state);
- lbltopcx.Text = offsetx.ToString("0.0");
- lbltopcy.Text = offsety.ToString("0.0");
- lblstate4.Text = state.ToString();
- }
- private void btnPost5_Click(object sender, EventArgs e)
- {
- List<string> filenames = new List<string>();
- filenames.Add("1111111");
- filenames.Add("2222222");
- filenames.Add("3333333");
- lblfocuspath.Text = wr.Img_Auto_Focus(filenames);
- }
- private void btnPost6_Click(object sender, EventArgs e)
- {
- List<string> filenames = new List<string>();
- filenames.Add("1111111");
- filenames.Add("2222222");
- filenames.Add("3333333");
- lblstigpath.Text = wr.Img_Auto_Focus(filenames);
- }
- private void btnPost7_Click(object sender, EventArgs e)
- {
- double offsetx = 0;
- double offsety = 0;
- double degree = 0;
- int direction = 0;
- int state = 0;
- //wr.Img_Center_Position_OffsetAngle_Direction("D:/aaaa.jpg", out offsetx, out offsety, out degree, out direction, out state);
- lblcenterx.Text = offsetx.ToString("0.0");
- lblcentery.Text = offsety.ToString("0.0");
- lbldegree2.Text = degree.ToString();
- lbldirection2.Text = direction.ToString();
- lblstate5.Text = state.ToString();
- }
- private void btnPost8_Click(object sender, EventArgs e)
- {
- int state = 0;
- wr.Img_Measure_Size("D:/aaaa.jpg", "1000", "0.005", out state);
- lblstate6.Text = state.ToString();
- }
- private void btnScanRotationSetLock_Click(object sender, EventArgs e)
- {
- iSEM.SetScanRotationOff();
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- iSEM.SetTiltAngleOff();
- }
- private void btnTiltAngleSetOn_Click(object sender, EventArgs e)
- {
- iSEM.SetTiltAngleOn();
- }
- private void btnScanRotationSetOn_Click(object sender, EventArgs e)
- {
- iSEM.SetScanRotationOn();
- }
- private void btnExeEly3_Click(object sender, EventArgs e)
- {
- iSEM.CmdFIBSTARTELY();
- }
- private void btnCreateConfig_Click(object sender, EventArgs e)
- {
- MeasureParam cfm = new MeasureParam();
- cfm.Is_Photograph = chkWIsP.Checked;
- cfm.PT = chkWPT.Checked;
- cfm.PTTemp = txtWPTF.Text;
- cfm.FIBTemp = txtWFIBF.Text;
- cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
- cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
- cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
- cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
- cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
- if(cbbWXZ.SelectedIndex==0)
- {
- cfm.Correction_Angle = 36;
- }
- else
- {
- cfm.Correction_Angle = 54;
- }
-
- cfm.SampleName = cbbWYP.Text;
- cfm.Firm = cbbWCS.Text;
- ConfigFile cf = new ConfigFile(cfm);
-
- cf.Save(@"E:\test.cfg");
- List<String> _sT = sT.ToList();
- if(_sT.IndexOf(cbbWYP.Text)<0)
- {
- _sT.Add(cbbWYP.Text);
- sT = _sT.ToArray();
- string wsT = "";
- for(int i=0;i<sT.Length;i++)
- {
- wsT += sT[i] + ",";
- }
- wsT = wsT.Substring(0, wsT.Length - 1);
- config.AppSettings.Settings["Sample_Type"].Value = wsT;
- }
- List<String> _firms = firms.ToList();
- if (_firms.IndexOf(cbbWCS.Text) < 0)
- {
- _firms.Add(cbbWCS.Text);
- firms = _firms.ToArray();
- string wFirms = "";
- for (int i = 0; i < firms.Length; i++)
- {
- wFirms += firms[i] + ",";
- }
- wFirms = wFirms.Substring(0, wFirms.Length - 1);
- config.AppSettings.Settings["Firm"].Value = wFirms;
- }
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- reloadconfig();
- }
- private void btnReadConfig_Click(object sender, EventArgs e)
- {
- MeasureParam cfm = new MeasureParam();
- ConfigFile cf = new ConfigFile(cfm);
- cf.Read(@"E:\test.cfg");
- chkRIsP.Checked = cfm.Is_Photograph;
- chkRPT.Checked = cfm.PT;
- txtRPTF.Text = cfm.PTTemp;
- txtRFIBF.Text = cfm.FIBTemp;
- txtRLZ.Text = cfm.Stretch_Magnification.ToString();
- txtRQGF.Text = cfm.Location_Magnification.ToString();
- txtRQGD.Text = cfm.Location_Voltage.ToString();
- txtRPZF.Text = cfm.Photograph_Magnification.ToString();
- txtRPZD.Text = cfm.Photograph_Voltage.ToString();
- txtRXZ.Text = cfm.Correction_Angle.ToString();
- txtRYP.Text = cfm.SampleName;
- txtRCS.Text = cfm.Firm;
- }
- private void FormUnitControl_Load(object sender, EventArgs e)
- {
- reloadconfig();
- cbbWYP.SelectedIndex = 0;
- cbbWCS.SelectedIndex = 0;
- cbbWXZ.SelectedIndex = 0;
- this.chart1.Series[0].Points.Clear();
-
- }
- private void reloadconfig()
- {
- String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
- String firm = ConfigurationManager.AppSettings["Firm"];
- sT = sample_Type.Split(',');
- cbbWYP.Items.Clear();
- for (int i = 0; i < sT.Length; i++)
- {
- cbbWYP.Items.Add(sT[i]);
- }
-
- firms = firm.Split(',');
- cbbWCS.Items.Clear();
- for (int i = 0; i < firms.Length; i++)
- {
- cbbWCS.Items.Add(firms[i]);
- }
-
- }
-
- private void btnPsFile_Click(object sender, EventArgs e)
- {
- OpenFileDialog sfd = new OpenFileDialog();
- sfd.Title = "选择位置文件:";
- //sfd.InitialDirectory = @"C:\ProgramData\Carl Zeiss\SmartSEM\User\Default";
- sfd.Filter = "TXT文件|*.TXT";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- //Console.WriteLine(sfd.FileName);
- StreamReader sr = new StreamReader(sfd.FileName, Encoding.Default);
- String line = "";
- sr.ReadLine();
- sr.ReadLine();
- sr.ReadLine();
- sr.ReadLine();
- line = sr.ReadLine();
- sr.Close();
- sr.Dispose();
- String[] lines = line.Split(',');
- double x = Convert.ToDouble(lines[1]);
- double y = Convert.ToDouble(lines[2]);
- chart1.Series[0].Points.AddXY(x, y);
- chart1.Series[0].Points[0].Label = x.ToString("0.000") + "," + y.ToString("0.000");
- }
- }
- private void btnrect_Click(object sender, EventArgs e)
- {
- this.chart1.Series[0].Points.Clear();
- List<double> xpoints = new List<double>();
- List<double> ypoints = new List<double>();
- //排列数
- int rag = Convert.ToInt32(txtarray.Text);
- //间距
- double dist = Convert.ToDouble(txtdistance.Text);
- //中心点x,y轴坐标
- double cx = Convert.ToDouble(txtx.Text);
- double cy = Convert.ToDouble(txty.Text);
- //求样品1的水平角度
- double angle = 0;
- //xpoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
- //ypoints.Add(Math.Pow(Math.Pow(Convert.ToDouble(txtx.Text), 2) + Math.Pow(Convert.ToDouble(txty.Text), 2), 0.5));
- xpoints.Add(Convert.ToDouble(txtsample1x.Text));
- ypoints.Add(Convert.ToDouble(txtsample1y.Text));
- //计算第一个点与X轴的交角度数
- angle = Math.Atan2(ypoints[0] - cy, cx - xpoints[0]) * 180 / Math.PI;
- lblPs1.Text = angle.ToString("0.0");
- //这里是求与第一个点横向排列的其他点的移动角度
- //就是按45度向左向右移动的度
- angle = 45 - angle;
- angle = angle * Math.PI / 180;
- txtsample1x.Text = xpoints[0].ToString("0.000");
- txtsample1y.Text = ypoints[0].ToString("0.000");
- chart1.Series[0].Points.AddXY(xpoints[0], ypoints[0]);
- chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[0].ToString("0.000") + "," + ypoints[0].ToString("0.000");
- double tx = 0;
- double ty = 0;
- for (int j = 0; j < rag; j++)
- {
- //计算每行第一个点的坐标
- if(j>0)
- {
- tx = dist * j * Math.Sin(angle);
- ty = dist * j * Math.Cos(angle);
- xpoints.Add(tx + xpoints[0]);
- ypoints.Add(ypoints[0] - ty);
- chart1.Series[0].Points.AddXY(xpoints[xpoints.Count-1], ypoints[ypoints.Count-1]);
- chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[xpoints.Count - 1].ToString("0.000") + "," + ypoints[ypoints.Count - 1].ToString("0.000");
- }
- //计算每行其他点的坐标
- for (int i = 1; i < rag; i++)
- {
- tx = dist * i * Math.Cos(angle);
- ty = dist * i * Math.Sin(angle);
- xpoints.Add(tx + xpoints[j * rag]);
- ypoints.Add(ty + ypoints[j * rag]);
- chart1.Series[0].Points.AddXY(xpoints[xpoints.Count - 1], ypoints[ypoints.Count - 1]);
- chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Label = xpoints[xpoints.Count - 1].ToString("0.000") + "," + ypoints[ypoints.Count - 1].ToString("0.000");
- }
- }
- }
- private void btn30_Click(object sender, EventArgs e)
- {
- txtsample1x.Text = "21.7";
- txtsample1y.Text = "90";
- btnrect_Click(null, null);
- }
- private void btn45_Click(object sender, EventArgs e)
- {
- txtsample1x.Text = "29.65";
- txtsample1y.Text = "100.35";
- btnrect_Click(null, null);
- }
- private void btn60_Click(object sender, EventArgs e)
- {
- txtsample1x.Text = "40";
- txtsample1y.Text = "108.3";
- btnrect_Click(null, null);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetSEMVoltage();
- if (float.IsNaN(ret))
- {
- txtVoltage.Text = "NaN";
- txtVoltage.Enabled = false;
- button2.Enabled = false;
- }
- else
- {
- txtVoltage.Text = ret.ToString();
- button2.Enabled = true;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- float set = 0;
- if (float.TryParse(txtVoltage.Text, out set))
- {
- iSEM.SetSEMVoltage(set);
- }
- }
- }
- }
|