Measure.cs 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. //时间:20200610
  2. //作者:郝爽
  3. //功能:测量线程
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.IO;
  12. using System.Drawing;
  13. using System.Xml;
  14. using SmartSEMControl;
  15. using MeasureData;
  16. using FileManager;
  17. using WebManager;
  18. using OpenCvSharp;
  19. using DBManager;
  20. using Extender;
  21. using CookComputing.XmlRpc;
  22. namespace MeasureThread
  23. {
  24. #region 信息定义
  25. public delegate void ThreadStatusHandler(object sender, ThreadStatusEventArgs e); //声明委托
  26. public delegate void CutHolesStatusHandler(object sender, CutHolesStatusEventArgs e);
  27. //测量线程状态
  28. public class ThreadStatusEventArgs
  29. {
  30. //状态
  31. public Boolean State
  32. {
  33. get { return m_state; }
  34. set { m_state = value; }
  35. }
  36. private Boolean m_state;
  37. //时间
  38. public DateTime Time
  39. {
  40. get { return m_time; }
  41. set { m_time = value; }
  42. }
  43. private DateTime m_time;
  44. //步骤代码
  45. public String Step_Code
  46. {
  47. get { return step_Code; }
  48. set { step_Code = value; }
  49. }
  50. private String step_Code;
  51. //其他消息
  52. public String Message
  53. {
  54. get { return this.message; }
  55. set { this.message = value; }
  56. }
  57. private String message;
  58. //孔名
  59. public String HoleName
  60. {
  61. get { return this.holeName; }
  62. set { this.holeName = value; }
  63. }
  64. private String holeName;
  65. //图片信息
  66. public class PictureInformation
  67. {
  68. public String Picture_FullPath
  69. {
  70. get { return picture_FullPath; }
  71. set { picture_FullPath = value; }
  72. }
  73. private String picture_FullPath;
  74. public double Work_Voltage
  75. {
  76. get { return work_Voltage; }
  77. set { work_Voltage = value; }
  78. }
  79. private double work_Voltage;
  80. public double Magnification
  81. {
  82. get { return magnification; }
  83. set { magnification = value; }
  84. }
  85. private double magnification;
  86. public double Work_Distance
  87. {
  88. get { return work_Distance; }
  89. set { work_Distance = value; }
  90. }
  91. private double work_Distance;
  92. public String Work_Status
  93. {
  94. get { return work_Status; }
  95. set { work_Status = value; }
  96. }
  97. private String work_Status;
  98. }
  99. //图片信息实例类
  100. public PictureInformation Picture_Information
  101. {
  102. get { return picture_Information; }
  103. set { picture_Information = value; }
  104. }
  105. private PictureInformation picture_Information;
  106. //图像处理信息
  107. public class ImageInformation
  108. {
  109. public int Method_Name
  110. {
  111. get { return method_Name; }
  112. set { method_Name = value; }
  113. }
  114. private int method_Name;
  115. public Source_Img_Degree_Direction SIDD;
  116. public Cut_Position CP;
  117. public Cut_Success CS;
  118. public Trapezoid_Top_Center_Position TTCP;
  119. public Auto_Foucs AF;
  120. public Auto_Stigmatic AS;
  121. public Center_Position_OffsetAngle_Direction CPOD;
  122. public Measure_Size MS;
  123. public ImageInformation()
  124. {
  125. SIDD = new Source_Img_Degree_Direction();
  126. CP = new Cut_Position();
  127. CS = new Cut_Success();
  128. TTCP = new Trapezoid_Top_Center_Position();
  129. AF = new Auto_Foucs();
  130. AS = new Auto_Stigmatic();
  131. CPOD = new Center_Position_OffsetAngle_Direction();
  132. MS = new Measure_Size();
  133. }
  134. //1-计算原始图像偏移角度及方向
  135. public class Source_Img_Degree_Direction
  136. {
  137. public Boolean Is_Image = false;
  138. public double Degree
  139. {
  140. get { return degree; }
  141. set { degree = value; }
  142. }
  143. private double degree;
  144. public int Direction
  145. {
  146. get { return direction; }
  147. set { direction = value; }
  148. }
  149. private int direction;
  150. public int State
  151. {
  152. get { return state; }
  153. set { state = value; }
  154. }
  155. private int state;
  156. }
  157. //2-计算切割点位置
  158. public class Cut_Position
  159. {
  160. public Boolean Is_Image = false;
  161. public double Offsetx
  162. {
  163. get { return offsetx; }
  164. set { offsetx = value; }
  165. }
  166. private double offsetx;
  167. public double Offsety
  168. {
  169. get { return offsety; }
  170. set { offsety = value; }
  171. }
  172. private double offsety;
  173. public int State
  174. {
  175. get { return state; }
  176. set { state = value; }
  177. }
  178. private int state;
  179. }
  180. //3-是否切割成功
  181. public class Cut_Success
  182. {
  183. public Boolean Is_Image = false;
  184. public int State
  185. {
  186. get { return state; }
  187. set { state = value; }
  188. }
  189. private int state;
  190. }
  191. //4-计算切割后图像梯形区域上边中心点坐标
  192. public class Trapezoid_Top_Center_Position
  193. {
  194. public Boolean Is_Image = false;
  195. public double TopCenterX
  196. {
  197. get { return topCenterX; }
  198. set { topCenterX = value; }
  199. }
  200. private double topCenterX;
  201. public double TopCenterY
  202. {
  203. get { return topCenterY; }
  204. set { topCenterY = value; }
  205. }
  206. private double topCenterY;
  207. public int State
  208. {
  209. get { return state; }
  210. set { state = value; }
  211. }
  212. private int state;
  213. }
  214. //5-自动对焦
  215. public class Auto_Foucs
  216. {
  217. public Boolean Is_Image = true;
  218. public String Img_Path
  219. {
  220. get { return img_Path; }
  221. set { img_Path = value; }
  222. }
  223. private String img_Path;
  224. }
  225. //6-自动像闪
  226. public class Auto_Stigmatic
  227. {
  228. public Boolean Is_Image = true;
  229. public String Img_Path
  230. {
  231. get { return img_Path; }
  232. set { img_Path = value; }
  233. }
  234. private String img_Path;
  235. }
  236. //7-计算切割面区域中心坐标,以及偏移角度及方向
  237. public class Center_Position_OffsetAngle_Direction
  238. {
  239. public Boolean Is_Image = false;
  240. public double CenterX
  241. {
  242. get { return centerX; }
  243. set { centerX = value; }
  244. }
  245. private double centerX;
  246. public double CenterY
  247. {
  248. get { return centerY; }
  249. set { centerY = value; }
  250. }
  251. private double centerY;
  252. public double Degree
  253. {
  254. get { return degree; }
  255. set { degree = value; }
  256. }
  257. private double degree;
  258. public int Direction
  259. {
  260. get { return direction; }
  261. set { direction = value; }
  262. }
  263. private int direction;
  264. public int State
  265. {
  266. get { return state; }
  267. set { state = value; }
  268. }
  269. private int state;
  270. }
  271. //8-测量尺寸
  272. public class Measure_Size
  273. {
  274. public Boolean Is_Image = false;
  275. public int State
  276. {
  277. get { return state; }
  278. set { state = value; }
  279. }
  280. private int state;
  281. }
  282. }
  283. //图像处理信息实例类
  284. public ImageInformation Image_Information
  285. {
  286. get { return image_Information; }
  287. set { image_Information = value; }
  288. }
  289. private ImageInformation image_Information;
  290. public ThreadStatusEventArgs(string a_State)
  291. {
  292. picture_Information = new PictureInformation();
  293. image_Information = new ImageInformation();
  294. }
  295. }
  296. //切孔状态
  297. public class CutHolesStatusEventArgs
  298. {
  299. public string State
  300. {
  301. get { return m_state; }
  302. set { m_state = value; }
  303. }
  304. private string m_state;
  305. public string HoleName
  306. {
  307. get { return m_holeName; }
  308. set { m_holeName = value; }
  309. }
  310. private string m_holeName;
  311. public CutHolesStatusEventArgs(string a_state, string a_holeName)
  312. {
  313. this.m_state = a_state;
  314. this.m_holeName = a_holeName;
  315. }
  316. }
  317. #endregion
  318. public class Measure
  319. {
  320. NLog.Logger log;
  321. #region 变量定义
  322. //Web接口类
  323. public ImageProcess ImagePro = null;
  324. //SmartSEM远程路径
  325. public String RemoteELYPath = "";
  326. public String RemoteMLFPath = "";
  327. //扫描周期
  328. private float cycle_time = 0;
  329. //人工干预
  330. public int hand_intervene = 2;
  331. //样品台保护值
  332. public float X_Min = 0;
  333. public float X_Max = 0.13f;
  334. public float Y_Min = 0;
  335. public float Y_Max = 0.13f;
  336. public float Z_Min = 0;
  337. public float Z_Max = 0.05f;
  338. public float T_Min = -4;
  339. public float T_Max = 70;
  340. public float R_Min = -380;
  341. public float R_Max = 380;
  342. public float M_Min = 0;
  343. public float M_Max = 0.012f;
  344. public event ThreadStatusHandler SendThreadStatus; // 声明事件
  345. public event CutHolesStatusHandler SendCutHolesStatus; // 声明事件
  346. //定义一个全局的消息类
  347. ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");
  348. //全局只有一个fatorySEM
  349. static FactoryHardware factorySEM = FactoryHardware.Instance;
  350. ISEMControl iSEM = factorySEM.ISEM;
  351. //@的作用是不用转义字符\\只打一个就行
  352. const String ImageName0 = @"SEMStraighten.tif"; //传给客户,原始图像,为拉直操作
  353. const String ImageName1 = @"FIBStraighten.tif"; //传给客户,原始图像,为拉直操作
  354. //const String ImageName1 = @"SEMFindCutPostion.tif"; //传给客户,作水平校正
  355. const String ImageName2 = @"FIBCutPostion.tif";//传给客户,找到切割点
  356. const String ImageName31 = @"FIBBefore.tif";
  357. const String ImageName32 = @"FIBAfter.tif";
  358. const String ImageName4 = @"SEMTrapCP.tif";//传给客户,找到已经切割点
  359. const String ImageName5 = @"SEMDegreeTrap.tif";//传给客户,水平校正
  360. const String ImageName6 = @"SEMMagEnd.tif";//传给客户,测量层高
  361. const String ImageName7 = @"BeforeImage.tif";//计算感兴趣的区域
  362. const String ImageNameTwo_1 = @"SEMRegion.tif";//第一个测量区域拍照
  363. const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针
  364. const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针
  365. const String MacoScanPic = "Scan picture.MLF";//一般质量抓图的宏
  366. const String MacoGoodPic = "Good picture.MLF";//高质量抓图的宏
  367. const String MacoExportTif = "Export TIFF.MLF";// 导出有标尺的图像,这个图像为使用工具SmartSEM工具的图像
  368. const String ElyDeposition = @"Deposition.ely"; //沉积
  369. const String ElyCrossSection = @"CrossSection.ely"; //切割
  370. const float fMin = (float)0.0000002; //单位是米
  371. private Locate m_locate;
  372. private Focus m_focuse;
  373. private Photo m_photo;
  374. private ArgSend mArgSend;
  375. public Boolean key_stop = false;
  376. FibWork m_FibWork;
  377. PTWork m_PTWork;
  378. //int m_nWorkHoleNo = -1;
  379. public ThreadStatusEventArgs GetArgs()
  380. {
  381. return arg;
  382. }
  383. //测量文件
  384. private MeasureFile m_measureFile;
  385. public MeasureFile MeasureFile
  386. {
  387. get { return this.m_measureFile; }
  388. set { this.m_measureFile = value; }
  389. }
  390. //测量的切割孔,这个切孔的状态要保存的测量文件中去
  391. private List<MeasureData.CutHole> m_cutHoles;
  392. public List<MeasureData.CutHole> cutHoles
  393. {
  394. get { return this.m_cutHoles; }
  395. set { this.m_cutHoles = value; }
  396. }
  397. public MeasureParam MParam//测量参数对象
  398. {
  399. get { return this.m_measureFile.MParam; }
  400. //set { this.m_measureParam = value; }
  401. }
  402. //工作文件夹
  403. private string m_WorkingFolder;
  404. public string mWorkingFolder
  405. {
  406. get { return this.m_WorkingFolder; }
  407. set { this.m_WorkingFolder = value; }
  408. }
  409. //程序当前路径
  410. private string m_ProgramFolder = Directory.GetCurrentDirectory();
  411. //线程状态
  412. private ThreadStatus m_ThreadStatus;
  413. public ThreadStatus TStatus
  414. {
  415. get { return this.m_ThreadStatus; }
  416. set { this.m_ThreadStatus = value; }
  417. }
  418. #endregion
  419. //构造函数
  420. public Measure(String webServerIP, String webServerPort, String webServerUrl, MeasureFile a_measurefile)
  421. {
  422. m_measureFile = a_measurefile;
  423. //SmartSEM远程路径
  424. log = NLog.LogManager.GetCurrentClassLogger();
  425. TStatus = new ThreadStatus();
  426. cutHoles = new List<MeasureData.CutHole>();
  427. //配置远程连接
  428. ImagePro = new ImageProcess(webServerIP, webServerPort, webServerUrl);
  429. m_locate = new Locate(iSEM);
  430. m_focuse = new Focus(iSEM ,MParam.FocusServerIP,MParam.FocusServerPort);
  431. m_photo = new Photo(iSEM);
  432. mArgSend = new ArgSend(this, iSEM);
  433. }
  434. //初始化测量业务, 读测量文件,判断是否有可测试的切孔
  435. public bool InitMeasure()
  436. {
  437. log.Info("进入初始化函数");
  438. List<CutHole> listHoles = m_measureFile.ListCutHole;
  439. foreach (CutHole h in listHoles)
  440. {
  441. if (h.SWITCH == true)
  442. {
  443. m_cutHoles.Add(h);
  444. }
  445. }
  446. if (m_cutHoles.Count == 0) return false;
  447. if (MParam.IsEDSToRun == true)
  448. {
  449. log.Info("要进行能谱分析,初始化Xray数据库", true);
  450. Init_MeasDB();
  451. }
  452. //设置工作文件夹
  453. mWorkingFolder = m_measureFile.FilePath;
  454. for(int i=0;i<m_cutHoles.Count;i++)
  455. {
  456. m_cutHoles[i].InitPath(i, mWorkingFolder);
  457. }
  458. //检查硬件连接是否正常
  459. if (!iSEM.ConnectStatus())
  460. {
  461. MessageBox.Show("连接电镜失败!", "重要错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  462. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  463. log.Error("测量线程报错:连接硬件硬件连接失败", false);
  464. return false;
  465. }
  466. //设置SmartSEM远程路径
  467. //iSEM.SetRemoteELYPath(RemoteELYPath);
  468. //iSEM.SetRemoteMLFPath(RemoteMLFPath);
  469. iSEM.SetRemoteDesELYPath(m_measureFile.MParam.RemoteELYDesPath);
  470. iSEM.SetRemoteDesMLFPath(m_measureFile.MParam.RemoteMLFDesPath);
  471. m_FibWork = new FibWork(iSEM, MParam.RemoteFIBOriginalEly);
  472. m_PTWork = new PTWork(iSEM, MParam.RemotePTOriginalEly);
  473. iSEM.SetScanRotationOff();
  474. Thread.Sleep(200);
  475. //20.光束等复位
  476. iSEM.SetBeamShiftX(0);
  477. Thread.Sleep(200);
  478. iSEM.SetBeamShiftY(0);
  479. Thread.Sleep(200);
  480. return true;
  481. }
  482. //给前台UI发送消息步骤
  483. public void SendMsg(string step_code)
  484. {
  485. arg.Step_Code = step_code;
  486. arg.Time = DateTime.Now;
  487. SendThreadStatus(this, arg);
  488. }
  489. //给前台UI发送孔状态信息
  490. public void SendCutHoleMsg(string a_state, string a_holeName)
  491. {
  492. CutHolesStatusEventArgs arg = new CutHolesStatusEventArgs(a_state, a_holeName);
  493. arg.HoleName = a_holeName;
  494. arg.State = a_state;
  495. SendCutHolesStatus(this, arg);
  496. }
  497. //测量流程
  498. public void DoMeasure()
  499. {
  500. //创建线程的测量状态的更新
  501. this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);
  502. //将停止键复位
  503. key_stop = false;
  504. //开始测量就将模式设置为SEM
  505. log.Info("测量线程:开始切换到SEM模式", true);
  506. if (!iSEM.CmdFIBModeSEM())
  507. {
  508. log.Error("测量线程报错:开始切换到SEM模式失败。", false);
  509. return;
  510. }
  511. arg.Picture_Information.Work_Status = "SEM";
  512. //开始做各个孔的测量
  513. for (int currHoleNo = 0; currHoleNo < m_cutHoles.Count; currHoleNo++)
  514. {
  515. var currHole = m_cutHoles[currHoleNo];
  516. //判断孔状态
  517. if (currHole.STATE != State.Ready)
  518. {
  519. log.Warn("测试孔" + currHole.HoleName + "状态非就绪,不予测量。", true);
  520. continue;
  521. }
  522. log.Warn("测量线程:第"+ currHoleNo.ToString() + "分析点,名称:" + currHole.HoleName + " 开始测量。", true);
  523. currHole.START = DateTime.Now;
  524. currHole.STATE = State.InProcess;
  525. SendCutHoleMsg(((int)currHole.STATE).ToString(), currHole.HoleName);
  526. //开始测量
  527. if (!HoleMeasure(currHole))
  528. {
  529. currHole.STATE = State.Failed;
  530. currHole.END = DateTime.Now;
  531. SendCutHoleMsg(((int)currHole.STATE).ToString(), currHole.HoleName);
  532. Thread.Sleep(3000);
  533. continue;
  534. }
  535. //保存文件,将测量状态更改
  536. currHole.STATE = State.Success;
  537. currHole.END = DateTime.Now;
  538. SendCutHoleMsg(((int)currHole.STATE).ToString(), currHole.HoleName);
  539. if (key_stop)
  540. {
  541. log.Error("用户停止测量");
  542. break;
  543. }
  544. //两个点之间更换,加延时以便完成显示
  545. Thread.Sleep(3000);
  546. }
  547. m_measureFile.Save(); //save all the measure info into Xml file.
  548. }
  549. /// <summary>
  550. ///13. 自动 定位功能,沉积
  551. /// </summary>
  552. /// <returns></returns>
  553. public bool GetFIBPosition(CutHole currHole)
  554. {
  555. float px = 0;
  556. int state = 1;
  557. log.Info("测量线程:FIB自动定位放大倍数" + MParam.Location_Magnification.ToString(), true);
  558. Thread.Sleep(200);
  559. if (!m_focuse.SetMagnification(MParam.Location_Magnification))// the m_focuse object is used to set magnification.
  560. {
  561. log.Error("测量线程报错:13.自动定位、沉积-自动定位放大倍数" + MParam.Location_Magnification.ToString() + "控制失败", false);
  562. return false;
  563. }
  564. arg.State = true;
  565. arg.Message = "放大" + MParam.Location_Magnification.ToString("0.0") + "倍成功";
  566. SendMsg("2-0");
  567. //判断是否停止进程
  568. if (key_stop)
  569. {
  570. log.Info("停止键按下。", true);
  571. return false;
  572. }
  573. log.Info("测量线程:切换到FIB模式。", true);
  574. //6.设置FIB拍照参数——扫描时间、束流等
  575. //7.控制FIB自动亮度、对比度
  576. Thread.Sleep(200);
  577. if (!iSEM.CmdFIBModeFIB())
  578. {
  579. log.Error("测量线程报错:切换到FIB模式失败。", false);
  580. return false;
  581. }
  582. arg.State = true;
  583. arg.Picture_Information.Work_Status = "FIB";
  584. arg.Message = "FIB模式切换成功";
  585. SendMsg("2-1");
  586. Thread.Sleep(1000);
  587. //判断是否停止进程
  588. if (key_stop)
  589. {
  590. log.Info("停止键按下。", true);
  591. return false;
  592. }
  593. //刷亮度对比度
  594. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//iSEM.CmdSaveRate();
  595. Thread.Sleep(200);
  596. iSEM.SetAutoBright(100);
  597. Thread.Sleep(200);
  598. iSEM.SetAutoContrast(100);
  599. iSEM.SetAutoVideoBrightnessAndContrast();
  600. Thread.Sleep(10000);
  601. iSEM.SetAutoVideoOff();
  602. //8.控制FIB拍照
  603. Thread.Sleep(200);
  604. String fileName2 = currHole.data_path + "\\" + currHole.HoleName + "_" + MParam.Location_Magnification.ToString("0") + "_" + ImageName2;
  605. m_photo.GetParam().Mag = MParam.Location_Magnification;
  606. m_photo.GetParam().savePath = fileName2;
  607. if (!m_photo.TakePhoto())
  608. {
  609. log.Error("测量线程报错:FIB拍照失败。", false);
  610. return false;
  611. }
  612. mArgSend.SendArgumentToScreen("2-3", "FIB拍照成功",fileName2);
  613. //判断是否停止进程
  614. if (key_stop)
  615. {
  616. log.Info("停止键按下。", true);
  617. return false;
  618. }
  619. float x1=0,y1=0, x2=0, y2=0;
  620. //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
  621. log.Info("测量线程:调用图像处理接口,准备移动样品台", true);
  622. log.Info("文件名=" + fileName2, true);
  623. log.Info("样品类型=" + MParam.SampleType, true);
  624. log.Info("供应商名称=" + MParam.Firm, true);
  625. ImagePro.Img_Cut_Position(fileName2, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out x1, out y1, out x2, out y2, out state);
  626. log.Info("FIB梯形左上角和右上角位置信息= (" + x1.ToString() + ", " + y1.ToString() + "), (" + x2.ToString() + ", " + y2.ToString() + ")", true);
  627. log.Info("准备移动样品台返回状态=" + state.ToString(), true);
  628. if (state == 1)
  629. {
  630. m_FibWork.ModifyCutTemplate(x1, y1 ,x2, y2);
  631. //判断是否需要PT沉积,如果需要也要修改PT的ELY文件
  632. if (MParam.IfPT)
  633. {
  634. m_PTWork.ModifyPTTemp(x1,y1,x2,y2);
  635. }
  636. }
  637. else
  638. {
  639. log.Error("测量线程报错:自动定位图像接口返回0", false);
  640. return false;
  641. }
  642. iSEM.CmdFIBModeSEM();
  643. Thread.Sleep(200);
  644. if (key_stop)
  645. {
  646. log.Info("停止键按下", true);
  647. return false;
  648. }
  649. return true;
  650. }
  651. /// <summary>
  652. /// 14. FIB切割
  653. /// </summary>
  654. /// <returns></returns>
  655. public bool FIBCuting()
  656. {
  657. int state = 0;
  658. if (!iSEM.CmdFIBModeFIB())
  659. {
  660. log.Error("测量线程报错:切换到SEM模式失败", false);
  661. return false;
  662. }
  663. //arg.Message = "切换到FIB模式成功。";
  664. //arg.State = true;
  665. //SendMsg("2-7");
  666. Thread.Sleep(1000);
  667. m_focuse.SetMagnification(MParam.Location_Magnification);
  668. //14.自动控制FIB切割
  669. //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  670. //2.控制FIB进行切割
  671. //以上1、2步全部用ELY文件代替
  672. if (!m_FibWork.DoFIBWork())
  673. {
  674. log.Error("测量线程报错:" + arg.Message, false);
  675. return false;
  676. }
  677. arg.State = true;
  678. arg.Message = "FIB切割成功";
  679. SendMsg("2-8");
  680. Thread.Sleep(300);
  681. //判断是否停止进程
  682. if (key_stop)
  683. {
  684. log.Info("停止键按下", true);
  685. return false;
  686. }
  687. //做切割后SEM的拍照
  688. log.Info("测量线程:切割后SEM拍照", true);
  689. if (!iSEM.CmdFIBModeSEM())
  690. {
  691. log.Error("测量线程报错:切换到SEM模式失败", false);
  692. return false;
  693. }
  694. Thread.Sleep(1000);
  695. mArgSend.SendArgumentToScreen("3-0", "SEM模式切换成功");
  696. return true;
  697. }
  698. /// <summary>
  699. /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  700. /// </summary>
  701. /// <returns></returns>
  702. public bool MoveToCenter(CutHole currHole)
  703. {
  704. float x2 = 0, y2 = 0;
  705. int state = 0;
  706. //切换到SEM模式
  707. if (!iSEM.CmdFIBModeSEM())
  708. {
  709. log.Error("测量线程报错:" + arg.Message, false);
  710. return false;
  711. }
  712. Thread.Sleep(1000);
  713. if (key_stop)
  714. {
  715. log.Info("停止键按下", true);
  716. return false;
  717. }
  718. String fileName4 = currHole.data_path + "\\" + MParam.Firm + "-" + MParam.MoveToCenterMagnification.ToString("0") + "-" +currHole.HoleName + "-" + ImageName4;
  719. //add by zjx 2020-12-21 根据客户的需求修改图片的名称 end
  720. log.Info("fileName4=" + fileName4, true);
  721. float mag = MParam.MoveToCenterMagnification;
  722. m_photo.GetParam().Mag = mag;
  723. m_photo.GetParam().savePath = fileName4;
  724. m_photo.TakePhoto();
  725. //arg.Message = "SEM拍照成功";
  726. mArgSend.SendArgumentToScreen("3-2", "SEM拍照成功", fileName4);
  727. if (key_stop)
  728. {
  729. return false;
  730. }
  731. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  732. //5.根据坐标控制SEM移动到切孔位置,居中
  733. log.Info("测量线程:图像处理接口,准备移动样品台", true);
  734. log.Info("文件名=" + fileName4, true);
  735. ImagePro.Img_Trapezoid_Top_Center_Position(fileName4, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out x2, out y2, out state);
  736. log.Info("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
  737. log.Info("准备移动样品台返回状态=" + state.ToString(), true);
  738. if (state == 1)
  739. {
  740. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  741. if (!m_locate.MoveToPixByMoveStage(x2, y2))
  742. {
  743. log.Error("测量线程报错:" + arg.Message, false);
  744. return false;
  745. }
  746. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置成功";
  747. mArgSend.SendArgumentToScreen("3-3",arg.Message);
  748. //add by zjx 2020-12-21 根据客户的需求修改图片的名称
  749. // String fileName10 = currHole.data_path + "\\" + MParam.Firm + "-" + MParam.Location_Magnification.ToString("0") + "-" + currHole.HoleName + "-" + ImageName10;
  750. //add by zjx 2020-12-21 根据客户的需求修改图片的名称 end
  751. //log.Info("fileName10====================" + fileName10, true);
  752. //m_photo.GetParam().savePath = fileName10;
  753. }
  754. else
  755. {
  756. log.Error("测量线程报错:" + arg.Message, false);
  757. return false;
  758. }
  759. //判断是否停止进程
  760. return true;
  761. }
  762. /// <summary>
  763. /// 17.自动控制SEM拍截面照
  764. /// </summary>
  765. /// <returns></returns>
  766. public bool ShotSection(CutHole currHole,ref List<String> limg_path, ref List<float> lsize)
  767. {
  768. int state = 0;
  769. #region 对焦
  770. Focusparam fprm = new Focusparam()
  771. {
  772. //voltage = MParam.Photograph_Voltage,
  773. mag = MParam.Photograph_Magnification,
  774. reduceWindowPos = new System.Drawing.Point(402, 128),
  775. reduceWinHeight = 600,
  776. reduceWinWidth = 600,
  777. IfAutoBrightnessAndContrast = true,
  778. brightness = 50.0f,
  779. contrast = 30.0f,
  780. tiltCorrAngle = MParam.Correction_Angle_Inside,
  781. workingDis = 5.0f,
  782. };
  783. //add by sun 2020-12-17 解决3大类样品FIB下亮度过白导致无法识别问题
  784. float m_TempBrightness=MParam.ShotSectionManualBrightness;
  785. float m_TempContrast = MParam.ShotSectionManualConstrast;
  786. fprm.brightness = m_TempBrightness;
  787. fprm.contrast = m_TempContrast;
  788. m_focuse.setFocusParam(fprm);
  789. m_focuse.DoFocusBySetMainParameter();
  790. Thread.Sleep(200);
  791. if (key_stop)
  792. {
  793. log.Info("停止键按下", true);
  794. return false;
  795. }
  796. //4、拍照,5、保存照片
  797. string fileName6 =currHole.data_path + "\\" + MParam.Firm + "-" + MParam.Photograph_Magnification.ToString("0") + "-" + currHole.HoleName + "-" + ImageName6;
  798. log.Info("fileName6=" + fileName6, true);
  799. PhotoParam phop = new PhotoParam()
  800. {
  801. Mag = MParam.Photograph_Magnification,
  802. savePath=fileName6,
  803. };
  804. m_photo.SetPhotoParam(phop);
  805. if (!m_photo.TakePhoto())
  806. {
  807. log.Error("测量线程报错:" + arg.Message, false);
  808. return false;
  809. }
  810. mArgSend.SendArgumentToScreen("3-7", "SEM拍照成功", fileName6);
  811. //判断是否停止进程
  812. if (key_stop)
  813. {
  814. log.Info("停止键按下", true);
  815. return false;
  816. }
  817. #endregion
  818. #region 获取两个位置上及放大倍数
  819. //计算两个测量区域坐标
  820. List<System.Drawing.Point> ct = new List<System.Drawing.Point>();
  821. List<float> mag = new List<float>();
  822. System.Drawing.Point ct0;
  823. float magMax;
  824. //log.Info("测量线程:图像处理接口,计算两个放大区域坐标,输入图像" + fileName6.ToString() + "控制失败", true);
  825. ImagePro.Img_Measure_Region_Position(fileName6, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out ct, out mag, out ct0, out state);
  826. string s = "";
  827. for (int i = 0; i < ct.Count; i++)
  828. {
  829. s += " 输出观测点" + i.ToString() + "为(" + ct[i].X.ToString() + "," + ct[i].Y.ToString() + ")"
  830. + "放大倍数=" + mag[i];
  831. }
  832. log.Info("测量线程:图像处理接口返回值为" + state.ToString() +
  833. ",计算放大区域坐标,输入图像" + fileName6.ToString() +
  834. "输入样品 " + Convert.ToInt32(MParam.SampleTypeNo()) +
  835. " 输入厂商" + MParam.Firm.ToString() +
  836. s +
  837. " 输出对焦点为(" + ct0.X.ToString() + "," + ct0.Y.ToString() + ")", true);
  838. #endregion
  839. if (state == 1 && ct.Count != 0 && mag.Count != 0)
  840. {
  841. // mArgSend.SendArgumentToScreen("3-10", "获取位置及放大倍数成功");
  842. #region 记录初始设置的BeamShift的百分比和样品台XY位置
  843. m_locate.RecordCurrentBeamShiftAndStagePosition();
  844. #endregion
  845. //找到放大倍数最大值
  846. magMax = mag[0];
  847. for (int m = 1; m < mag.Count; m++)
  848. {
  849. if (mag[m] > magMax)
  850. {
  851. magMax = mag[m];
  852. }
  853. }
  854. #region 移动到梯形左上角
  855. //20201127将视野移动到梯形左上角位置
  856. m_locate.MoveToPix(ct0.X, ct0.Y,MParam.PixelSizeCor);
  857. log.Info("测量线程:移动到对焦点( " + ct0.X.ToString()
  858. + "," + ct0.Y.ToString() + ")", true);
  859. Thread.Sleep(200);
  860. //循环升级对焦,每次放大3000倍
  861. int startmag=7000;
  862. if (magMax < 7000)
  863. {
  864. startmag =(int) magMax;
  865. }
  866. for (int curmag= startmag; curmag < magMax+3000; curmag += 5000)
  867. {
  868. fprm.IfAutoBrightnessAndContrast = true;
  869. fprm.reduceWinHeight = 480;
  870. fprm.reduceWinWidth = 450;
  871. fprm.tiltCorrAngle = MParam.Correction_Angle_Inside;
  872. fprm.mag = curmag;
  873. m_focuse.setFocusParam(fprm);
  874. m_focuse.DoFocusBySetMainParameter();
  875. }
  876. #endregion
  877. m_photo.EnforceContrast() ;//enter inside,enforce the brightness.
  878. #region 循环拍照
  879. for (int n = 0; n < ct.Count; n++)
  880. {
  881. #region 恢复到拍照的状态
  882. m_locate.RestoreLastBeamShiftAndStagePosition();
  883. #endregion
  884. #region 移动到指定点位置
  885. LocateParam lprm = new LocateParam()
  886. {
  887. PositionX = ct[n].X,
  888. PositionY = ct[n].Y,
  889. PixelSize_Y_cur = MParam.PixelSizeCor,
  890. };
  891. if (!m_locate.MoveToPix(lprm.PositionX,lprm.PositionY,lprm.PixelSize_Y_cur))
  892. {
  893. //移动到第一个点失败
  894. log.Error("测量线程报错:移动到点(" + ct[n].X.ToString() + "," + ct[n].Y.ToString() + ")失败", false);
  895. }
  896. log.Info("测量线程:移动到第1个点( " + ct[n].X.ToString()
  897. + "," + ct[n].Y.ToString() + ")", true);
  898. #endregion
  899. log.Info("测量线程:移动到第一个点位置完成!", true);
  900. #region 拍照
  901. //add by zjx 2020-12-21 根据客户的需求修改图片的名称
  902. String fileName7 = currHole.data_path + "\\" + MParam.Firm + "-" + mag[n].ToString() + "-" + currHole.HoleName + "-" + n.ToString() + "-" + ImageNameTwo_1;
  903. //add by zjx 2020-12-21 根据客户的需求修改图片的名称 end
  904. log.Info("fileName7=" + fileName7, true);
  905. if (n == 0)//如果是第一个观测点就做角度修正
  906. {
  907. String fileName5 = currHole.data_path + "\\" + MParam.Firm + "-" + mag[n].ToString("0") + "-" + currHole.HoleName + "-" + ImageName5;
  908. //add by zjx 2020-12-21 根据客户的需求修改图片的名称 end
  909. log.Info("纠正前 fileName5=" + fileName5, true);
  910. m_photo.GetParam().savePath = fileName5;
  911. m_photo.GetParam().Mag = mag[n];
  912. m_photo.TakePhoto();
  913. //8,计算切割面区域偏移角度及方向
  914. float degree = 0;
  915. int direction = 0;
  916. ImagePro.Img_Center_Position_OffsetAngle_Direction(fileName5, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out degree, out direction, out state);
  917. log.Info("测量线程:拍照角度移动,输入图像" + fileName5 + "输出角度为" + degree.ToString() + "输出方向为" + direction.ToString() + "返回值为" + state.ToString(), true);
  918. log.Info("样品" + currHole.HoleNo.ToString() + "计算切割面区域的角度=" + degree.ToString(), true);
  919. //接口返回像素,*pixelsize,得到坐标点。判断移动方式
  920. if (state == 1)
  921. {
  922. //梯形角度
  923. iSEM.SetScanRotationOn();
  924. Thread.Sleep(200);
  925. //20201128陈工要求,谭博返回角度*0.7
  926. iSEM.SetScanRotation(Convert.ToSingle(degree * MParam.ScanRotCor));
  927. Thread.Sleep(200);
  928. string Message = "图像接口返回角度为:" + degree.ToString();
  929. mArgSend.SendArgumentToScreen("3-8", Message, fileName5);
  930. }
  931. else
  932. {
  933. log.Error("测量线程报错:" + arg.Message, false);
  934. }
  935. //纠正后再次拍照
  936. log.Info("纠正后拍照!");
  937. m_photo.GetParam().savePath = fileName7;
  938. m_photo.GetParam().Mag = mag[n];
  939. m_photo.TakePhoto();
  940. }
  941. else
  942. {
  943. m_photo.GetParam().savePath = fileName7;
  944. m_photo.GetParam().Mag = mag[n];
  945. m_photo.TakePhoto();
  946. }
  947. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
  948. Thread.Sleep(200);
  949. cycle_time = iSEM.GetCycleTime();
  950. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  951. Thread.Sleep(200);
  952. mArgSend.SendArgumentToScreen("3-11", "移动到第"+n+"个点位置拍照成功",fileName7);
  953. // add by zjx 在测量图上显示放大倍数和像素大小等信息
  954. limg_path.Add(fileName7);
  955. //获取像素大小
  956. lsize.Add(iSEM.GetPixelSize());
  957. float size = iSEM.GetPixelSize();
  958. SaveMeasDataPic(fileName7, mag[n], size);
  959. Thread.Sleep(1000);
  960. #endregion
  961. }
  962. #endregion
  963. }
  964. else
  965. {
  966. log.Error("测量线程报错:" + arg.Message, false);
  967. }
  968. //判断是否停止进程
  969. if (key_stop)
  970. {
  971. log.Info("停止键按下", true);
  972. return false;
  973. }
  974. iSEM.SetTiltAngleOff();
  975. Thread.Sleep(200);
  976. iSEM.SetScanRotationOff();
  977. Thread.Sleep(200);
  978. iSEM.SetBeamShiftX(0);
  979. Thread.Sleep(200);
  980. iSEM.SetBeamShiftY(0);
  981. Thread.Sleep(200);
  982. //判断是否停止进程
  983. if (key_stop)
  984. {
  985. return false;
  986. }
  987. return true;
  988. }
  989. public bool HoleMeasure(CutHole currHole)
  990. {
  991. //第一步:位置恢复
  992. #region 第一步:坐标恢复
  993. mArgSend.SendArgumentToScreen("0-0","");// tell the HMI that we are doing this step.
  994. log.Info("测量线程:恢复样品分析点位置(R,X,Y,Z) = (" + currHole.Position.R.ToString() + ","
  995. + currHole.Position.X.ToString() + ","
  996. + currHole.Position.Y.ToString() + ","
  997. + currHole.Position.Z.ToString() + ")", true);
  998. Locate lo = new Locate(iSEM);
  999. lo.LocateCutHolePosition(currHole, MParam.IfTilt);
  1000. if (!m_focuse.SetMagnification(MParam.Location_Magnification))
  1001. {
  1002. log.Error("测量线程报错:设置定位放大倍数" + MParam.Location_Magnification.ToString() + "控制失败", false);
  1003. return false;
  1004. }
  1005. if (key_stop)
  1006. {
  1007. log.Info("停止键被按下", true);
  1008. return false;
  1009. }
  1010. arg.HoleName = currHole.HoleName;
  1011. arg.State = true;
  1012. arg.Message = "样品台移动到观测点:" + currHole.HoleName + "的位置成功。";
  1013. SendMsg("0-0");
  1014. #endregion
  1015. //第二步:设置电流电压
  1016. //add by sun 2020-12-17 不同样品电压、电流不一致,应设置灵活。123456类电压2000V电流200pA,7类5000V 500pA,能谱 7000V 500pA
  1017. log.Warn("测量线程:设置拍照电压 123456类电压2000V电流200pA,7类5000V 500pA,能谱 7000V 500pA 目前是第 " + MParam.SampleType + " 类!", true);
  1018. if (!SetVoltageAndIPROBE())
  1019. {
  1020. log.Error("测量线程:设置电压电流失败!目前是第 " + MParam.SampleType + " 类!", false);
  1021. return false;
  1022. }
  1023. //第三步:自动化流程-每个点都需要补偿54度
  1024. if (MParam.IsTiltCorrectionToRun == true)
  1025. {
  1026. mArgSend.SendArgumentToScreen("0-1", "");// tell the HMI that we are doing this step.
  1027. log.Info("测量线程:倾斜补偿角度为" + MParam.Correction_Angle_OutSide.ToString(), true);
  1028. if (!m_focuse.TiltCorrection(MParam.Correction_Angle_OutSide))
  1029. {
  1030. log.Error("测量线程报错:倾斜补偿角度为54度失败", false);
  1031. return false;
  1032. }
  1033. arg.Message = "角度补偿54度成功!";
  1034. arg.State = true;
  1035. SendMsg("0-1");
  1036. }
  1037. //判断是否停止进程
  1038. if (key_stop)
  1039. {
  1040. log.Info("停止键按下", true);
  1041. return false;
  1042. }
  1043. //第四步:拉直 ( 2是5/6类样品,不需要拉直)
  1044. if (MParam.IsStraightenToRun)
  1045. {
  1046. mArgSend.SendArgumentToScreen("1-0", "");// tell the HMI that we are doing this step.
  1047. log.Warn("测量线程:拉直操作开始!", true);
  1048. if (!Straighten_Handle(currHole))
  1049. {
  1050. log.Info("测量线程报错:拉直操作失败。", true);
  1051. return false;
  1052. }
  1053. log.Info("测量线程:拉直操作结束!", true);
  1054. }
  1055. else
  1056. {
  1057. arg.Message = "拉直操作自动对焦成功!";
  1058. arg.State = true;
  1059. SendMsg("1-0");
  1060. Thread.Sleep(200);
  1061. arg.Message = "拉直拍照成功!";
  1062. arg.Picture_Information.Picture_FullPath = "";
  1063. arg.State = true;
  1064. SendMsg("1-1");
  1065. Thread.Sleep(200);
  1066. arg.Message = "拉直操作完成";
  1067. arg.State = true;
  1068. SendMsg("1-2");
  1069. Thread.Sleep(200);
  1070. }
  1071. //判断是否停止进程
  1072. if (key_stop)
  1073. {
  1074. log.Info("停止键按下。", true);
  1075. return false;
  1076. }
  1077. //第五步: 定位功能 PT沉积
  1078. if (MParam.IsGetFibPositionToRun==true)
  1079. {
  1080. mArgSend.SendArgumentToScreen("2-0", "");// tell the HMI that we are doing this step.
  1081. log.Warn("测量线程:PIB切割自动定位开始!", true);
  1082. if (!GetFIBPosition(currHole))
  1083. {
  1084. log.Error("测量线程报错:自动定位失败,程序退出。", false);
  1085. return false;
  1086. }
  1087. log.Info("测量线程:自动定位结束!", true);
  1088. }
  1089. //11.自动工具样品类型参数确定是否需要PT沉积
  1090. log.Info("是否PT:" + MParam.IfPT.ToString());
  1091. if (MParam.IfPT)
  1092. {
  1093. arg.State = true;
  1094. arg.Message = "PT沉积";
  1095. SendMsg("2-4");
  1096. m_PTWork.DoWholePTWork();
  1097. }
  1098. arg.State = true;
  1099. arg.Message = "";
  1100. SendMsg("2-5");
  1101. arg.State = true;
  1102. arg.Message = "";
  1103. SendMsg("2-6");
  1104. //判断是否停止进程
  1105. if (key_stop)
  1106. {
  1107. log.Info("停止键按下。", true);
  1108. return false;
  1109. }
  1110. //14.自动控制FIB切割 del by sun 2020-12-15 temp
  1111. if (MParam.IsFibCutingToRun == true)
  1112. {
  1113. mArgSend.SendArgumentToScreen("2-8", "");// tell the HMI that we are doing this step.
  1114. log.Warn("测量线程:自动控制FIB切割开始!==" + MParam.IsFibCutingToRun, true);
  1115. if (!FIBCuting())
  1116. {
  1117. log.Error("测量线程报错:自动控制FIB切割失败。", false);
  1118. return false;
  1119. }
  1120. log.Info("测量线程:自动控制FIB切割结束!", true);
  1121. }
  1122. //del by sun 2020-12-15 temp end
  1123. //判断是否停止进程
  1124. if (key_stop)
  1125. {
  1126. return false;
  1127. }
  1128. //16.找到切割位置
  1129. if (MParam.IsMoveToCenterToRun == true)
  1130. {
  1131. mArgSend.SendArgumentToScreen("3-2", "");// tell the HMI that we are doing this step.
  1132. log.Info("测量线程:找到切割位置开始!移动到视野中心", true);
  1133. if (!MoveToCenter(currHole))
  1134. {
  1135. return false;
  1136. }
  1137. log.Info("测量线程:找到切割位置结束!", true);
  1138. //判断是否停止进程
  1139. if (key_stop)
  1140. {
  1141. return false;
  1142. }
  1143. }
  1144. List<String> limg_path = new List<string>();
  1145. List<float> lsize = new List<float>();
  1146. if (MParam.IsShotSectionToRun == true)
  1147. {
  1148. mArgSend.SendArgumentToScreen("3-7", "");// tell the HMI that we are doing this step.
  1149. log.Warn("测量线程:自动控制SEM拍截面照开始", true);
  1150. //将过程17最后的拍照图片提出给18步进行调用
  1151. //17.自动控制SEM拍截面照
  1152. if (!ShotSection(currHole, ref limg_path, ref lsize))
  1153. {
  1154. log.Error("拍截面照失败!");
  1155. return false;
  1156. }
  1157. log.Info("测量线程:自动控制SEM拍截面照结束!", true);
  1158. //18.自动层高分析
  1159. if (MParam.IsLayerAnalysisToRun == true)
  1160. {
  1161. mArgSend.SendArgumentToScreen("3-12", "");// tell the HMI that we are doing this step.
  1162. log.Warn("测量线程:自动层高分析开始", true);
  1163. float size = iSEM.GetPixelSize();
  1164. int state = 1;
  1165. ImagePro.Img_Measure_Height(limg_path, lsize, currHole.data_path + "\\", Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out state);
  1166. if (state == 0)
  1167. {
  1168. log.Error("层高分析失败!");
  1169. return false;
  1170. }
  1171. arg.State = true;
  1172. arg.Message = "层高分析成功";
  1173. SendMsg("3-12");
  1174. log.Info("测量线程:自动层高分析结束!", true);
  1175. }
  1176. }
  1177. //判断是否停止进程
  1178. if (key_stop)
  1179. {
  1180. return false;
  1181. }
  1182. //}
  1183. //add by zjx 2020-12-18 为了测试只做能谱部分 end
  1184. //19.能谱分析
  1185. if (MParam.IsEDSToRun)
  1186. {
  1187. mArgSend.SendArgumentToScreen("4-0", "");// tell the HMI that we are doing this step.
  1188. if (currHole.HoleNo + 1 == m_cutHoles.Count)//最后样品分析点才跑能谱
  1189. {
  1190. log.Warn("测量线程:能谱分析开始===" + MParam.IsEDSToRun, true);
  1191. EDS_Analysis(currHole);
  1192. log.Info("测量线程:能谱分析结束===" + MParam.IsEDSToRun, true);
  1193. }
  1194. }
  1195. //20.复位
  1196. if (MParam.IsBeamShiftResetToRun == true)
  1197. {
  1198. log.Info("测量线程:复位开始", true);
  1199. BeamShiftReset();
  1200. }
  1201. return true;
  1202. }
  1203. //初始化拉直操作
  1204. public bool Straighten_Handle(CutHole currHole)
  1205. {
  1206. //设置拉直的放大倍数
  1207. log.Info("测量线程:设置拉直放大倍数,放大倍数为" + MParam.Straighten_Magnification.ToString(), true);
  1208. if (!m_focuse.SetMagnification(MParam.Straighten_Magnification))
  1209. {
  1210. log.Error("测量线程报错:设置SEM放大倍数为拉直放大倍数失败,放大倍数为" + MParam.Straighten_Magnification.ToString(), false);
  1211. return false;
  1212. }
  1213. //arg.Message = "拉直放大倍数设置成功!";
  1214. //arg.State = true;
  1215. //SendMsg("0-2");
  1216. //1、自动对焦
  1217. log.Info("测量线程:拉直操作前自动对焦开始", true);
  1218. var p = new Focusparam();
  1219. p.IfAutoBrightnessAndContrast = true;
  1220. p.mag = MParam.Straighten_Magnification;
  1221. p.reduceWindowPos = new System.Drawing.Point(402, 128);
  1222. p.reduceWinWidth = 400;
  1223. p.reduceWinHeight = 400;
  1224. p.brightness = MParam.StraightenManualBrightness;
  1225. p.contrast = MParam.StraightenManualContrast;
  1226. m_focuse.setFocusParam(p);
  1227. if (!m_focuse.DoFocusByNewMagnification(MParam.Straighten_Magnification))
  1228. {
  1229. log.Error("测量线程报错:拉直操作自动对焦失败,程序退出。", false);
  1230. return false;
  1231. }
  1232. Thread.Sleep(1000);
  1233. arg.Message = "拉直操作自动对焦成功!";
  1234. arg.State = true;
  1235. SendMsg("1-0");
  1236. //判断是否停止进程
  1237. if (key_stop)
  1238. {
  1239. log.Info("停止键按下。", true);
  1240. return false;
  1241. }
  1242. //2、拍张照片
  1243. String fileName0 = currHole.data_path + "\\" + currHole.HoleName + "_" + MParam.Straighten_Magnification.ToString("0") + "_" + ImageName0;
  1244. log.Info("测量线程:设置保存图像的是扫描速度保存图像" + fileName0, true);
  1245. //拍照前改变速度,延时
  1246. m_photo.GetParam().Mag = p.mag;
  1247. m_photo.GetParam().savePath = fileName0;
  1248. if (!m_photo.TakePhoto())
  1249. {
  1250. log.Error("测量线程报错:拉直拍照失败", false);
  1251. return false;
  1252. }
  1253. arg.Message = "拉直拍照成功!";
  1254. arg.Picture_Information.Picture_FullPath = fileName0;
  1255. arg.State = true;
  1256. SendMsg("1-1");
  1257. //3、华为接口,获取旋转角度
  1258. float degree = 0;
  1259. int direction = 0;
  1260. int state = 1;
  1261. ImagePro.Img_OffsetAngle_Direction(fileName0, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out degree, out direction, out state);
  1262. log.Info("测量线程:使用图像处理接口:样品" + currHole.HoleNo.ToString() + "初始化拉直角度=" + degree.ToString(), true);
  1263. log.Info("图像处理结果拉直角度=" + degree.ToString(), true);
  1264. log.Info("图像处理结果拉直角度=" + degree.ToString(), true);
  1265. if (state == 0)
  1266. {
  1267. log.Info("测量线程:图像处理接口参数state返回为零", false);
  1268. return false;
  1269. }
  1270. if (direction == 2)
  1271. {
  1272. degree = -degree;
  1273. }
  1274. if (degree != 0)
  1275. {
  1276. //4、拉直,旋转R轴
  1277. log.Info("测量线程:图像拉直,旋转角度" + degree.ToString(), true);
  1278. m_locate.RotateStageByDeltaR(degree);
  1279. //判断是否停止进程
  1280. if (key_stop)
  1281. {
  1282. log.Info("停止键按下", true);
  1283. return false;
  1284. }
  1285. }
  1286. arg.Message = "拉直操作完成";
  1287. arg.State = true;
  1288. SendMsg("1-2");
  1289. return true;
  1290. }
  1291. #region 能谱所有参数
  1292. //全局只有一个Extender
  1293. static ExtenderInterface factoryExtender = ExtenderInterface.Instance;
  1294. public IExtenderControl iExtender = null;
  1295. const int ScanFieldSize = 1142;
  1296. MeasureDB m_MeasDB = null;
  1297. int m_nXrayId = 0;
  1298. const String ImageNameEDS = @"EDSImage.tif"; //EDS能谱图片
  1299. const String ImageNameEDS4 = @"SEMTrapCPEDS.tif";//传给客户,找到已经切割点
  1300. const String ImageNameEDS5 = @"SEMDegreeTrapEDS.tif";//传给客户,水平校正
  1301. const String ImageNameEDS6 = @"SEMMagEndEDS.tif";//传给客户,测量层高
  1302. /// <summary>
  1303. /// 做能谱分析
  1304. /// </summary>
  1305. /// <param name="a_CutHoleID">分析点视场ID,索引号</param>
  1306. /// <param name="a_CutHoleName">分析点视场名称</param>
  1307. /// <param name="a_FieldImagePositionID">分析点的视场位置ID,图像处理会返回多个Xray分析点,但我们这里只取第一个点所在的视场</param>
  1308. /// <returns>成功或失败</returns>
  1309. public bool DoEDS(CutHole currHole, int a_FieldImagePositionID)
  1310. {
  1311. try
  1312. {
  1313. string CutHoleName = currHole.HoleName;
  1314. //XrayID记录
  1315. log.Info("程序进入EDS测量!", true);
  1316. iExtender = factoryExtender.IExtender;
  1317. Thread.Sleep(500);
  1318. EDSParam param = MParam.EDSParam;
  1319. double dDwellTime = param.DwellTime;
  1320. int nImageType = param.ImageType;
  1321. double dScanSizes = param.ScanSize;
  1322. log.Info("dDwellTime=" + dDwellTime.ToString() + " nImageType=" + nImageType.ToString() + " dScanSizes=" + dScanSizes.ToString(), true);
  1323. iExtender.SetImageAcquistionSetting(dDwellTime, nImageType, dScanSizes);
  1324. string path = currHole.EDS_path;
  1325. string edsfn = path + "\\" + a_FieldImagePositionID.ToString() + "_" + ImageNameEDS;
  1326. log.Info("EDS_PATH=" + edsfn, true);
  1327. iExtender.GrabImage(edsfn, 0, 0, 0, 0, 0);//get the field eds image where the anylysis point locate.
  1328. arg.Picture_Information.Picture_FullPath = "";
  1329. arg.State = true;
  1330. SendMsg("4-5");//向界面发送指令:能谱拍照
  1331. //arg.State = false;
  1332. arg.Message = "";
  1333. arg.Picture_Information.Picture_FullPath = edsfn;
  1334. SendMsg("EDSPic");
  1335. //送给客户,计算感兴趣的区域
  1336. List<System.Drawing.Point> listPoints = new List<System.Drawing.Point>();
  1337. List<System.Drawing.Point> LinesStartPoint = new List<System.Drawing.Point>();
  1338. List<List<Segment>> Features = new List<List<Segment>>();
  1339. List<int> lines_height = new List<int>();
  1340. System.Drawing.Point area_pt = new System.Drawing.Point();
  1341. int width = 1;
  1342. int height = 1;
  1343. int AreasNo = 0;
  1344. long[] XrayData;
  1345. Dictionary<string, double> listElement;
  1346. int xrayCollectMode = param.XrayCollectMode;
  1347. switch (xrayCollectMode)
  1348. {
  1349. case 0://point mode
  1350. //点数据
  1351. int state = 0;
  1352. ImagePro.EDS_Param_Points(edsfn, a_FieldImagePositionID, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out listPoints, out state);
  1353. if (state == 0)
  1354. {
  1355. log.Error("点采集失败", false);
  1356. return false;
  1357. }
  1358. log.Info("返回 listPoints=" + listPoints.Count.ToString(), true);
  1359. if (!m_MeasDB.InsertAnylysisField(currHole.HoleNo, CutHoleName, currHole.EDS_path, listPoints.Count, Features.Count, a_FieldImagePositionID))
  1360. {
  1361. log.Error("插入分析视场失败", false);
  1362. }
  1363. iExtender.BeginMultipleAquisition();
  1364. Thread.Sleep(100);
  1365. //点采集
  1366. m_nXrayId = 0;
  1367. foreach (System.Drawing.Point pt in listPoints)
  1368. {
  1369. XrayData = new long[2000];
  1370. listElement = new Dictionary<string, double>();
  1371. if (iExtender.XrayPointCollecting(1000, pt.X, pt.Y , out XrayData, out listElement))
  1372. {
  1373. string ele = "";
  1374. foreach (var s in listElement)
  1375. {
  1376. ele += s.ToString();
  1377. }
  1378. log.Info("采集时间=1000", true);
  1379. log.Info("采集点:(" + pt.X.ToString() + ":" + pt.Y.ToString() + ") 元素:" + ele);
  1380. //写入数据库
  1381. m_nXrayId++;
  1382. log.Info("点采集结束,写入数据库开始--" + m_nXrayId.ToString(), true);
  1383. Boolean ret = m_MeasDB.InsertAPointXray(currHole.HoleNo, m_nXrayId, pt.X, pt.Y, XrayData, listElement, a_FieldImagePositionID);
  1384. Thread.Sleep(1000);
  1385. }
  1386. }
  1387. m_MeasDB.PointDataSubmitted();
  1388. iExtender.EndMultipleAquisition();
  1389. break;
  1390. case 1://line mode
  1391. log.Info("线扫描", true);
  1392. state = 0;
  1393. ImagePro.EDS_Param_Lines(edsfn, a_FieldImagePositionID, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out LinesStartPoint, out lines_height, out state);
  1394. string sp = "";
  1395. foreach (System.Drawing.Point p in LinesStartPoint)
  1396. {
  1397. sp += "(" + p.X + "," + p.Y + ")";
  1398. }
  1399. log.Info("线返回数据,lines=" + LinesStartPoint.Count.ToString() + " " + sp+"每条线的长度为:"+ lines_height[0].ToString(), true);
  1400. if (state == 1)
  1401. {
  1402. //将线转换为segment数据
  1403. log.Info("将线转换为segment数据", true);
  1404. for (int i = 0; i < LinesStartPoint.Count; i++)
  1405. {
  1406. int wholeHeight = lines_height[i];
  1407. int singleHeight = 3;//每5高度形成一个单元
  1408. for (int k = 0; k < wholeHeight; k += singleHeight)
  1409. {
  1410. List<Segment> feature = new List<Segment>();
  1411. for (int j = 0; j <= singleHeight; j++)
  1412. {
  1413. Segment segment = new Segment();
  1414. segment.X = LinesStartPoint[i].X;
  1415. segment.Y = LinesStartPoint[i].Y+j+k;
  1416. segment.Length = 1;
  1417. feature.Add(segment);
  1418. }
  1419. Features.Add(feature);
  1420. }
  1421. }
  1422. }
  1423. else
  1424. {
  1425. log.Error("线扫图片处理失败", false);
  1426. return false;
  1427. }
  1428. //线采集
  1429. m_nXrayId = 0;
  1430. iExtender.BeginMultipleAquisition();
  1431. //Thread.Sleep(100);
  1432. log.Info(" Features.Coun的长度为"+ Features.Count.ToString());
  1433. for (int i = 0; i < Features.Count; i++)
  1434. {
  1435. List<Segment> listSeg = Features[i];
  1436. XrayData = new long[2000];
  1437. listElement = new Dictionary<string, double>();
  1438. //if (iExtender.XrayAreaCollectiong(5000, listSeg, out XrayData, out listElement))
  1439. if (iExtender.XrayPointCollecting(300, listSeg[0].X, listSeg[0].Y, out XrayData, out listElement))
  1440. {
  1441. string ele = "";
  1442. foreach (var s in listElement)
  1443. {
  1444. ele += s.ToString();
  1445. }
  1446. log.Info("采集时间=300", true);
  1447. log.Info("(" + listSeg[0].X + "," + listSeg[0].Y + ") height=3" + " 元素:" + ele);
  1448. log.Info("线采集结束,写入数据库开始", true);
  1449. //写入数据库
  1450. m_nXrayId++;
  1451. AreasNo++;
  1452. //m_MeasDB.InsertAPointXray(currHole.HoleNo, m_nXrayId, listSeg[0].X, listSeg[0].Y, XrayData, listElement, a_FieldImagePositionID);
  1453. //m_MeasDB.InsertAAreaXay(currHole.HoleNo, m_nXrayId, AreasNo, listSeg, XrayData, listElement, a_FieldImagePositionID);
  1454. m_MeasDB.SaveToMemory(currHole.HoleNo, m_nXrayId, AreasNo, listSeg, XrayData, listElement, a_FieldImagePositionID);
  1455. }
  1456. else
  1457. {
  1458. log.Error("线扫xray失败");
  1459. }
  1460. }
  1461. m_MeasDB.LineDataSubmitted();
  1462. iExtender.EndMultipleAquisition();
  1463. break;
  1464. case 2: //area mode
  1465. //面数据
  1466. state = 0;
  1467. ImagePro.EDS_Param_Areas(edsfn, a_FieldImagePositionID, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out area_pt, out width, out height, out state);
  1468. log.Info("面返回数据" + area_pt.X.ToString() + "," + area_pt.Y.ToString() + ",height=" + height.ToString() + ",width=" + width.ToString(), true);
  1469. if (state == 1)
  1470. {
  1471. //将面转换为segment数据,每5行形成一个面
  1472. int singleH = 5;
  1473. for (int k = 0; k < height; k += singleH)
  1474. {
  1475. List<Segment> segments = new List<Segment>();
  1476. for (int j = 0; j <= singleH; j++)
  1477. {
  1478. Segment segment = new Segment();
  1479. segment.X = area_pt.X;
  1480. segment.Y = area_pt.Y + j+k;
  1481. segment.Length = width;
  1482. segments.Add(segment);
  1483. }
  1484. Features.Add(segments);
  1485. }
  1486. }
  1487. else
  1488. {
  1489. log.Error("面扫图片处理失败", false);
  1490. return false;
  1491. }
  1492. //面采集
  1493. iExtender.BeginMultipleAquisition();
  1494. Thread.Sleep(100);
  1495. foreach (List<Segment> feature in Features)
  1496. {
  1497. XrayData = new long[2000];
  1498. listElement = new Dictionary<string, double>();
  1499. log.Info("AreaTime=15000", true);
  1500. if (iExtender.XrayAreaCollectiong(15000, feature, out XrayData, out listElement))
  1501. {
  1502. string ele = "";
  1503. foreach (var s in listElement)
  1504. {
  1505. ele += s.ToString();
  1506. }
  1507. log.Info(" 元素:" + ele);
  1508. log.Info("面采集结束,写入数据库开始", true);
  1509. //写入数据库
  1510. m_nXrayId++;
  1511. AreasNo++;
  1512. m_MeasDB.InsertAAreaXay(currHole.HoleNo, m_nXrayId, AreasNo, feature, XrayData, listElement, a_FieldImagePositionID);
  1513. }
  1514. else
  1515. {
  1516. log.Error("面扫xray失败");
  1517. }
  1518. }
  1519. iExtender.EndMultipleAquisition();
  1520. break;
  1521. }
  1522. //存储数据
  1523. //向分析点数据库更新
  1524. }
  1525. catch (Exception e)
  1526. {
  1527. iExtender.EndMultipleAquisition();
  1528. log.Error(e.Message, false);
  1529. return false;
  1530. }
  1531. return true;
  1532. }
  1533. /// <summary>
  1534. /// 初始化数据库
  1535. /// </summary>
  1536. public void Init_MeasDB()
  1537. {
  1538. m_MeasDB = new MeasureDB(m_measureFile);
  1539. }
  1540. /// <summary>
  1541. /// 161.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  1542. /// </summary>
  1543. /// <returns></returns>
  1544. public bool EDS_MoveToCenter(CutHole currHole)
  1545. {
  1546. float x2 = 0, y2 = 0;
  1547. int state = 0;
  1548. float tmag = MParam.MoveToCenterMagnification;
  1549. Focusparam focusPrm = new Focusparam()
  1550. {
  1551. IfAutoBrightnessAndContrast = true,
  1552. mag = tmag,
  1553. reduceWindowPos = new System.Drawing.Point(256, 192),
  1554. reduceWinWidth = 400,
  1555. reduceWinHeight = 400,
  1556. workingDis = 10,//unit:mm
  1557. brightness = 50,
  1558. contrast = 29,
  1559. tiltCorrAngle = MParam.Correction_Angle_OutSide,
  1560. ifStig = false,
  1561. };
  1562. m_focuse.setFocusParam(focusPrm);
  1563. m_focuse.DoFocusBySetMainParameter();
  1564. float mag = tmag;
  1565. String fileName4 = currHole.data_path + "\\EDS\\" + MParam.Firm + "-" + mag.ToString("0") + "-" + currHole.HoleName + "-" + ImageNameEDS4;
  1566. PhotoParam prm = new PhotoParam()
  1567. {
  1568. Mag = mag,
  1569. savePath = fileName4,
  1570. };
  1571. m_photo.SetPhotoParam(prm);
  1572. m_photo.TakePhoto();
  1573. arg.Picture_Information.Picture_FullPath = fileName4;
  1574. mArgSend.SendArgumentToScreen("4-2", "", fileName4);
  1575. if (key_stop)
  1576. {
  1577. return false;
  1578. }
  1579. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  1580. //5.根据坐标控制SEM移动到切孔位置,居中
  1581. log.Info("测量线程:图像处理接口,准备移动样品台", true);
  1582. log.Info("文件名=" + fileName4, true);
  1583. ImagePro.Img_Trapezoid_Top_Center_Position(fileName4, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out x2, out y2, out state);
  1584. log.Info("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
  1585. log.Info("准备移动样品台返回状态=" + state.ToString(), true);
  1586. if (state == 1)
  1587. {
  1588. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1589. if (!m_locate.MoveToPixByMoveStage(x2,y2))
  1590. {
  1591. log.Error("测量线程报错:" + arg.Message, false);
  1592. return false;
  1593. }
  1594. }
  1595. else
  1596. {
  1597. log.Error("测量线程报错:" + arg.Message, false);
  1598. return false;
  1599. }
  1600. //判断是否停止进程
  1601. if (key_stop)
  1602. {
  1603. log.Info("停止键按下", true);
  1604. return false;
  1605. }
  1606. Thread.Sleep(2000);
  1607. return true;
  1608. }
  1609. /// <summary>
  1610. /// 171.能谱第17步找点采集数据
  1611. /// </summary>
  1612. /// <returns></returns>
  1613. public bool EDS_ShotSection(CutHole currHole)
  1614. {
  1615. int state = 0;
  1616. Focusparam fprm = new Focusparam()
  1617. {
  1618. mag = MParam.Photograph_Magnification,
  1619. reduceWindowPos = new System.Drawing.Point(402, 128),
  1620. reduceWinHeight = 600,
  1621. reduceWinWidth = 600,
  1622. IfAutoBrightnessAndContrast = true,
  1623. workingDis = 10,//unit mm
  1624. brightness = 50,
  1625. contrast = 29,
  1626. tiltCorrAngle = MParam.Correction_Angle_Inside,
  1627. ifStig = false,
  1628. };
  1629. log.Info("自动对焦开始!", true);
  1630. m_focuse.setFocusParam(fprm);
  1631. m_focuse.DoFocusBySetMainParameter();
  1632. SendMsg("4-4");
  1633. fprm.ifStig = false;
  1634. //add by zjx 2020-12-21 根据客户的需求修改图片的名称
  1635. String fileName5 = currHole.data_path + "\\EDS\\" + MParam.Firm + "-" + MParam.Photograph_Magnification.ToString("0") + "-" + currHole.HoleName + "-" + ImageName5;
  1636. //add by zjx 2020-12-21 根据客户的需求修改图片的名称 end
  1637. log.Info("fileName5=" + fileName5, true);
  1638. log.Info("开始拍摄截面照!");
  1639. PhotoParam phoPrm = new PhotoParam()
  1640. {
  1641. Mag = MParam.Photograph_Magnification,
  1642. savePath = fileName5,
  1643. };
  1644. //Photo pho = new Photo(phoPrm, iSEM);
  1645. m_photo.SetPhotoParam(phoPrm);
  1646. m_photo.TakePhoto();
  1647. //判断是否停止进程
  1648. if (key_stop)
  1649. {
  1650. log.Info("停止键按下", true);
  1651. return false;
  1652. }
  1653. #endregion
  1654. //if (MParam.IsShotSectionToRun == false)//Is_Photograph 代表 是否是只拍照
  1655. //{
  1656. #region 获取两个位置上及放大倍数
  1657. //计算两个测量区域坐标
  1658. List<System.Drawing.Point> ct = new List<System.Drawing.Point>();
  1659. List<float> mag = new List<float>();
  1660. System.Drawing.Point ct0;
  1661. float magMax;
  1662. log.Info("图像处理接口,计算两个放大区域坐标,输入图像" + fileName5.ToString(), true);
  1663. ImagePro.Img_Measure_Region_Position(fileName5, Convert.ToInt32(MParam.SampleTypeNo()), MParam.Firm, out ct, out mag, out ct0, out state);
  1664. string s = "";
  1665. for (int i = 0; i < ct.Count; i++)
  1666. {
  1667. s += "输出观测点" + i.ToString() + "为(" + ct[i].X.ToString() + "," + ct[i].Y.ToString() + ")"
  1668. + "放大倍数=" + mag[i];
  1669. }
  1670. log.Info("测量线程:图像处理接口返回值为" + state.ToString() +
  1671. ",计算两个放大区域坐标,输入图像" + fileName5.ToString() +
  1672. "输入样品" + Convert.ToInt32(MParam.SampleTypeNo()) +
  1673. "输入厂商" + MParam.Firm.ToString() +
  1674. s +
  1675. "输出对焦点为(" + ct0.X.ToString() + "," + ct0.Y.ToString() + ")", true);
  1676. #endregion
  1677. if (state == 1 && ct.Count != 0 && mag.Count != 0)
  1678. {
  1679. Locate recordPostion = new Locate(iSEM);
  1680. recordPostion.RecordCurrentBeamShiftAndStagePosition();
  1681. //找到第一个观测点放大倍数find the first anylysis point and the mag.
  1682. magMax = mag[0];
  1683. #region 移动到梯形左上角
  1684. //20201127将视野移动到梯形左上角位置
  1685. log.Warn("开始对焦 移动到对焦点( " + ct0.X.ToString()
  1686. + "," + ct0.Y.ToString() + ")", true);
  1687. m_locate.MoveToPix(ct0.X,ct0.Y,MParam.PixelSizeCor);
  1688. Thread.Sleep(200);
  1689. //add by sun 2020-12-15 拍截面图调用蔡司接口时,要保证扫描速度5以上,自动亮度对比度功能关闭
  1690. iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//CmdFocusRate(5);
  1691. //add by sun 2020-12-15 拍截面图调用蔡司接口时,要保证扫描速度5以上,自动亮度对比度功能关闭 end
  1692. cycle_time = iSEM.GetCycleTime();
  1693. Thread.Sleep(100 + Convert.ToInt32(cycle_time));
  1694. Focusparam fprm1 = new Focusparam()
  1695. {
  1696. mag = magMax / 2,
  1697. reduceWindowPos = new System.Drawing.Point(402, 128),
  1698. reduceWinHeight = 600,
  1699. reduceWinWidth = 600,
  1700. IfAutoBrightnessAndContrast = true,
  1701. workingDis = 10,
  1702. brightness = 49.4f,
  1703. contrast = 30.1f,
  1704. tiltCorrAngle = MParam.Correction_Angle_Inside,
  1705. ifStig = false,
  1706. };
  1707. log.Info("自动对焦1开始!", true);
  1708. m_focuse.setFocusParam(fprm1);
  1709. m_focuse.DoFocusByNewMagnification(fprm1.mag);
  1710. log.Info("自动对焦2开始!", true);
  1711. m_focuse.DoFocusByNewMagnification(magMax);
  1712. #endregion
  1713. log.Warn("对焦完成,开始用能谱拍摄观测点照片!并分析图片以获得Xray点位置!");
  1714. recordPostion.RestoreLastBeamShiftAndStagePosition();
  1715. log.Warn("移动到指定观测点!并准备打Xray");
  1716. m_locate.MoveToPix(ct[0].X,ct[0].Y,MParam.PixelSizeCor);
  1717. SendMsg("4-4");//向界面发送指令:放大并对拍摄点对焦
  1718. Thread.Sleep(500);
  1719. #region 拍照
  1720. //log.Info("进入内部观察,不对焦!", true);
  1721. log.Info("开始EDS拍照,设置放大倍数" + mag[0]);
  1722. m_focuse.SetMagnification(mag[0]);
  1723. // m_photo.EnforceContrast();
  1724. log.Warn("EDS获取指定观测点图片,并打Xray");
  1725. DoEDS(currHole, 1);
  1726. log.Info("像素扫描:CmdPixelScan");
  1727. iSEM.CmdPixelScan();
  1728. Thread.Sleep(200);
  1729. log.Info("改变刷新率 " + "CMD_SCANRATE4");
  1730. iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
  1731. cycle_time = iSEM.GetCycleTime();
  1732. Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
  1733. SendMsg("4-6");//向界面发生指令:采集能谱信息
  1734. }
  1735. #endregion
  1736. //}
  1737. iSEM.SetTiltAngleOff();
  1738. Thread.Sleep(200);
  1739. iSEM.SetScanRotationOff();
  1740. Thread.Sleep(200);
  1741. iSEM.SetBeamShiftX(0);
  1742. Thread.Sleep(200);
  1743. iSEM.SetBeamShiftY(0);
  1744. Thread.Sleep(200);
  1745. //判断是否停止进程
  1746. return true;
  1747. }
  1748. /// <summary>
  1749. /// 19.能谱分析
  1750. /// </summary>
  1751. /// <returns></returns>
  1752. public bool EDS_Analysis(CutHole currHole)
  1753. {
  1754. //1.先降Z轴 37.241左右使工作距离从5mm 变为 10mm,这样方便能谱工作,麻烦是需要从新对焦。由于移动样品台会有误差,容易造成图像偏移,最好从新定位
  1755. Locate lo = new Locate(iSEM);
  1756. lo.MoveZAxisByAbs(MParam.EDSZ / 1000);
  1757. //判断是否停止进程
  1758. if (key_stop)
  1759. {
  1760. log.Info("停止键按下", true);
  1761. return false;
  1762. }
  1763. SendMsg("4-0");
  1764. //2.角度补偿关闭
  1765. // iSEM.SetScanRotationOff();
  1766. //在层高分析时,角度补偿已经纠正,能谱分析不必再做
  1767. Thread.Sleep(200);
  1768. iSEM.SetSEMVoltage(MParam.EDSV);
  1769. Thread.Sleep(200);
  1770. iSEM.SetSEMIPROBE(MParam.EDSA / 1000000000);
  1771. Thread.Sleep(200);
  1772. SendMsg("4-1");
  1773. log.Warn("开始梯形移到视野中心!");
  1774. if (!EDS_MoveToCenter(currHole))
  1775. {
  1776. return false;
  1777. }
  1778. SendMsg("4-3");
  1779. //7.调用171步过程
  1780. log.Warn("开始打能谱图和打Xray!");
  1781. if (!EDS_ShotSection(currHole))
  1782. {
  1783. return false;
  1784. }
  1785. return true;
  1786. }
  1787. /// <summary>
  1788. /// 20.光束等复位
  1789. /// </summary>
  1790. public void BeamShiftReset()
  1791. {
  1792. iSEM.SetTiltAngleOff();
  1793. Thread.Sleep(200);
  1794. iSEM.SetScanRotationOff();
  1795. Thread.Sleep(200);
  1796. iSEM.SetBeamShiftX(0);
  1797. Thread.Sleep(200);
  1798. iSEM.SetBeamShiftY(0);
  1799. Thread.Sleep(200);
  1800. }
  1801. //add by sun 2020-12-17 不同样品电压、电流不一致,应设置灵活。123456类电压2000V电流200pA,7类5000V 500pA,能谱 7000V 500pA
  1802. #region 设置电压电流
  1803. public bool SetVoltageAndIPROBE()
  1804. {
  1805. log.Info("测量线程:设置电压电流 123456类电压2000V电流200pA,7类5000V 500pA,能谱 7000V 500pA 目前是第 " + MParam.SampleType + " 类!", true);
  1806. bool mRet_VoltageFlag = false;
  1807. bool mRet_ElecFlag = false;
  1808. float vot, iprobe;
  1809. vot = MParam.Voltage;
  1810. iprobe = MParam.Iprobe;
  1811. mRet_VoltageFlag = iSEM.SetSEMVoltage(vot);
  1812. Thread.Sleep(500);
  1813. mRet_ElecFlag = iSEM.SetSEMIPROBE(iprobe / 1000000000);
  1814. Thread.Sleep(500);
  1815. if (!mRet_VoltageFlag) return false;
  1816. if (!mRet_ElecFlag) return false;
  1817. log.Info("测量线程:设置电压电流完成!", true);
  1818. return true;
  1819. }
  1820. #endregion
  1821. //add by sun 2020-12-17 不同样品电压、电流不一致,应设置灵活。123456类电压2000V电流200pA,7类5000V 500pA,能谱 7000V 500pA end
  1822. //add by sun 2020-12-17 根据客户要求,3大类样品需要在5000倍下在拍摄一张图片,不需要分析
  1823. //add by sun 2020-12-17 根据客户要求,3大类样品需要在5000倍下在拍摄一张图片,不需要分析 end
  1824. //add by zjx 2020-12-21 在测量图上显示放大倍数和像素大小等信息
  1825. public void SaveMeasDataPic(String picFullPath, float Mag, float pixelsize)
  1826. {
  1827. try
  1828. {
  1829. using (System.Drawing.Image img = Image.FromFile(picFullPath))
  1830. {
  1831. Bitmap bmp = new Bitmap(img.Width, img.Height);
  1832. using (Graphics g = Graphics.FromImage(bmp))
  1833. {
  1834. g.DrawImage(img, 0, 0, img.Width, img.Height);
  1835. String str = "Mag:" + Mag.ToString("0") + "X\tPixelSize:" + (pixelsize * 1000000).ToString("0.00") + "um";
  1836. Font font = new Font("宋体", 16, FontStyle.Bold);
  1837. SolidBrush sbrush = new SolidBrush(Color.LimeGreen);
  1838. g.DrawString(str, font, sbrush, new PointF(40, img.Height - 30));
  1839. }
  1840. System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
  1841. Bitmap newBitmap = new Bitmap(img.Width, img.Height, bmpData.Stride, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, bmpData.Scan0);
  1842. String path = Path.GetDirectoryName(picFullPath) +
  1843. Path.GetFileNameWithoutExtension(picFullPath) +
  1844. "_Data" + Path.GetExtension(picFullPath);
  1845. newBitmap.SetResolution(1, 1);
  1846. newBitmap.Save(path);
  1847. }
  1848. }
  1849. catch
  1850. {
  1851. log.Error("在测量图上显示放大倍数和像素大小信息失败", false);
  1852. }
  1853. }
  1854. //add by zjx 2020-12-21 在测量图上显示放大倍数和像素大小等信息 end
  1855. }
  1856. }