Measure.cs 94 KB

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