123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- //时间:
- //作者:
- //功能:单元测试功能
- 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.IO;
- using SmartSEMControl;
- namespace HOZProject
- {
- public partial class FormUnitControl : Form
- {
- //全局只有一个fatorySEM
- static FactoryHardware factorySEM = FactoryHardware.Instance;
- ISEMControl iSEM = factorySEM.ISEM;
- #region 系统参数
- private String path = Directory.GetCurrentDirectory();
- #endregion
- #region 构造函数
- public FormUnitControl()
- {
- InitializeComponent();
-
- //Calling Notification for updated status
- //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
- //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
- //加载参数
- }
- #endregion
-
- #region 设备初始化按键
- private void btnInit_Click(object sender, EventArgs e)
- {
- //if (sem.Init())
- //{
- // btnInit.BackColor = Color.Lime;
- //}
- //else
- //{
- // btnInit.BackColor = Color.Red;
- //}
- }
- #endregion
-
- #region 设备关闭按键
- private void btnCloseCtrl_Click(object sender, EventArgs e)
- {
- //if (sem.UnInit())
- //{
- // btnInit.BackColor = Control.DefaultBackColor;
- //}
- }
- #endregion
- #region 设置参数更新通知
- private void btnSetNotify_Click(object sender, EventArgs e)
- {
- //if (m_bInitialised)
- //{
- // // Magnification
- // if (CZEMApi.SetNotify("AP_MAG", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_MAG");
- // return;
- // }
- // // Working distance
- // if (CZEMApi.SetNotify("AP_WD", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_WD");
- // return;
- // }
- // // BRIGHTNESS 亮度
- // if (CZEMApi.SetNotify("AP_BRIGHTNESS", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_BRIGHTNESS");
- // return;
- // }
- // // AP_CONTRAST,对比度
- // if (CZEMApi.SetNotify("AP_CONTRAST", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_CONTRAST");
- // return;
- // }
- // // Vacuum
- // if (CZEMApi.SetNotify("DP_VACSTATUS", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_VACSTATUS");
- // return;
- // }
- // // Gun / EHT state
- // if (CZEMApi.SetNotify("DP_RUNUPSTATE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_RUNUPSTATE");
- // return;
- // }
- // // actual KV / EHT
- // if (CZEMApi.SetNotify("AP_ACTUALKV", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_ACTUALKV");
- // return;
- // }
- // // actual current
- // if (CZEMApi.SetNotify("AP_ACTUALCURRENT", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_ACTUALCURRENT");
- // return;
- // }
- // // column type
- // if (CZEMApi.SetNotify("DP_COLUMN_TYPE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_COLUMN_TYPE");
- // return;
- // }
- // // mode
- // if (CZEMApi.SetNotify("DP_OPERATING_MODE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_OPERATING_MODE");
- // return;
- // }
- // // scan rate
- // if (CZEMApi.SetNotify("DP_SCANRATE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_SCANRATE");
- // return;
- // }
- // // auto function active
- // if (CZEMApi.SetNotify("DP_AUTO_FUNCTION", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_AUTO_FUNCTION");
- // return;
- // }
- // // probe current
- // if (CZEMApi.SetNotify("AP_IPROBE", 1) != 0)
- // {
- // DisplayError("SetNotify", "AP_IPROBE");
- // return;
- // }
- // // detector
- // if (CZEMApi.SetNotify("DP_DETECTOR_TYPE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_DETECTOR_TYPE");
- // return;
- // }
- // // stage initialised
- // if (CZEMApi.SetNotify("DP_STAGE_INIT", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_STAGE_INIT");
- // return;
- // }
- // // stage busy?
- // if (CZEMApi.SetNotify("DP_STAGE_IS", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_STAGE_IS");
- // return;
- // }
- // // fib mode
- // if (CZEMApi.SetNotify("DP_FIB_MODE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_FIB_MODE");
- // return;
- // }
- // // fib gun state
- // if (CZEMApi.SetNotify("DP_FIB_GUN_STATE", 1) != 0)
- // {
- // DisplayError("SetNotify", "DP_FIB_GUN_STATE");
- // return;
- // }
- //listmsg.Items.Add("Notification enabled");
- // }
- }
- #endregion
-
- #region 缩放Get
- private void btnenlargeGet_Click(object sender, EventArgs e)
- {
- float ret = iSEM.GetMagnification();
- if (float.IsNaN(ret))
- {
- lblenlargeGet.Text = "NaN";
- txtenlargeSet.Enabled = false;
- btnenlargeSet.Enabled = false;
- }
- else
- {
- lblenlargeGet.Text = ret.ToString();
- 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))
- {
- lblWDGet.Text = "NaN";
- txtWDSet.Enabled = false;
- btnWDSet.Enabled = false;
- }
- else
- {
- lblWDGet.Text = ret.ToString();
- 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))
- {
- lblBrightnessGet.Text = "NaN";
- txtBrightnessSet.Enabled = false;
- btnBrightnessSet.Enabled = false;
- }
- else
- {
- lblBrightnessGet.Text = ret.ToString();
- 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))
- {
- lblContrastGet.Text = "NaN";
- txtContrastSet.Enabled = false;
- btnContrastSet.Enabled = false;
- }
- else
- {
- lblContrastGet.Text = ret.ToString();
- 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))
- {
- lblAstigmatismXGet.Text = "NaN";
- txtAstigmatismXSet.Enabled = false;
- btnAstigmatismXSet.Enabled = false;
- }
- else
- {
- lblAstigmatismXGet.Text = ret.ToString();
- 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))
- {
- lblAstigmatismYGet.Text = "NaN";
- txtAstigmatismYSet.Enabled = false;
- btnAstigmatismYSet.Enabled = false;
- }
- else
- {
- lblAstigmatismYGet.Text = ret.ToString();
- 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))
- {
- lblTiltAngleGet.Text = "NaN";
- txtTiltAngleSet.Enabled = false;
- btnTiltAngleSet.Enabled = false;
- }
- else
- {
- lblTiltAngleGet.Text = ret.ToString();
- 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.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))
- {
- lblScanRotationGet.Text = "NaN";
- txtScanRotationSet.Enabled = false;
- btnScanRotationSet.Enabled = false;
- }
- else
- {
- lblScanRotationGet.Text = ret.ToString();
- 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.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 btnOpenVoltage_Click(object sender, EventArgs e)
- {
- iSEM.CmdOpenVoltage();
- }
- #endregion
- #region 关闭电压
- private void btnCloseVoltage_Click(object sender, EventArgs e)
- {
- iSEM.CmdCloseVoltage();
- }
- #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
- private void btnDoSemDriftCorrn_Click(object sender, EventArgs e)
- {
- iSEM.SetTiltCorrectionOff();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- iSEM.SetTiltCorrectionOn();
- }
- private void FormUnitControl_FormClosing(object sender, FormClosingEventArgs e)
- {
- if(iSEM!=null)
- {
- iSEM.Dispose();
- }
- }
- private void btnCMDMCF_Click(object sender, EventArgs e)
- {
- iSEM.CMDMCFFilename("OPTON");
- }
- }
- }
|