123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using NLog;
- using SmartSEMControl;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MeasureThread
- {
- class Focus : IFocus
- {
- private Focusparam prm;
- private ISEMControl iSEM;
- private NLog.Logger log;
- public Focus(Focusparam prm, ISEMControl iSEM)
- {
- log = NLog.LogManager.GetCurrentClassLogger();
- this.prm = prm ?? throw new ArgumentNullException(nameof(prm));
- this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
- this.log = log ?? throw new ArgumentNullException(nameof(log));
- }
- public bool DoFocus()
- {
-
- //set voltage and SemIprobe
- bool mRet_VoltageFlag = iSEM.SetSEMVoltage(prm.voltage);
- Thread.Sleep(500);
- bool mRet_ElecFlag = iSEM.SetSEMIPROBE(prm.Iprobe / 1000000000);
- Thread.Sleep(500);
- // set magnification
- bool mRetMag=iSEM.SetMagnification(prm.mag);
- //float current = iSEM.GetMagnification();
- //while (Math.Abs(current - prm.mag) > 1)
- //{
- // iSEM.SetMagnification(prm.mag);
- // Thread.Sleep(200);
- // current = iSEM.GetMagnification();
- //}
- Thread.Sleep(500);
- //
- if (!TiltCorrection(54.0f))
- {
- return false;
- }
- if (!iSEM.SetWorkingDistance(prm.workingDis/1000))
- {
- //log.Error("测量线程报错:重新设置到标准工作距离失败。", false);
- return false;
- }
- // set the window of focusing.
- iSEM.SetReduced(402, 128, 400, 400);
- iSEM.CmdFocusScanSpeed(prm.ScanSpeed);//
- if (prm.IfAutoBrightnessAndContrast)
- {
- iSEM.SetAutoVideoBrightnessAndContrast();
- Thread.Sleep(5000);
- }
- else
- {
- iSEM.SetAutoVideoOff();
- Thread.Sleep(200);
- iSEM.SetBrightness(prm.brightness);//50.0f
- Thread.Sleep(200);
- iSEM.SetContrast(prm.contrast);//30.0f
- Thread.Sleep(200);
- }
- if (!ImageFocus1(true))
- {
- log.Error("测量线程报错:拉直操作自动对焦失败,程序退出。", false);
-
- return false;
- }
- iSEM.CloseReduced();
- Thread.Sleep(200);
- iSEM.SetAutoVideoBrightnessAndContrast();
-
- float cycle_time = iSEM.GetCycleTime();
- Thread.Sleep(100 + Convert.ToInt32(cycle_time));
- return true;
- }
- public void setFocusParam(Focusparam param)
- {
- prm = param;
- }
- //角度补偿
- public bool TiltCorrection(float a_fAngle)
- {
- if (!iSEM.SetTiltAngleOn())
- {
- return false;
- }
- Thread.Sleep(200);
- //恢复原始状态
- if (!iSEM.SetTiltAngle(a_fAngle))
- {
- return false;
- }
- return true;
- }
- //执行自动对焦
- public bool ImageFocus1(Boolean Is_Stig)
- {
-
- #region 执行蔡司自动对焦程序
- //服务地址
- string snumstr = @"http://192.168.1.101:8123";
- bool normalized;
-
- // 调用方法;只对焦不消像散
- if (Is_Stig)
- {
- string focusstig = XmlRpcClient.autofocusstig(10, 3, 3, 3, 0.7, snumstr);//,normalized
- if (focusstig != "success")
- {
- return false;
- }
- }
- else
- {
- string onlyfocus = XmlRpcClient.autofocus(10, 3, 3, true, snumstr);//,normalized
- if (onlyfocus != "success")
- {
- return false;
- }
- }
- #endregion
-
- return true;
- }
- }
- }
|