Measure.cs 92 KB

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