Measure.cs 84 KB

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