Measure.cs 84 KB

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