Measure.cs 85 KB

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