Measure.cs 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710
  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 SmartSEMControl;
  13. using MeasureData;
  14. using FileManager;
  15. using WebManager;
  16. using OpenCvSharp;
  17. using Extender;
  18. namespace MeasureThread
  19. {
  20. //图片模式
  21. public enum ImageMode
  22. {
  23. FIB,
  24. SEM
  25. }
  26. public delegate void ThreadStatusHandler(object sender, ThreadStatusEventArgs e); //声明委托
  27. public delegate void CutHolesStatusHandler(object sender, CutHolesStatusEventArgs e);
  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. public class CutHolesStatusEventArgs
  297. {
  298. public string State
  299. {
  300. get { return m_state; }
  301. set { m_state = value; }
  302. }
  303. private string m_state;
  304. public string HoleName
  305. {
  306. get { return m_holeName; }
  307. set { m_holeName = value; }
  308. }
  309. private string m_holeName;
  310. public CutHolesStatusEventArgs(string a_state, string a_holeName)
  311. {
  312. this.m_state = a_state;
  313. this.m_holeName = a_holeName;
  314. }
  315. }
  316. public class Measure
  317. {
  318. /// 图像拉直算法
  319. /// </summary>
  320. /// <param name="Slope">倾斜角度</param>
  321. /// <param name="x0">圆心坐标x</param>
  322. /// <param name="y0">圆心坐标y</param>
  323. /// <param name="x1">倾斜情况下帧图的坐标x</param>
  324. /// <param name="y1">倾斜情况下帧图的坐标y</param>
  325. /// <param name="Hx">复位到原位置需要移动的x值(返回值)</param>
  326. /// <param name="Hy">复位到原位置需要移动的y值(返回值)</param>
  327. /// <returns></returns>
  328. public bool Straightening(float Slope, float x0, float y0, float x1, float y1, ref float Hx, ref float Hy)
  329. {
  330. try
  331. {
  332. float xr = x1 - x0;//倾斜图到中心的距离差x
  333. float yr = y1 - y0;//倾斜图到中心的距离差y
  334. float R = (float)Math.Sqrt(xr * xr + yr * yr);//圆心到倾斜图的长度
  335. //double D = 2 * R * Math.Sin(ScanRotation / 2);//倾斜图与矫正图底边的长度
  336. float k = (float)(Math.Atan(yr / xr) / Math.PI * 180);//x1,y1的直角三角形圆心角度
  337. float k_S = k - Slope;//通过夹角差求x2,y2
  338. //int y2 = (int)Math.Round(Math.Sin(Math.PI / (180 / k_S)) * R);
  339. //int x2 = (int)Math.Round(Math.Cos(Math.PI / (180 / k_S)) * R);
  340. float y2 = (float)(Math.Sin(Math.PI / (180 / k_S)) * R);
  341. float x2 = (float)(Math.Cos(Math.PI / (180 / k_S)) * R);
  342. if (Slope > 0 || Slope < 0)
  343. {
  344. Hx = x0 + x2;
  345. Hy = y0 + y2;
  346. }
  347. else
  348. {
  349. Hx = 0;
  350. Hy = 0;
  351. }
  352. return true;
  353. }
  354. catch (Exception)
  355. {
  356. return false;
  357. }
  358. }
  359. //Web接口类
  360. public WebResult wr = null;
  361. //扫描周期
  362. private float cycle_time = 0;
  363. //人工干预
  364. public int hand_intervene = 2;
  365. //样品台保护值
  366. public float X_Min = 0;
  367. public float X_Max = 0.13f;
  368. public float Y_Min = 0;
  369. public float Y_Max = 0.13f;
  370. public float Z_Min = 0;
  371. public float Z_Max = 0.05f;
  372. public float T_Min = -4;
  373. public float T_Max = 70;
  374. public float R_Min = -380;
  375. public float R_Max = 380;
  376. public float M_Min = 0;
  377. public float M_Max = 0.012f;
  378. public float x_center_point = 65;
  379. public float y_center_point = 65;
  380. public event ThreadStatusHandler SendThreadStatus; // 声明事件
  381. public event CutHolesStatusHandler SendCutHolesStatus; // 声明事件
  382. //定义一个全局的消息类
  383. ThreadStatusEventArgs arg = new ThreadStatusEventArgs("0-0");
  384. //全局只有一个fatorySEM
  385. static FactoryHardware factorySEM = FactoryHardware.Instance;
  386. ISEMControl iSEM = factorySEM.ISEM;
  387. //全局只有一个Extender
  388. static ExtenderInterface factoryExtender = null;// ExtenderInterface.Instance;
  389. IExtenderControl iExtender = null;// factoryExtender.IExtender;
  390. //@的作用是不用转义字符\\只打一个就行
  391. const String ImageName0 = @"Straighten.tif"; //传给客户,原始图像,为拉直操作
  392. const String ImageName1 = @"FindCutPostion.tif"; //传给客户,作水平校正
  393. const String ImageName2 = @"FIBCutPostion.tif";//传给客户,找到切割点
  394. const String ImageName31 = @"FIBBefore.tif";
  395. const String ImageName32 = @"FIBAfter.tif";
  396. const String ImageName4 = @"SEMTrapCP.tif";//传给客户,找到已经切割点
  397. const String ImageName5 = @"SEMDegreeTrap.tif";//传给客户,水平校正
  398. const String ImageName6 = @"SEMMagEnd.tif";//传给客户,测量层高
  399. const String ImageName7 = @"EDSImage.tif";//计算感兴趣的区域
  400. const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针
  401. const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针
  402. const String MacoScanPic = "Scan picture.MLF";//一般质量抓图的宏
  403. const String MacoGoodPic = "Good picture.MLF";//高质量抓图的宏
  404. const String MacoExportTif = "Export TIFF.MLF";// 导出有标尺的图像,这个图像为使用工具SmartSEM工具的图像
  405. const String ElyDeposition = @"Deposition.ely"; //沉积
  406. const String ElyCrossSection = @"CrossSection.ely"; //切割
  407. const float fMin = (float)0.0000002; //单位是米
  408. public Boolean key_stop = false;
  409. String focus_path = "";
  410. String FIBfocus_path = "";
  411. String StigX_path = "";
  412. String StigY_path = "";
  413. String EDS_path = "";
  414. String data_path = "";
  415. int m_nWorkHoleNo = -1;
  416. //测量文件
  417. private MeasureFile m_measureFile;
  418. public MeasureFile MeasureFile
  419. {
  420. get { return this.m_measureFile; }
  421. set { this.m_measureFile = value; }
  422. }
  423. //测量的切割孔
  424. private List<MeasureData.CutHole> m_cutHoles;
  425. public List<MeasureData.CutHole> cutHoles
  426. {
  427. get { return this.m_cutHoles; }
  428. set { this.m_cutHoles = value; }
  429. }
  430. //工作文件夹
  431. private string m_WorkingFolder;
  432. public string WorkingFolder
  433. {
  434. get { return this.m_WorkingFolder; }
  435. set { this.m_WorkingFolder = value; }
  436. }
  437. //程序当前路径
  438. private string m_ProgramFolder = Directory.GetCurrentDirectory();
  439. //线程状态
  440. private ThreadStatus m_ThreadStatus;
  441. public ThreadStatus TStatus
  442. {
  443. get { return this.m_ThreadStatus; }
  444. set { this.m_ThreadStatus = value; }
  445. }
  446. //测量参数
  447. private MeasureParam m_MsParam;
  448. public MeasureParam MeasParam
  449. {
  450. get { return this.m_MsParam; }
  451. set { this.m_MsParam = value; }
  452. }
  453. //构造函数
  454. public Measure(String webServerIP, String webServerPort, String webServerUrl)
  455. {
  456. MeasParam = new MeasureParam();
  457. TStatus = new ThreadStatus();
  458. cutHoles = new List<MeasureData.CutHole>();
  459. //配置远程连接
  460. wr = new WebResult(webServerIP,webServerPort,webServerUrl);
  461. }
  462. //初始化测量业务, 读测量文件,判断是否有可测试的切孔
  463. public bool InitMeas(MeasureFile a_measureFile)
  464. {
  465. m_measureFile = a_measureFile;
  466. List<CutHole> listHoles = m_measureFile.ListCutHole;
  467. foreach (CutHole h in listHoles)
  468. {
  469. if (h.SWITCH == true)
  470. {
  471. m_cutHoles.Add(h);
  472. }
  473. }
  474. if (m_cutHoles.Count == 0)
  475. return false;
  476. this.m_MsParam = m_measureFile.MParam;
  477. if(m_measureFile.MParam.EDS == true)
  478. {
  479. factoryExtender = ExtenderInterface.Instance;
  480. iExtender = factoryExtender.IExtender;
  481. }
  482. return true;
  483. }
  484. public void SendMsg(string step_code)
  485. {
  486. arg.Step_Code = step_code;
  487. arg.Time = DateTime.Now;
  488. SendThreadStatus(this, arg);
  489. }
  490. public void SendCutHoleMsg(string a_state, string a_holeName)
  491. {
  492. CutHolesStatusEventArgs arg = new CutHolesStatusEventArgs(a_state, a_holeName);
  493. arg.HoleName = a_holeName;
  494. arg.State = a_state;
  495. SendCutHolesStatus(this, arg);
  496. }
  497. public bool DoEDS()
  498. {
  499. EDSParam param = m_measureFile.MParam.EDSP;
  500. double dDwellTime = param.DwellTime;
  501. int nImageType = param.ImageType;
  502. double dScanSizes = param.ScanSize;
  503. iExtender.SetImageAcquistionSetting(dDwellTime, nImageType, dScanSizes);
  504. string path = EDS_path;
  505. iExtender.GrabImage(path + "\\EDSImage.tif", 0, 0, 0, 0, 0);
  506. //送给客户,计算感兴趣的区域
  507. if (param.PointMode == true)
  508. {
  509. //点采集
  510. List<Point> listPoints = new List<Point>();
  511. foreach (Point pt in listPoints)
  512. {
  513. long[] XrayData = new long[2000];
  514. Dictionary<string, double> listElement = new Dictionary<string, double>();
  515. iExtender.XrayPointCollectiong(param.PointTime, pt.X, pt.Y, out XrayData, out listElement);
  516. //写入数据库
  517. }
  518. }
  519. if (param.AreaMode == true)
  520. {
  521. //面采集
  522. long[] XrayData = new long[2000];
  523. Dictionary<string, double> listElement = new Dictionary<string, double>();
  524. List<List<Segment>> listFeature = new List<List<Segment>>();
  525. foreach (List < Segment> listSeg in listFeature)
  526. {
  527. iExtender.XrayAreaCollectiong(param.AreaTime, listSeg, out XrayData, out listElement);
  528. //写入数据库
  529. }
  530. }
  531. return true;
  532. }
  533. //测量流程
  534. public void DoMeasure()
  535. {
  536. //创建线程的测量状态的更新
  537. this.TStatus.ComputeTime(THREAD_TIME_TYPE.START);
  538. if (SendThreadStatus != null)
  539. {
  540. //SendMsg("开始测量。");
  541. }
  542. LogManager.AddHardwareLog("开始测量",true);
  543. //检查硬件连接是否正常
  544. if (!ConnectHardware())
  545. {
  546. //SendMsg("连接硬件失败。");
  547. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  548. return;
  549. }
  550. //设置工作文件夹
  551. if (!SetWorkingFolderStr())
  552. {
  553. //SendMsg("设置工作文件夹失败");
  554. this.TStatus.ComputeTime(THREAD_TIME_TYPE.STOPPED);
  555. return;
  556. }
  557. //增加EDS控制
  558. //将停止键复位
  559. key_stop = false;
  560. //开始测量就将模式设置为SEM
  561. if (!iSEM.CmdFIBModeSEM())
  562. {
  563. LogManager.AddHardwareLog("开始切换到SEM模式失败,程序退出。", true);
  564. return;
  565. }
  566. arg.Picture_Information.Work_Status = "SEM";
  567. //自动亮度对比度
  568. if (!iSEM.SetAutoVideoBrightnessAndContrast())
  569. {
  570. LogManager.AddHardwareLog("开始设置自动亮度、对比度失败,程序退出。", true);
  571. return;
  572. }
  573. Thread.Sleep(5000);
  574. //设置扫描周期
  575. iSEM.CmdFocusRate();
  576. cycle_time = iSEM.GetCycleTime();
  577. if (cycle_time == 0)
  578. {
  579. LogManager.AddHardwareLog("获取扫描周期时间失败", true);
  580. return;
  581. }
  582. for (int i = 0; i < m_cutHoles.Count; i++)
  583. {
  584. //记录测量序号和孔名
  585. m_nWorkHoleNo = i;
  586. arg.HoleName = m_cutHoles[i].HoleName;
  587. //最终数据存放目录
  588. data_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName;
  589. //对焦数据存放目录
  590. focus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\Focus";
  591. m_MsParam.AutoFocus.Path = focus_path;
  592. if (!Directory.Exists(focus_path))
  593. {
  594. Directory.CreateDirectory(focus_path);
  595. }
  596. //FIB对焦数据存放目录
  597. FIBfocus_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\FIBFocus";
  598. m_MsParam.FIBFocus.Path = FIBfocus_path;
  599. if (!Directory.Exists(FIBfocus_path))
  600. {
  601. Directory.CreateDirectory(FIBfocus_path);
  602. }
  603. //StigX数据存放目录
  604. StigX_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigX";
  605. m_MsParam.AutoStigX.Path = StigX_path;
  606. if (!Directory.Exists(StigX_path))
  607. {
  608. Directory.CreateDirectory(StigX_path);
  609. }
  610. //StigY数据存放目录
  611. StigY_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\StigY";
  612. m_MsParam.AutoStigY.Path = StigY_path;
  613. if (!Directory.Exists(StigY_path))
  614. {
  615. Directory.CreateDirectory(StigY_path);
  616. }
  617. //EDS数据存放路径
  618. if (m_measureFile.MParam.EDS == true)
  619. {
  620. EDS_path = WorkingFolder + "\\" + m_cutHoles[i].HoleName + "\\EDS";
  621. m_MsParam.AutoStigY.Path = EDS_path;
  622. if (!Directory.Exists(EDS_path))
  623. {
  624. Directory.CreateDirectory(EDS_path);
  625. }
  626. }
  627. //判断孔状态
  628. if (m_cutHoles[i].STATE != State.Ready)
  629. {
  630. continue;
  631. }
  632. //开始循环工作
  633. if (i == 0)
  634. {
  635. m_cutHoles[i].START = DateTime.Now;
  636. //切孔操作-开始
  637. m_cutHoles[i].STATE = State.InProcess;
  638. //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  639. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  640. //1、移动样品台到第一个观测点,先移动R轴,再移动XY轴
  641. if (!iSEM.SetStageGotoR(m_cutHoles[0].Position.R))
  642. {
  643. LogManager.AddHardwareLog("样品台R轴移动失败。", true);
  644. return;
  645. }
  646. while (true)
  647. {
  648. Thread.Sleep(5000);
  649. if (iSEM.GetStageIs() == 0)
  650. {
  651. break;
  652. }
  653. }
  654. //判断是否停止进程
  655. if (key_stop)
  656. {
  657. return;
  658. }
  659. //移动XY轴
  660. if (!iSEM.MoveStageXY(m_cutHoles[0].Position.X, m_cutHoles[0].Position.Y))
  661. {
  662. LogManager.AddHardwareLog("样品台XY轴移动失败。", true);
  663. return;
  664. }
  665. while (true)
  666. {
  667. Thread.Sleep(5000);
  668. if (iSEM.GetStageIs() == 0)
  669. {
  670. break;
  671. }
  672. }
  673. //判断是否停止进程
  674. if (key_stop)
  675. {
  676. return;
  677. }
  678. //成功
  679. if (FirstHole())
  680. {
  681. //保存文件,将测量状态更改
  682. m_cutHoles[i].STATE = State.Success;
  683. m_cutHoles[i].END = DateTime.Now;
  684. m_measureFile.Save();
  685. }
  686. //失败
  687. else
  688. {
  689. m_cutHoles[i].STATE = State.Failed;
  690. m_cutHoles[i].END = DateTime.Now;
  691. m_measureFile.Save();
  692. }
  693. //切孔操作-完成
  694. //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  695. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  696. }
  697. else
  698. {
  699. //其他孔测量之前的初始化
  700. if (!OtherHole_Init())
  701. {
  702. arg.Message = "当前测量点位置初始失败!";
  703. arg.State = false;
  704. SendMsg("0-1");
  705. Thread.Sleep(5000);
  706. continue;
  707. }
  708. //其他孔的测量
  709. m_cutHoles[i].START = DateTime.Now;
  710. //非第一个孔的测试
  711. //SendMsg("第" + i.ToString() + "个切孔开始测量");
  712. //切孔操作-开始
  713. //SendCutHoleMsg(((int)ThreadState.InProcess).ToString(), m_cutHoles[i].HoleName);
  714. m_cutHoles[i].STATE = State.InProcess;
  715. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  716. //其他孔的测试
  717. //成功
  718. if (OtherHole())
  719. {
  720. //保存文件,将测量状态更改
  721. m_cutHoles[i].STATE = State.Success;
  722. m_cutHoles[i].END = DateTime.Now;
  723. m_measureFile.Save();
  724. }
  725. //失败
  726. else
  727. {
  728. m_cutHoles[i].STATE = State.Failed;
  729. m_cutHoles[i].END = DateTime.Now;
  730. m_measureFile.Save();
  731. }
  732. //切孔操作-完成
  733. //SendCutHoleMsg(((int)ThreadState.Success).ToString(), m_cutHoles[i].HoleName);
  734. SendCutHoleMsg(((int)m_cutHoles[i].STATE).ToString(), m_cutHoles[i].HoleName);
  735. }
  736. if(key_stop)
  737. {
  738. m_cutHoles[i].END = DateTime.Now;
  739. m_cutHoles[i].STATE = State.Ready;
  740. m_measureFile.Save();
  741. arg.Message = "用户停止测量";
  742. SendMsg("0-0");
  743. break;
  744. }
  745. }
  746. }
  747. //检查硬件连接是否正常
  748. public bool ConnectHardware()
  749. {
  750. //返回硬件的连接状态
  751. return iSEM.ConnectStatus();
  752. }
  753. //设置工作文件夹
  754. public bool SetWorkingFolderStr()
  755. {
  756. WorkingFolder = m_measureFile.FilePath;
  757. return true;
  758. }
  759. //插入PT针
  760. public bool InsertPT()
  761. {
  762. string fn = m_ProgramFolder + "\\Macro\\" + MacoInsertPt;
  763. //SendMsg("调用宏插入PT针宏文件" + fn);
  764. iSEM.CMDMCFFilename(fn);
  765. //延时1s??
  766. Thread.Sleep(1000);
  767. return true;
  768. }
  769. //撤出PT针
  770. public bool RetractPT()
  771. {
  772. string fn = m_ProgramFolder + "\\Macro\\" + MacoRetractPt;
  773. //SendMsg("调用宏撤出PT针宏文件" + fn);
  774. iSEM.CMDMCFFilename(fn);
  775. //延时1s??
  776. Thread.Sleep(1000);
  777. return true;
  778. }
  779. //PT沉积
  780. public bool PTWork()
  781. {
  782. //执行PT沉积的ELY文件
  783. //string fn = m_ProgramFolder + "\\Macro\\" + ElyDeposition;
  784. //SendMsg("执行PT沉积Ely文件:" + fn);
  785. if (!ExcuteEly(m_MsParam.PTTemp))
  786. {
  787. return false;
  788. }
  789. //等待沉积完成
  790. while (true)
  791. {
  792. Thread.Sleep(10000);
  793. if (iSEM.GetFIBMode() == 0)
  794. {
  795. break;
  796. }
  797. }
  798. return true;
  799. }
  800. //FIB切割
  801. public bool FIBWork()
  802. {
  803. //执行PT沉积的ELY文件
  804. //string fn = m_ProgramFolder + "\\Macro\\" + ElyCrossSection;
  805. //SendMsg("执行FIB切割Ely文件:" + fn);
  806. if (!ExcuteEly(m_MsParam.FIBTemp))
  807. {
  808. return false;
  809. }
  810. //等待切割完成
  811. while (true)
  812. {
  813. Thread.Sleep(10000);
  814. if (iSEM.GetFIBMode() == 0)
  815. {
  816. break;
  817. }
  818. }
  819. return true;
  820. }
  821. //执行ELY文件的步骤
  822. public bool ExcuteEly(string a_filename)
  823. {
  824. //执行ELy文件有三个动作
  825. //1. 选择ELY文件
  826. //SendMsg("选择ELY文件");
  827. if (!iSEM.CmdFIBLoadELY(a_filename))
  828. {
  829. //SendMsg("选择ELY文件失败");
  830. return false;
  831. }
  832. Thread.Sleep(1000);
  833. //2. 确认ELY文件
  834. //SendMsg("确认ELY文件");
  835. if (!iSEM.CmdFIBEXPOSUREELY())
  836. {
  837. //SendMsg("确认ELY文件失败");
  838. return false;
  839. }
  840. Thread.Sleep(1000);
  841. //3. 执行ELY文件
  842. //SendMsg("执行ELY文件");
  843. if (!iSEM.CmdFIBSTARTELY())
  844. {
  845. //SendMsg("执行ELY文件失败");
  846. return false;
  847. }
  848. Thread.Sleep(1000);
  849. return true;
  850. }
  851. //执行自动对焦
  852. public bool ImageFocus(String step_code)
  853. {
  854. if (m_measureFile.MParam.FocusMode == 1)//手动
  855. {
  856. if (DialogResult.Yes == MessageBox.Show("图像自动对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  857. {
  858. }
  859. else
  860. {
  861. return false;
  862. }
  863. }
  864. else if(m_measureFile.MParam.FocusMode == 2)//自有自动
  865. {
  866. //郝工增加自动对焦算法
  867. //处理文件夹
  868. if (Directory.Exists(focus_path))
  869. {
  870. Directory.Delete(focus_path, true);
  871. }
  872. Thread.Sleep(3000);
  873. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  874. Thread.Sleep(1000);
  875. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  876. Thread.Sleep(1000);
  877. //再创建文件夹
  878. Directory.CreateDirectory(focus_path);
  879. //1、对焦参数类,2、输出工作距离
  880. int wd = 0;
  881. //20201015 根据当前的工作距离重新计算对焦位置
  882. float currentWd = iSEM.GetWorkingDistance();
  883. m_MsParam.AutoFocus.UP = currentWd * 1000000 - m_MsParam.AutoFocus.Step;
  884. m_MsParam.AutoFocus.Down = currentWd * 1000000 + m_MsParam.AutoFocus.Step;
  885. LogManager.AddHardwareLog("修改对焦参数", true);
  886. AutoFocus(m_MsParam.AutoFocus, out wd, step_code);
  887. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  888. //设置工作距离
  889. iSEM.SetWorkingDistance((float)(wd * 0.00000001));
  890. //设置完工作距离后必须延迟5秒
  891. Thread.Sleep(5000);
  892. //处理图片位置
  893. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  894. }
  895. else if(m_MsParam.FocusMode == 3) //客户自动
  896. {
  897. //后期和客户对接接口
  898. List<string> filenames = new List<string>();
  899. String retfilename = wr.Img_Auto_Focus(filenames);
  900. }
  901. else //蔡司自动对焦
  902. {
  903. iSEM.CmdAutoFocusCoarse();
  904. while(true)
  905. {
  906. Thread.Sleep(10000);
  907. if(0 == iSEM.GetAutoFunction())
  908. {
  909. break;
  910. }
  911. }
  912. iSEM.CmdAutoFocusFine();
  913. while (true)
  914. {
  915. Thread.Sleep(10000);
  916. if (0 == iSEM.GetAutoFunction())
  917. {
  918. break;
  919. }
  920. }
  921. }
  922. return true;
  923. }
  924. //执行自动消像散
  925. public bool ImageStig(String step_code)
  926. {
  927. if (m_measureFile.MParam.FocusMode == 1)//手动
  928. {
  929. if (DialogResult.Yes == MessageBox.Show("图像自动消像散已完成?", "确认消息", MessageBoxButtons.YesNo))
  930. {
  931. }
  932. else
  933. {
  934. return false;
  935. }
  936. }
  937. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  938. {
  939. //郝工增加自动对焦算法
  940. //处理文件夹
  941. if (Directory.Exists(StigX_path))
  942. {
  943. Directory.Delete(StigX_path, true);
  944. }
  945. Thread.Sleep(3000);
  946. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  947. Thread.Sleep(1000);
  948. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  949. Thread.Sleep(1000);
  950. //再创建文件夹
  951. Directory.CreateDirectory(StigX_path);
  952. //1、对焦参数类,2、输出像散值
  953. int stigX = 0;
  954. //根据当前的stigX重新计算像散值
  955. float currentStigX = iSEM.GetAstigmatismX();
  956. //m_MsParam.AutoStigX.Step = 10; //像散的步长为10
  957. m_MsParam.AutoStigX.UP = currentStigX - m_MsParam.AutoStigX.Step;
  958. m_MsParam.AutoStigX.Down = currentStigX + m_MsParam.AutoStigX.Step;
  959. LogManager.AddHardwareLog("修改消像散参数", true);
  960. AutoStig(m_MsParam.AutoStigX, out stigX, step_code);
  961. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  962. //设置工作距离
  963. iSEM.SetAstigmatismX((float)(stigX * 0.01));
  964. //设置完工作距离后必须延迟5秒
  965. Thread.Sleep(5000);
  966. //处理图片位置
  967. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  968. //处理文件夹
  969. if (Directory.Exists(StigY_path))
  970. {
  971. Directory.Delete(StigY_path, true);
  972. }
  973. Thread.Sleep(3000);
  974. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  975. Thread.Sleep(1000);
  976. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  977. Thread.Sleep(1000);
  978. //再创建文件夹
  979. Directory.CreateDirectory(StigY_path);
  980. //1、对焦参数类,2、输出像散值
  981. int stigY = 0;
  982. //根据当前的stigX重新计算像散值
  983. float currentStigY = iSEM.GetAstigmatismY();
  984. //m_MsParam.AutoStigY.Step = 10; //像散的步长为10
  985. m_MsParam.AutoStigY.UP = currentStigY - m_MsParam.AutoStigY.Step;
  986. m_MsParam.AutoStigY.Down = currentStigY + m_MsParam.AutoStigY.Step;
  987. LogManager.AddHardwareLog("修改消像散参数", true);
  988. AutoStig(m_MsParam.AutoStigY, out stigY, step_code);
  989. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  990. //设置工作距离
  991. iSEM.SetAstigmatismY((float)(stigY * 0.01));
  992. //设置完工作距离后必须延迟5秒
  993. Thread.Sleep(5000);
  994. }
  995. else if (m_MsParam.FocusMode == 3) //客户自动
  996. {
  997. //后期和客户对接接口
  998. List<string> filenames = new List<string>();
  999. String retfilename = wr.Img_Auto_Focus(filenames);
  1000. }
  1001. else //蔡司自动对焦
  1002. {
  1003. iSEM.CmdAutoFocusCoarse();
  1004. while (true)
  1005. {
  1006. Thread.Sleep(10000);
  1007. if (0 == iSEM.GetAutoFunction())
  1008. {
  1009. break;
  1010. }
  1011. }
  1012. iSEM.CmdAutoFocusFine();
  1013. while (true)
  1014. {
  1015. Thread.Sleep(10000);
  1016. if (0 == iSEM.GetAutoFunction())
  1017. {
  1018. break;
  1019. }
  1020. }
  1021. }
  1022. return true;
  1023. }
  1024. //执行FIB自动对焦,FIBFocus
  1025. //执行自动消像散
  1026. public bool FIBFocus(String step_code)
  1027. {
  1028. if (m_measureFile.MParam.FocusMode == 1)//手动
  1029. {
  1030. if (DialogResult.Yes == MessageBox.Show("FIB图像对焦已完成?", "确认消息", MessageBoxButtons.YesNo))
  1031. {
  1032. }
  1033. else
  1034. {
  1035. return false;
  1036. }
  1037. }
  1038. else if (m_measureFile.MParam.FocusMode == 2)//自有自动
  1039. {
  1040. //郝工增加自动对焦算法
  1041. //处理文件夹
  1042. if (Directory.Exists(FIBfocus_path))
  1043. {
  1044. Directory.Delete(FIBfocus_path, true);
  1045. }
  1046. Thread.Sleep(3000);
  1047. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1048. Thread.Sleep(1000);
  1049. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1050. Thread.Sleep(1000);
  1051. //再创建文件夹
  1052. Directory.CreateDirectory(FIBfocus_path);
  1053. //1、对焦参数类,2、输出对焦值
  1054. int FIBFocus = 0;
  1055. //根据当前的stigX重新计算像散值
  1056. float currentFIBFocus = iSEM.GetFIBObjectivePotential();
  1057. //m_MsParam.FIBFocus.Step = 10; //像散的步长为10
  1058. m_MsParam.FIBFocus.UP = currentFIBFocus - m_MsParam.FIBFocus.Step;
  1059. m_MsParam.FIBFocus.Down = currentFIBFocus + m_MsParam.FIBFocus.Step;
  1060. LogManager.AddHardwareLog("修改FIB自动对焦参数", true);
  1061. AutoFIBFocus(m_MsParam.FIBFocus, out FIBFocus, step_code);
  1062. //LogManager.AddHardwareLog("算法输出"+ wd.ToString(), true);
  1063. //设置工作距离
  1064. iSEM.SetFIBObjectivePotential((float)(FIBFocus * 0.01));
  1065. //设置完工作距离后必须延迟5秒
  1066. Thread.Sleep(5000);
  1067. //处理图片位置
  1068. //File.Copy(focus_path + "\\fine\\" + wd.ToString() + ".tif", data_path + "\\" + ImageName);
  1069. }
  1070. else if (m_MsParam.FocusMode == 3) //客户自动
  1071. {
  1072. //后期和客户对接接口
  1073. List<string> filenames = new List<string>();
  1074. String retfilename = wr.Img_Auto_Focus(filenames);
  1075. }
  1076. else //蔡司自动对焦
  1077. {
  1078. iSEM.CmdAutoFocusCoarse();
  1079. while (true)
  1080. {
  1081. Thread.Sleep(10000);
  1082. if (0 == iSEM.GetAutoFunction())
  1083. {
  1084. break;
  1085. }
  1086. }
  1087. iSEM.CmdAutoFocusFine();
  1088. while (true)
  1089. {
  1090. Thread.Sleep(10000);
  1091. if (0 == iSEM.GetAutoFunction())
  1092. {
  1093. break;
  1094. }
  1095. }
  1096. }
  1097. return true;
  1098. }
  1099. /// <summary>
  1100. ///13. 自动 定位功能,沉积
  1101. /// </summary>
  1102. /// <returns></returns>
  1103. public bool GetPoistion()
  1104. {
  1105. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1106. int state = 1;
  1107. //1.控制SEM放大600X
  1108. if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
  1109. {
  1110. arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
  1111. arg.State = false;
  1112. SendMsg("1-5");
  1113. return false;
  1114. }
  1115. if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification))
  1116. {
  1117. arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍失败";
  1118. arg.State = false;
  1119. SendMsg("1-5");
  1120. return false;
  1121. }
  1122. arg.State = true;
  1123. arg.Message = "放大" + m_measureFile.MParam.Location_Magnification.ToString("0.0") + "倍成功";
  1124. SendMsg("1-5");
  1125. //判断是否停止进程
  1126. if (key_stop)
  1127. {
  1128. return false;
  1129. }
  1130. //2.控制SEM自动对焦、亮度、对比度
  1131. if(ImageFocus("1-6"))
  1132. {
  1133. arg.Message = "自动对焦完成";
  1134. arg.State = true;
  1135. SendMsg("1-6");
  1136. }
  1137. else
  1138. {
  1139. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1140. arg.Message = "自动对焦失败";
  1141. arg.State = false;
  1142. SendMsg("1-6");
  1143. }
  1144. //判断是否停止进程
  1145. if (key_stop)
  1146. {
  1147. return false;
  1148. }
  1149. //1.1大于10000倍进行消像散处理
  1150. float dMag = iSEM.GetMagnification();
  1151. if (dMag > 10000)//需要消像散
  1152. {
  1153. if (!ImageStig("1-6"))
  1154. {
  1155. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1156. arg.Message = "拉直操作自动消像散失败!";
  1157. arg.State = false;
  1158. SendMsg("1-6");
  1159. return false;
  1160. }
  1161. arg.Message = "拉直操作自动消像散成功!";
  1162. arg.State = true;
  1163. SendMsg("1-6");
  1164. }
  1165. //3.控制SEM拍照,找到切割位置
  1166. String fileName1 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Location_Magnification.ToString("0") + "_" + ImageName1;
  1167. arg.Picture_Information.Picture_FullPath = fileName1;
  1168. arg.Picture_Information.Work_Voltage = m_MsParam.Location_Voltage;
  1169. arg.Picture_Information.Magnification = m_MsParam.Location_Magnification;
  1170. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1171. Thread.Sleep(1000);
  1172. //拍照前改变速度,延时
  1173. iSEM.CmdSaveRate();
  1174. cycle_time = iSEM.GetCycleTime();
  1175. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1176. if (!GetImage(ImageMode.SEM, fileName1))
  1177. {
  1178. arg.Message = "SEM拍照失败";
  1179. arg.State = false;
  1180. SendMsg("1-7");
  1181. return false;
  1182. }
  1183. arg.State = true;
  1184. arg.Message = "SEM拍照成功";
  1185. SendMsg("1-7");
  1186. iSEM.CmdFocusRate();
  1187. cycle_time = iSEM.GetCycleTime();
  1188. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1189. //判断是否停止进程
  1190. if (key_stop)
  1191. {
  1192. return false;
  1193. }
  1194. //判断是否为仅拍照,不是则执行FIB操作
  1195. if (!m_MsParam.Is_Photograph)
  1196. {
  1197. //6.设置FIB拍照参数——扫描时间、束流等
  1198. //7.控制FIB自动亮度、对比度
  1199. if (!iSEM.CmdFIBModeFIB())
  1200. {
  1201. arg.Message = "FIB模式切换失败";
  1202. arg.State = false;
  1203. SendMsg("1-8");
  1204. return false;
  1205. }
  1206. arg.State = true;
  1207. arg.Picture_Information.Work_Status = "FIB";
  1208. arg.Message = "FIB模式切换成功";
  1209. SendMsg("1-8");
  1210. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1211. //判断是否停止进程
  1212. if (key_stop)
  1213. {
  1214. return false;
  1215. }
  1216. //8.控制FIB拍照
  1217. //9.保存照片======更改路径
  1218. String fileName2 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString("0") + "_" + ImageName2;
  1219. arg.Picture_Information.Picture_FullPath = fileName2;
  1220. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1221. Thread.Sleep(1000);
  1222. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1223. Thread.Sleep(1000);
  1224. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1225. Thread.Sleep(1000);
  1226. //FIB的放大位数,将来会改
  1227. if(!iSEM.SetFIBMagnification(m_MsParam.FIB_Magnification))
  1228. {
  1229. arg.Message = "FIB放大倍数设置失败";
  1230. arg.State = false;
  1231. SendMsg("1-9");
  1232. return false;
  1233. }
  1234. arg.Message = "FIB放大倍数设置成功";
  1235. arg.State = true;
  1236. SendMsg("1-9");
  1237. Thread.Sleep(1000);
  1238. //增加FIB对焦
  1239. //2.控制SEM自动对焦、亮度、对比度
  1240. if (FIBFocus("1-10"))
  1241. {
  1242. arg.Message = "自动FIB对焦完成";
  1243. arg.State = true;
  1244. SendMsg("1-10");
  1245. }
  1246. else
  1247. {
  1248. LogManager.AddHardwareLog("设置观测点后,自动FIB对焦失败。", true);
  1249. arg.Message = "自动FIB对焦失败";
  1250. arg.State = false;
  1251. SendMsg("1-10");
  1252. }
  1253. //判断是否停止进程
  1254. if (key_stop)
  1255. {
  1256. return false;
  1257. }
  1258. //拍照前改变速度,延时
  1259. iSEM.CmdSaveRate();
  1260. cycle_time = iSEM.GetCycleTime();
  1261. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1262. if (!GetImage(ImageMode.FIB, fileName2))
  1263. {
  1264. arg.Message = "FIB拍照失败";
  1265. arg.State = false;
  1266. SendMsg("1-11");
  1267. return false;
  1268. }
  1269. arg.State = true;
  1270. arg.Message = "FIB拍照成功";
  1271. SendMsg("1-11");
  1272. iSEM.CmdFocusRate();
  1273. cycle_time = iSEM.GetCycleTime();
  1274. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1275. //判断是否停止进程
  1276. if (key_stop)
  1277. {
  1278. return false;
  1279. }
  1280. //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
  1281. LogManager.AddHardwareLog("准备移动样品台", true);
  1282. LogManager.AddHardwareLog("文件名="+fileName2, true);
  1283. LogManager.AddHardwareLog("样品类型="+m_MsParam.SampleName, true);
  1284. LogManager.AddHardwareLog("供应商名称="+m_MsParam.Firm, true);
  1285. wr.Img_Cut_Position(fileName2, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
  1286. LogManager.AddHardwareLog("FIB梯形左上角和右上角位置信息= " + x1.ToString() + ", " + y1.ToString() + ", " + x2.ToString() + ", " + y2.ToString(), true);
  1287. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1288. if (state == 1)
  1289. {
  1290. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1291. float xc = (x1 + x2) / 2;
  1292. float yc = (y1 + y2) / 2;
  1293. if (!MoveToPix(xc,yc))
  1294. {
  1295. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  1296. arg.State = false;
  1297. SendMsg("1-12");
  1298. return false;
  1299. }
  1300. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置成功";
  1301. arg.State = true;
  1302. SendMsg("1-12");
  1303. if (hand_intervene == 1)
  1304. {
  1305. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1306. }
  1307. }
  1308. else
  1309. {
  1310. arg.Message = "图像接口参数state返回值为零";
  1311. arg.State = false;
  1312. SendMsg("1-12");
  1313. if(hand_intervene==1)
  1314. {
  1315. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1316. {
  1317. return false;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. return false;
  1323. }
  1324. }
  1325. //判断是否停止进程
  1326. if (key_stop)
  1327. {
  1328. return false;
  1329. }
  1330. //11.自动工具样品类型参数确定是否需要PT沉积
  1331. if (m_MsParam.PT)
  1332. {
  1333. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1334. //第10步已经移动好位置
  1335. //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确
  1336. //x0 = iSEM.GetStageAtX();
  1337. //y0 = iSEM.GetStageAtY();
  1338. //if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
  1339. //{
  1340. // arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败";
  1341. // arg.State = false;
  1342. // SendMsg("1-1");
  1343. // return false;
  1344. //}
  1345. //arg.State = true;
  1346. //arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动成功";
  1347. //SendMsg("1-8");
  1348. //判断是否停止进程
  1349. //if (key_stop)
  1350. //{
  1351. // return false;
  1352. //}
  1353. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  1354. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1355. {
  1356. if (!InsertPT())
  1357. {
  1358. arg.Message = "插入PT针失败";
  1359. arg.State = false;
  1360. SendMsg("1-13");
  1361. return false;
  1362. }
  1363. arg.State = true;
  1364. arg.Message = "插入PT针成功";
  1365. SendMsg("1-13");
  1366. }
  1367. //判断是否停止进程
  1368. if (key_stop)
  1369. {
  1370. return false;
  1371. }
  1372. //3. 根据坐标进行PT沉积
  1373. if (!PTWork())
  1374. {
  1375. arg.Message = "PT沉积失败";
  1376. arg.State = false;
  1377. SendMsg("1-14");
  1378. return false;
  1379. }
  1380. arg.State = true;
  1381. arg.Message = "PT沉积成功";
  1382. SendMsg("1-14");
  1383. //判断是否停止进程
  1384. if (key_stop)
  1385. {
  1386. return false;
  1387. }
  1388. //15.根据样品类型决定是否撤出PT针
  1389. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1390. {
  1391. if (!RetractPT())
  1392. {
  1393. arg.Message = "撤出PT针失败";
  1394. arg.State = false;
  1395. SendMsg("1-15");
  1396. return false;
  1397. }
  1398. arg.State = true;
  1399. arg.Message = "撤出PT针成功";
  1400. SendMsg("1-15");
  1401. }
  1402. //判断是否停止进程
  1403. if (key_stop)
  1404. {
  1405. return false;
  1406. }
  1407. }
  1408. }
  1409. //12.根据梯形坐标控制FIB调整到中心位置
  1410. //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确
  1411. //以上两步已经将程序移动到11内部去做
  1412. //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库
  1413. float[] firstPosition = iSEM.GetStagePosition();
  1414. m_cutHoles[0].Position.X = firstPosition[0];
  1415. m_cutHoles[0].Position.Y = firstPosition[1];
  1416. m_cutHoles[0].Position.Z = firstPosition[2];
  1417. m_cutHoles[0].Position.T = firstPosition[3];
  1418. m_cutHoles[0].Position.R = firstPosition[4];
  1419. m_cutHoles[0].Position.M = firstPosition[5];
  1420. //这里要调用文件保存功能
  1421. arg.Message = "坐标1(" + firstPosition[0].ToString() + ","
  1422. + firstPosition[1].ToString() + ","
  1423. + firstPosition[2].ToString() + ","
  1424. + firstPosition[3].ToString() + ","
  1425. + firstPosition[4].ToString() + ","
  1426. + firstPosition[5].ToString() + ")";
  1427. arg.State = true;
  1428. SendMsg("1-16");
  1429. //判断是否停止进程
  1430. if (key_stop)
  1431. {
  1432. return false;
  1433. }
  1434. return true;
  1435. }
  1436. /// <summary>
  1437. /// 14. FIB切割
  1438. /// </summary>
  1439. /// <returns></returns>
  1440. public bool FIBCross()
  1441. {
  1442. int state = 0;
  1443. //这里不知道PT沉积之后是否变回SEM,所以这里加一句切换到FIB命令
  1444. if (!iSEM.CmdFIBModeFIB())
  1445. {
  1446. return false;
  1447. }
  1448. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  1449. //增加FIB对焦
  1450. if (FIBFocus("1-17"))
  1451. {
  1452. arg.Message = "FIB自动对焦完成";
  1453. arg.State = true;
  1454. SendMsg("1-17");
  1455. }
  1456. else
  1457. {
  1458. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1459. arg.Message = "自动对焦失败";
  1460. arg.State = false;
  1461. SendMsg("1-17");
  1462. return false;
  1463. }
  1464. //判断是否停止进程
  1465. if (key_stop)
  1466. {
  1467. return false;
  1468. }
  1469. String fileName31 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName31;
  1470. arg.Picture_Information.Picture_FullPath = fileName31;
  1471. arg.Picture_Information.Work_Status = "FIB";
  1472. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1473. Thread.Sleep(1000);
  1474. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1475. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1476. Thread.Sleep(1000);
  1477. //拍照前改变速度,延时
  1478. iSEM.CmdSaveRate();
  1479. cycle_time = iSEM.GetCycleTime();
  1480. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1481. if (!GetImage(ImageMode.SEM, fileName31))
  1482. {
  1483. arg.Message = "FIB切割前拍照SEM模式照失败";
  1484. arg.State = false;
  1485. SendMsg("1-18");
  1486. return false;
  1487. }
  1488. arg.State = true;
  1489. arg.Message = "FIB切割前拍照SEM模式照成功";
  1490. SendMsg("1-18");
  1491. iSEM.CmdFocusRate();
  1492. cycle_time = iSEM.GetCycleTime();
  1493. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1494. //判断是否停止进程
  1495. if (key_stop)
  1496. {
  1497. return false;
  1498. }
  1499. //14.自动控制FIB切割
  1500. //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  1501. //2.控制FIB进行切割
  1502. //以上1、2步全部用ELY文件代替
  1503. if (!FIBWork())
  1504. {
  1505. arg.Message = "FIB切割失败";
  1506. arg.State = false;
  1507. SendMsg("1-19");
  1508. return false;
  1509. }
  1510. arg.State = true;
  1511. arg.Message = "FIB切割成功";
  1512. SendMsg("1-19");
  1513. Thread.Sleep(1000);
  1514. //判断是否停止进程
  1515. if (key_stop)
  1516. {
  1517. return false;
  1518. }
  1519. //切割后会切换到SEM,所以需要再切换回FIB模式
  1520. if (!iSEM.CmdFIBModeFIB())
  1521. {
  1522. return false;
  1523. }
  1524. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1525. //3.控制FIB拍照600X
  1526. //底层没有控制方法。
  1527. //4.保存图片
  1528. String fileName32 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName32;
  1529. arg.Picture_Information.Picture_FullPath = fileName32;
  1530. arg.Picture_Information.Work_Status = "FIB";
  1531. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1532. Thread.Sleep(1000);
  1533. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1534. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1535. Thread.Sleep(1000);
  1536. //增加FIB对焦
  1537. if (FIBFocus("1-17"))
  1538. {
  1539. arg.Message = "FIB自动对焦完成";
  1540. arg.State = true;
  1541. SendMsg("1-17");
  1542. }
  1543. else
  1544. {
  1545. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1546. arg.Message = "自动对焦失败";
  1547. arg.State = false;
  1548. SendMsg("1-17");
  1549. return false;
  1550. }
  1551. //拍照前改变速度,延时
  1552. iSEM.CmdSaveRate();
  1553. cycle_time = iSEM.GetCycleTime();
  1554. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1555. if (!GetImage(ImageMode.FIB, fileName32))
  1556. {
  1557. arg.Message = "FIB切割后拍照失败";
  1558. arg.State = false;
  1559. SendMsg("1-20");
  1560. return false;
  1561. }
  1562. arg.State = true;
  1563. arg.Message = "FIB切割后拍照成功";
  1564. SendMsg("1-20");
  1565. iSEM.CmdFocusRate();
  1566. cycle_time = iSEM.GetCycleTime();
  1567. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1568. //判断是否停止进程
  1569. if (key_stop)
  1570. {
  1571. return false;
  1572. }
  1573. //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
  1574. wr.Img_Cut_Success(fileName31, fileName32, out state);
  1575. if(state == 0)
  1576. {
  1577. arg.Message = "图像接口参数state返回值为零";
  1578. arg.State = false;
  1579. SendMsg("1-21");
  1580. if (hand_intervene == 1)
  1581. {
  1582. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1583. {
  1584. return false;
  1585. }
  1586. }
  1587. else
  1588. {
  1589. return false;
  1590. }
  1591. }
  1592. arg.State = true;
  1593. arg.Message = "FIB切割校验成功";
  1594. SendMsg("1-21");
  1595. //判断是否停止进程
  1596. if (key_stop)
  1597. {
  1598. return false;
  1599. }
  1600. return true;
  1601. }
  1602. /// <summary>
  1603. /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  1604. /// </summary>
  1605. /// <returns></returns>
  1606. public bool FindCross()
  1607. {
  1608. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1609. int state = 0;
  1610. //切换到SEM模式
  1611. if (!iSEM.CmdFIBModeSEM())
  1612. {
  1613. arg.Message = "SEM模式切换失败";
  1614. arg.State = false;
  1615. SendMsg("1-22");
  1616. return false;
  1617. }
  1618. arg.State = true;
  1619. arg.Message = "SEM模式切换成功";
  1620. SendMsg("1-22");
  1621. arg.Picture_Information.Work_Status = "SEM";
  1622. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1623. //判断是否停止进程
  1624. if (key_stop)
  1625. {
  1626. return false;
  1627. }
  1628. //1.控制SEM放大到300倍
  1629. if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
  1630. {
  1631. arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
  1632. arg.State = false;
  1633. SendMsg("1-23");
  1634. return false;
  1635. }
  1636. if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification/3))
  1637. {
  1638. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification / 3).ToString("0.0") + "倍失败";
  1639. arg.State = false;
  1640. SendMsg("1-23");
  1641. return false;
  1642. }
  1643. arg.State = true;
  1644. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification/3).ToString("0.0") + "倍成功";
  1645. SendMsg("1-23");
  1646. //判断是否停止进程
  1647. if (key_stop)
  1648. {
  1649. return false;
  1650. }
  1651. //从高倍到低倍不用对焦,这里应该使用程序去判断要不要对焦
  1652. ////2.控制SEM自动对焦、亮度、对比度-接口,,将自动对焦提出单独函数调用
  1653. //if (ImageFocus("1-18"))
  1654. //{
  1655. // arg.Message = "自动对焦完成";
  1656. // arg.State = true;
  1657. // SendMsg("1-18");
  1658. //}
  1659. //else
  1660. //{
  1661. // arg.Message = "自动对焦失败";
  1662. // arg.State = false;
  1663. // SendMsg("1-18");
  1664. //}
  1665. //Thread.Sleep(5000);
  1666. ////判断是否停止进程
  1667. //if (key_stop)
  1668. //{
  1669. // return false;
  1670. //}
  1671. //3.控制SEM拍照
  1672. String fileName4 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + (m_MsParam.Location_Magnification/3).ToString("0") + "_" + ImageName4;
  1673. arg.Picture_Information.Picture_FullPath = fileName4;
  1674. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1675. Thread.Sleep(1000);
  1676. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1677. Thread.Sleep(1000);
  1678. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1679. Thread.Sleep(1000);
  1680. //拍照前改变速度,延时
  1681. iSEM.CmdSaveRate();
  1682. cycle_time = iSEM.GetCycleTime();
  1683. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1684. if (!GetImage(ImageMode.SEM, fileName4))
  1685. {
  1686. arg.State = false;
  1687. arg.Message = "SEM拍照失败";
  1688. SendMsg("1-24");
  1689. return false;
  1690. }
  1691. arg.State = true;
  1692. arg.Message = "SEM拍照成功";
  1693. SendMsg("1-24");
  1694. iSEM.CmdFocusRate();
  1695. cycle_time = iSEM.GetCycleTime();
  1696. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1697. //判断是否停止进程
  1698. if (key_stop)
  1699. {
  1700. return false;
  1701. }
  1702. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  1703. //5.根据坐标控制SEM移动到切孔位置,居中
  1704. LogManager.AddHardwareLog("准备移动样品台", true);
  1705. LogManager.AddHardwareLog("文件名=" + fileName4, true);
  1706. wr.Img_Trapezoid_Top_Center_Position(fileName4,out x2, out y2, out state);
  1707. LogManager.AddHardwareLog("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
  1708. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1709. if (state == 1)
  1710. {
  1711. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1712. if (!MoveToPix(x2, y2))
  1713. {
  1714. arg.State = false;
  1715. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1716. SendMsg("1-25");
  1717. return false;
  1718. }
  1719. //判断是否移动完成
  1720. while (true)
  1721. {
  1722. Thread.Sleep(5000);
  1723. if (iSEM.GetStageIs() == 0)
  1724. {
  1725. break;
  1726. }
  1727. }
  1728. arg.State = true;
  1729. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1730. SendMsg("1-25");
  1731. if (hand_intervene == 1)
  1732. {
  1733. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1734. }
  1735. }
  1736. else
  1737. {
  1738. arg.Message = "图像接口参数state返回值为零";
  1739. arg.State = false;
  1740. SendMsg("1-25");
  1741. if (hand_intervene == 1)
  1742. {
  1743. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1744. {
  1745. return false;
  1746. }
  1747. }
  1748. else
  1749. {
  1750. return false;
  1751. }
  1752. }
  1753. //判断是否停止进程
  1754. if (key_stop)
  1755. {
  1756. return false;
  1757. }
  1758. //6.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  1759. //x0 = iSEM.GetStageAtX();
  1760. //y0 = iSEM.GetStageAtY();
  1761. //if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
  1762. //{
  1763. // arg.Message = "位置校验失败";
  1764. // arg.State = false;
  1765. // SendMsg("1-21");
  1766. // return false;
  1767. //}
  1768. //arg.State = true;
  1769. //arg.Message = "位置校验成功";
  1770. //SendMsg("1-21");
  1771. ////判断是否停止进程
  1772. //if (key_stop)
  1773. //{
  1774. // return false;
  1775. //}
  1776. return true;
  1777. }
  1778. /// <summary>
  1779. /// 17.自动控制SEM拍截面照
  1780. /// </summary>
  1781. /// <returns></returns>
  1782. public bool ShotSection(ref String image18)
  1783. {
  1784. float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
  1785. int state = 0;
  1786. //1、放大6000倍,放大倍数参数photograph_
  1787. if (!iSEM.SetSEMVoltage(m_MsParam.Photograph_Voltage))
  1788. {
  1789. arg.Message = "电压设置" + m_MsParam.Photograph_Voltage.ToString("0.0") + "失败";
  1790. arg.State = false;
  1791. SendMsg("1-26");
  1792. return false;
  1793. }
  1794. if (!iSEM.SetMagnification(m_MsParam.Photograph_Magnification))
  1795. {
  1796. arg.Message = "放大倍数调整失败";
  1797. arg.State = false;
  1798. SendMsg("1-26");
  1799. return false;
  1800. }
  1801. arg.Message = "放大倍数调整成功";
  1802. arg.State = true;
  1803. SendMsg("1-26");
  1804. //判断是否停止进程
  1805. if (key_stop)
  1806. {
  1807. return false;
  1808. }
  1809. //2.控制SEM自动对焦、亮度、对比度-接口
  1810. if (ImageFocus("1-27"))
  1811. {
  1812. arg.Message = "自动对焦完成";
  1813. arg.State = true;
  1814. SendMsg("1-27");
  1815. }
  1816. else
  1817. {
  1818. arg.Message = "自动对焦失败";
  1819. arg.State = false;
  1820. SendMsg("1-27");
  1821. }
  1822. //判断是否停止进程
  1823. if (key_stop)
  1824. {
  1825. return false;
  1826. }
  1827. //1.1大于10000倍进行消像散处理
  1828. float dMag = iSEM.GetMagnification();
  1829. if (dMag > 10000)//需要消像散
  1830. {
  1831. if (!ImageStig("1-27"))
  1832. {
  1833. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1834. arg.Message = "拉直操作自动消像散失败!";
  1835. arg.State = false;
  1836. SendMsg("1-27");
  1837. return false;
  1838. }
  1839. arg.Message = "拉直操作自动消像散成功!";
  1840. arg.State = true;
  1841. SendMsg("1-27");
  1842. }
  1843. //3、设置SEM补偿角度
  1844. if (m_MsParam.Is_Photograph == false)
  1845. {
  1846. if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
  1847. {
  1848. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
  1849. arg.State = false;
  1850. SendMsg("1-28");
  1851. return false;
  1852. }
  1853. arg.State = true;
  1854. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
  1855. SendMsg("1-28");
  1856. Thread.Sleep(2000);
  1857. //判断是否停止进程
  1858. if (key_stop)
  1859. {
  1860. return false;
  1861. }
  1862. }
  1863. //4、拍照,5、保存照片
  1864. String fileName5 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName5;
  1865. arg.Picture_Information.Picture_FullPath = fileName5;
  1866. arg.Picture_Information.Work_Status = "SEM";
  1867. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1868. Thread.Sleep(1000);
  1869. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1870. Thread.Sleep(1000);
  1871. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1872. Thread.Sleep(1000);
  1873. //拍照前改变速度,延时
  1874. iSEM.CmdSaveRate();
  1875. cycle_time = iSEM.GetCycleTime();
  1876. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1877. if (!GetImage(ImageMode.SEM, fileName5))
  1878. {
  1879. arg.Message = "SEM拍照失败";
  1880. arg.State = false;
  1881. SendMsg("1-29");
  1882. return false;
  1883. }
  1884. arg.State = true;
  1885. arg.Message = "SEM拍照成功";
  1886. SendMsg("1-29");
  1887. iSEM.CmdFocusRate();
  1888. cycle_time = iSEM.GetCycleTime();
  1889. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1890. //判断是否停止进程
  1891. if (key_stop)
  1892. {
  1893. return false;
  1894. }
  1895. if (m_MsParam.Is_Photograph == false)
  1896. {
  1897. //8,计算切割面区域偏移角度及方向
  1898. float degree = 0;
  1899. int direction = 0;
  1900. wr.Img_Center_Position_OffsetAngle_Direction(fileName5, out degree, out direction, out state);
  1901. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "计算切割面区域的角度=" + degree.ToString(), true);
  1902. //接口返回像素,*pixelsize,得到坐标点。判断移动方式
  1903. if (state == 1)
  1904. {
  1905. //梯形角度
  1906. iSEM.SetScanRotationOn();
  1907. Thread.Sleep(1000);
  1908. iSEM.SetScanRotation(degree);
  1909. Thread.Sleep(1000);
  1910. arg.State = true;
  1911. arg.Message = "图像接口返回角度为:" + degree.ToString();
  1912. SendMsg("1-30");
  1913. if (hand_intervene == 1)
  1914. {
  1915. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1916. }
  1917. }
  1918. else
  1919. {
  1920. arg.Message = "图像接口参数State返回值为零";
  1921. arg.State = false;
  1922. SendMsg("1-30");
  1923. if(hand_intervene == 1)
  1924. {
  1925. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1926. {
  1927. return false;
  1928. }
  1929. }
  1930. else
  1931. {
  1932. return false;
  1933. }
  1934. }
  1935. //判断是否停止进程
  1936. if (key_stop)
  1937. {
  1938. return false;
  1939. }
  1940. //11、自动对焦。与之前操作相同
  1941. if (ImageFocus("1-31"))
  1942. {
  1943. arg.Message = "自动对焦完成";
  1944. arg.State = true;
  1945. SendMsg("1-31");
  1946. }
  1947. else
  1948. {
  1949. arg.Message = "自动对焦失败";
  1950. arg.State = false;
  1951. SendMsg("1-31");
  1952. }
  1953. //判断是否停止进程
  1954. if (key_stop)
  1955. {
  1956. return false;
  1957. }
  1958. //1.1大于10000倍进行消像散处理
  1959. dMag = iSEM.GetMagnification();
  1960. if (dMag > 10000)//需要消像散
  1961. {
  1962. if (!ImageStig("1-31"))
  1963. {
  1964. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1965. arg.Message = "拉直操作自动消像散失败!";
  1966. arg.State = false;
  1967. SendMsg("1-31");
  1968. return false;
  1969. }
  1970. arg.Message = "拉直操作自动消像散成功!";
  1971. arg.State = true;
  1972. SendMsg("1-31");
  1973. }
  1974. //12拍照
  1975. String fileName6 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName6;
  1976. arg.Picture_Information.Picture_FullPath = fileName6;
  1977. arg.Picture_Information.Work_Status = "SEM";
  1978. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1979. Thread.Sleep(1000);
  1980. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1981. Thread.Sleep(1000);
  1982. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1983. Thread.Sleep(1000);
  1984. //拍照前改变速度,延时
  1985. iSEM.CmdSaveRate();
  1986. cycle_time = iSEM.GetCycleTime();
  1987. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1988. if (!GetImage(ImageMode.SEM, fileName6))
  1989. {
  1990. arg.Message = "SEM拍照失败";
  1991. arg.State = false;
  1992. SendMsg("1-32");
  1993. return false;
  1994. }
  1995. arg.State = true;
  1996. image18 = fileName6;
  1997. arg.Message = "SEM拍照成功";
  1998. SendMsg("1-32");
  1999. iSEM.CmdFocusRate();
  2000. cycle_time = iSEM.GetCycleTime();
  2001. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2002. //判断是否停止进程
  2003. if (key_stop)
  2004. {
  2005. return false;
  2006. }
  2007. //华为程序还没有做出来
  2008. }
  2009. //14光束复位和Rotation关闭开关
  2010. arg.Message = "光束复位成功";
  2011. arg.State = true;
  2012. SendMsg("1-34");
  2013. iSEM.SetTiltAngleOff();
  2014. Thread.Sleep(1000);
  2015. iSEM.SetScanRotationOff();
  2016. Thread.Sleep(1000);
  2017. iSEM.SetBeamShiftX(0);
  2018. Thread.Sleep(1000);
  2019. iSEM.SetBeamShiftY(0);
  2020. Thread.Sleep(3000);
  2021. //判断是否停止进程
  2022. if (key_stop)
  2023. {
  2024. return false;
  2025. }
  2026. return true;
  2027. }
  2028. //第一个孔的测试过程
  2029. public bool FirstHole()
  2030. {
  2031. MeasureData.CutHole firstHole = m_cutHoles[0];
  2032. //设置拉直的放大倍数
  2033. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2034. {
  2035. arg.Message = "拉直放大倍数设置失败!";
  2036. arg.State = false;
  2037. SendMsg("1-0");
  2038. return false;
  2039. }
  2040. arg.Message = "拉直放大倍数设置成功!";
  2041. arg.State = true;
  2042. SendMsg("1-0");
  2043. Thread.Sleep(1000);
  2044. //自动化流程-每个点都需要补偿54度
  2045. if (m_MsParam.Is_Photograph == false)
  2046. {
  2047. if (!TiltCorrection(54.0f))
  2048. {
  2049. arg.Message = "角度补偿54度失败!";
  2050. arg.State = false;
  2051. SendMsg("1-1");
  2052. return false;
  2053. }
  2054. Thread.Sleep(2000);
  2055. arg.Message = "角度补偿54度成功!";
  2056. arg.State = true;
  2057. SendMsg("1-1");
  2058. //判断是否停止进程
  2059. if (key_stop)
  2060. {
  2061. return false;
  2062. }
  2063. }
  2064. //2、拉直操作
  2065. if (!Straighten_Handle())
  2066. {
  2067. LogManager.AddHardwareLog("拉直操作失败。", true);
  2068. return false;
  2069. }
  2070. //判断是否停止进程
  2071. if (key_stop)
  2072. {
  2073. return false;
  2074. }
  2075. //13. 自动 定位功能
  2076. if (!GetPoistion())
  2077. {
  2078. LogManager.AddHardwareLog("自动定位失败,程序退出。", true);
  2079. return false;
  2080. }
  2081. //判断是否停止进程
  2082. if (key_stop)
  2083. {
  2084. return false;
  2085. }
  2086. //14.自动控制FIB切割
  2087. if (m_MsParam.Is_Photograph == false)
  2088. {
  2089. if (!FIBCross())
  2090. {
  2091. return false;
  2092. }
  2093. }
  2094. //判断是否停止进程
  2095. if (key_stop)
  2096. {
  2097. return false;
  2098. }
  2099. //16.找到切割位置
  2100. if (m_MsParam.Is_Photograph == false)
  2101. {
  2102. if (!FindCross())
  2103. {
  2104. return false;
  2105. }
  2106. //判断是否停止进程
  2107. if (key_stop)
  2108. {
  2109. return false;
  2110. }
  2111. }
  2112. //将过程17最后的拍照图片提出给18步进行调用
  2113. String img18 = "";
  2114. //17.自动控制SEM拍截面照
  2115. if (!ShotSection(ref img18))
  2116. {
  2117. return false;
  2118. }
  2119. //判断是否停止进程
  2120. if (key_stop)
  2121. {
  2122. return false;
  2123. }
  2124. //18.自动层高分析
  2125. if (m_MsParam.Is_Photograph == false)
  2126. {
  2127. float size = iSEM.GetPixelSize();
  2128. float mag = iSEM.GetMagnification();
  2129. int state = 1;
  2130. //wr.Img_Measure_Size(img18, mag, size, out state);
  2131. if (state == 0)
  2132. {
  2133. arg.Message = "测量尺寸失败";
  2134. arg.State = false;
  2135. SendMsg("1-35");
  2136. return false;
  2137. }
  2138. arg.State = true;
  2139. arg.Message = "测量尺寸成功";
  2140. SendMsg("1-35");
  2141. }
  2142. #region 测试程序
  2143. //最后保存测量数据-测量文件、测量状态,m_cutHoles[i].STATE!=MeasureData.CutHole.State.Success.
  2144. //中间停止更新状态为Unmeasured,过程中return false时,更新状态为failed,保存测量文件
  2145. //if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))
  2146. //{
  2147. // SendMsg("拍摄照片完成");
  2148. // //return true;
  2149. //}
  2150. //else
  2151. //{
  2152. // SendMsg("拍摄照片失败");
  2153. // return false;
  2154. //}
  2155. //SendMsg("图像校正36度");
  2156. ////3.设置SEM角度补偿cos36度
  2157. //if (!TiltCorrection(36))
  2158. //{
  2159. // return false;
  2160. //}
  2161. //Thread.Sleep(3000);
  2162. //string fn;
  2163. //用宏抓一般图
  2164. //Thread.Sleep(5000);
  2165. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2166. //SendMsg("用宏抓一般图" + fn);
  2167. //iSEM.CMDMCFFilename(fn);
  2168. ////延时1s??
  2169. //Thread.Sleep(5000);
  2170. ////用宏抓好图
  2171. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2172. //SendMsg("用宏抓好图" + fn);
  2173. //iSEM.CMDMCFFilename(fn);
  2174. ////延时1s??
  2175. //Thread.Sleep(30000);
  2176. //Thread.Sleep(10000);
  2177. //WorkingFolder = m_measureFile.FilePath;
  2178. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2179. //SendMsg("SEM拍照存储到" + fileName6);
  2180. //if (!GetImage(ImageMode.SEM, fileName6))
  2181. //{
  2182. // SendMsg("SEM拍照失败");
  2183. // return false;
  2184. //}
  2185. ////用宏抓标志图
  2186. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2187. //SendMsg("用宏抓标志图" + fn);
  2188. //iSEM.CMDMCFFilename(fn);
  2189. ////延时1s??
  2190. //Thread.Sleep(30000);
  2191. //Thread.Sleep(5000);
  2192. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2193. //SendMsg("用宏抓一般图" + fn);
  2194. //iSEM.CMDMCFFilename(fn);
  2195. ////延时1s??
  2196. //Thread.Sleep(5000);
  2197. //SendMsg("所有图结束");
  2198. ////17.自动控制SEM拍截面照
  2199. //{
  2200. // //1.控制SEM放大到指定参数大小范围,6000x
  2201. // if (!iSEM.SetMagnification(6000))
  2202. // {
  2203. // return false;
  2204. // }
  2205. // //2.控制SEM自动对焦、消像散、亮度、对比度
  2206. // if (!MeasParam.FocusMode)
  2207. // {
  2208. // //弹出手动对焦的窗口
  2209. // }
  2210. // else
  2211. // {
  2212. // //调用自动对焦模块
  2213. // }
  2214. // //3.设置SEM角度补偿cos36度
  2215. // if (!TiltCorrection(36))
  2216. // {
  2217. // return false;
  2218. // }
  2219. // //4.控制SEM拍照
  2220. // //5.保存照片4
  2221. // String fileName5 = WorkingFolder + ImageName5;
  2222. // if (!GetImage(ImageMode.SEM, fileName5))
  2223. // {
  2224. // return false;
  2225. // }
  2226. // //6.将照片传给客户,获取偏移坐标
  2227. // float x6 = 0, y6 = 0;
  2228. // float angle1 = 0;
  2229. // float mage = 10000;
  2230. // //7.根据坐标控制SEM移动到分析位置
  2231. // if (!iSEM.MoveStageXY(x6, y6))
  2232. // {
  2233. // return false;
  2234. // }
  2235. // //8.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  2236. // float x7 = iSEM.GetStageAtX();
  2237. // float y7 = iSEM.GetStageAtY();
  2238. // if (Math.Abs(x6 - x7) > fMin && Math.Abs(y6 - y7) > fMin)
  2239. // {
  2240. // return false;
  2241. // }
  2242. // //9.控制SEM平行校正,并记录校正前初始值
  2243. // float foldAnagle = iSEM.GetScanRotation();
  2244. // if (foldAnagle == float.NaN)
  2245. // {
  2246. // return false;
  2247. // }
  2248. // if (!iSEM.SetScanRotation(angle1))
  2249. // {
  2250. // return false;
  2251. // }
  2252. // //10.控制SEM放大到指定参数大小范围
  2253. // if (!iSEM.SetMagnification(mage))
  2254. // {
  2255. // return false;
  2256. // }
  2257. // //11.控制SEM自动对焦、消像散、亮度、对比度
  2258. // if (!MeasParam.FocusMode)
  2259. // {
  2260. // //弹出手动对焦的窗口
  2261. // }
  2262. // else
  2263. // {
  2264. // //调用自动对焦模块
  2265. // }
  2266. // //12.控制SEM对分析位置拍照
  2267. // String fileName6 = WorkingFolder + ImageName6;
  2268. // if (!GetImage(ImageMode.SEM, fileName6))
  2269. // {
  2270. // return false;
  2271. // }
  2272. // //13.保存照片
  2273. // //14.控制SEM取消电子束校正,回到初始值
  2274. // if (!iSEM.SetScanRotation(foldAnagle))
  2275. // {
  2276. // return false;
  2277. // }
  2278. //}
  2279. ////18.自动层高分析
  2280. //{
  2281. // //1.获取SEM Pixel Size给客户传入参数
  2282. // if (iSEM.GetPixelSize() == float.NaN)
  2283. // {
  2284. // return false;
  2285. // }
  2286. // //2.将照片传给客户,客户进行层高分析(返回分析后的图像、相对坐标、分辨率、各层编号以及各层对应的层高数据),如果客户自行出分析报告则无需返回数据
  2287. //}
  2288. ////19.自动能谱分析
  2289. //{
  2290. // //1. 确定能谱位置
  2291. // //2. 控制牛津打能谱
  2292. // //3. 能谱分析——面扫+线扫描
  2293. //}
  2294. #endregion
  2295. return true;
  2296. }
  2297. //非第一个孔的测试过程
  2298. public bool OtherHole()
  2299. {
  2300. //设置拉直的放大倍数
  2301. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2302. {
  2303. LogManager.AddHardwareLog("拉直放大倍数设置失败,程序退出。", true);
  2304. arg.Message = "拉直放大倍数设置失败!";
  2305. arg.State = false;
  2306. SendMsg("1-0");
  2307. return false;
  2308. }
  2309. arg.Message = "拉直放大倍数设置成功!";
  2310. arg.State = true;
  2311. SendMsg("1-0");
  2312. Thread.Sleep(1000);
  2313. //自动化流程-每个点都需要补偿54度
  2314. if (m_MsParam.Is_Photograph == false)
  2315. {
  2316. if (!TiltCorrection(54.0f))
  2317. {
  2318. arg.Message = "角度补偿54度失败!";
  2319. arg.State = false;
  2320. SendMsg("1-1");
  2321. return false;
  2322. }
  2323. arg.Message = "角度补偿54度成功!";
  2324. arg.State = true;
  2325. SendMsg("1-1");
  2326. Thread.Sleep(2000);
  2327. //判断是否停止进程
  2328. if (key_stop)
  2329. {
  2330. return false;
  2331. }
  2332. }
  2333. //拉直操作
  2334. if (!Straighten_Handle())
  2335. {
  2336. return false;
  2337. }
  2338. //判断是否停止进程
  2339. if (key_stop)
  2340. {
  2341. return false;
  2342. }
  2343. //13. 自动 定位功能
  2344. if (!GetPoistion())
  2345. {
  2346. return false;
  2347. }
  2348. //判断是否停止进程
  2349. if (key_stop)
  2350. {
  2351. return false;
  2352. }
  2353. //14.自动控制FIB切割
  2354. if (m_MsParam.Is_Photograph == false)
  2355. {
  2356. if (!FIBCross())
  2357. {
  2358. return false;
  2359. }
  2360. }
  2361. //判断是否停止进程
  2362. if (key_stop)
  2363. {
  2364. return false;
  2365. }
  2366. // 16.找到切割位置
  2367. if (m_MsParam.Is_Photograph == false)
  2368. {
  2369. if (!FindCross())
  2370. {
  2371. return false;
  2372. }
  2373. //判断是否停止进程
  2374. if (key_stop)
  2375. {
  2376. return false;
  2377. }
  2378. }
  2379. //将过程17最后的拍照图片提出给18步进行调用
  2380. String img18 = "";
  2381. //17.自动控制SEM拍截面照
  2382. if (!ShotSection(ref img18))
  2383. {
  2384. return false;
  2385. }
  2386. //判断是否停止进程
  2387. if (key_stop)
  2388. {
  2389. return false;
  2390. }
  2391. //18.自动层高分析
  2392. if (m_MsParam.Is_Photograph == false)
  2393. {
  2394. float size = iSEM.GetPixelSize();
  2395. float mag = iSEM.GetMagnification();
  2396. int state = 1;
  2397. //wr.Img_Measure_Size(img18, mag, size, out state);
  2398. if (state == 0)
  2399. {
  2400. arg.Message = "测量尺寸失败";
  2401. SendMsg("1-35");
  2402. return false;
  2403. }
  2404. arg.Message = "测量尺寸成功";
  2405. SendMsg("1-35");
  2406. }
  2407. #region 测试程序
  2408. //string fn;
  2409. //用宏抓一般图
  2410. //Thread.Sleep(5000);
  2411. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2412. //SendMsg("用宏抓一般图" + fn);
  2413. //iSEM.CMDMCFFilename(fn);
  2414. ////延时1s??
  2415. //Thread.Sleep(5000);
  2416. ////用宏抓好图
  2417. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2418. //SendMsg("用宏抓好图" + fn);
  2419. //iSEM.CMDMCFFilename(fn);
  2420. ////延时1s??
  2421. //Thread.Sleep(30000);
  2422. //Thread.Sleep(10000);
  2423. //WorkingFolder = m_measureFile.FilePath;
  2424. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2425. //SendMsg("SEM拍照存储到" + fileName6);
  2426. //if (!GetImage(ImageMode.SEM, fileName6))
  2427. //{
  2428. // SendMsg("SEM拍照失败");
  2429. // return false;
  2430. //}
  2431. ////用宏抓标志图
  2432. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2433. //SendMsg("用宏抓标志图" + fn);
  2434. //iSEM.CMDMCFFilename(fn);
  2435. ////延时1s??
  2436. //Thread.Sleep(30000);
  2437. ////恢复简单抓图
  2438. //Thread.Sleep(5000);
  2439. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2440. //SendMsg("用宏抓一般图" + fn);
  2441. //iSEM.CMDMCFFilename(fn);
  2442. //SendMsg("所有图结束");
  2443. #endregion
  2444. return true;
  2445. }
  2446. //测试完第一个孔后的样品台初始化操作。
  2447. //再调用CommonWork执行非第一个孔的测试过程
  2448. public bool OtherHole_Init()
  2449. {
  2450. CutHole currentHole = m_cutHoles[m_nWorkHoleNo];
  2451. #region 1. 初始化
  2452. if (m_MsParam.Is_Photograph == false)
  2453. {
  2454. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2455. if (!iSEM.SetStageGotoT(0))
  2456. {
  2457. return false;
  2458. }
  2459. while (true)
  2460. {
  2461. Thread.Sleep(5000);
  2462. if (iSEM.GetStageIs() == 0)
  2463. {
  2464. break;
  2465. }
  2466. }
  2467. //判断是否停止进程
  2468. if (key_stop)
  2469. {
  2470. return false;
  2471. }
  2472. }
  2473. //6. 根据光镜坐标控制样品台移动
  2474. if (!iSEM.SetStageGotoR(currentHole.Position.R))
  2475. {
  2476. //SendMsg("移动失败");
  2477. return false;
  2478. }
  2479. LogManager.AddHardwareLog("移动R轴到="+ currentHole.Position.R.ToString(), true);
  2480. while (true)
  2481. {
  2482. Thread.Sleep(5000);
  2483. if (iSEM.GetStageIs() == 0)
  2484. {
  2485. break;
  2486. }
  2487. }
  2488. //判断是否停止进程
  2489. if (key_stop)
  2490. {
  2491. return false;
  2492. }
  2493. if(!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))
  2494. {
  2495. //SendMsg("移动失败");
  2496. return false;
  2497. }
  2498. LogManager.AddHardwareLog("移动X轴Y轴=" + currentHole.Position.X.ToString() + " " + currentHole.Position.Y.ToString(), true);
  2499. while (true)
  2500. {
  2501. Thread.Sleep(10000);
  2502. if (iSEM.GetStageIs() == 0)
  2503. {
  2504. break;
  2505. }
  2506. }
  2507. //判断是否停止进程
  2508. if (key_stop)
  2509. {
  2510. return false;
  2511. }
  2512. //7. 控制样品台,调整T轴54度、M/Z/R轴不变
  2513. if (m_MsParam.Is_Photograph == false)
  2514. {
  2515. if (!iSEM.SetStageGotoT(54))
  2516. {
  2517. return false;
  2518. }
  2519. while (true)
  2520. {
  2521. Thread.Sleep(5000);
  2522. if (iSEM.GetStageIs() == 0)
  2523. {
  2524. break;
  2525. }
  2526. }
  2527. }
  2528. //判断是否停止进程
  2529. if (key_stop)
  2530. {
  2531. return false;
  2532. }
  2533. #endregion
  2534. return true;
  2535. }
  2536. //初始化拉直操作
  2537. public bool Straighten_Handle()
  2538. {
  2539. //1、自动对焦
  2540. if (!ImageFocus("1-2"))
  2541. {
  2542. LogManager.AddHardwareLog("拉直操作自动对焦失败,程序退出。", true);
  2543. arg.Message = "拉直操作自动对焦失败!";
  2544. arg.State = false;
  2545. SendMsg("1-2");
  2546. return false;
  2547. }
  2548. arg.Message = "拉直操作自动对焦成功!";
  2549. arg.State = true;
  2550. SendMsg("1-2");
  2551. //判断是否停止进程
  2552. if (key_stop)
  2553. {
  2554. return false;
  2555. }
  2556. //1.1大于10000倍进行消像散处理
  2557. float dMag = iSEM.GetMagnification();
  2558. if (dMag > 10000)//需要消像散
  2559. {
  2560. if (!ImageStig("1-2"))
  2561. {
  2562. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  2563. arg.Message = "拉直操作自动消像散失败!";
  2564. arg.State = false;
  2565. SendMsg("1-2");
  2566. return false;
  2567. }
  2568. arg.Message = "拉直操作自动消像散成功!";
  2569. arg.State = true;
  2570. SendMsg("1-2");
  2571. }
  2572. //2、拍张照片
  2573. String fileName0 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Stretch_Magnification.ToString("0") + "_" + ImageName0;
  2574. //拍照前改变速度,延时
  2575. iSEM.CmdSaveRate();
  2576. cycle_time = iSEM.GetCycleTime();
  2577. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2578. if (!GetImage(ImageMode.SEM, fileName0))
  2579. {
  2580. arg.Message = "拉直拍照成功";
  2581. arg.State = false;
  2582. SendMsg("1-3");
  2583. return false;
  2584. }
  2585. arg.Message = "拉直拍照成功!";
  2586. arg.State = true;
  2587. SendMsg("1-3");
  2588. iSEM.CmdFocusRate();
  2589. cycle_time = iSEM.GetCycleTime();
  2590. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2591. //3、华为接口,获取旋转角度
  2592. float degree = 0;
  2593. int direction = 0;
  2594. int state = 1;
  2595. wr.Img_OffsetAngle_Direction(fileName0, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out degree, out direction, out state);
  2596. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "初始化拉直角度=" + degree.ToString(), true);
  2597. if (state == 0)
  2598. {
  2599. arg.Message = "华为接口参数state返回为零";
  2600. arg.State = false;
  2601. SendMsg("1-4");
  2602. if (hand_intervene == 1)
  2603. {
  2604. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  2605. {
  2606. return false;
  2607. }
  2608. }
  2609. else
  2610. {
  2611. return false;
  2612. }
  2613. }
  2614. if (direction == 2)
  2615. {
  2616. degree = -degree;
  2617. }
  2618. #region//暂时不用这个拉直
  2619. //旋转R轴
  2620. //float getr = iSEM.GetStageAtR();
  2621. //getr = getr + degree;
  2622. //if(getr>R_Max)
  2623. //{
  2624. // getr = getr - 360;
  2625. //}
  2626. //if(getr<R_Min)
  2627. //{
  2628. // getr = getr + 360;
  2629. //}
  2630. //iSEM.SetStageGotoR(getr);
  2631. //while (true)
  2632. //{
  2633. // Thread.Sleep(5000);
  2634. // if (iSEM.GetStageIs() == 0)
  2635. // {
  2636. // break;
  2637. // }
  2638. //}
  2639. //MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  2640. //////3、拉直
  2641. //float x0 = iSEM.GetStageAtX();
  2642. //float y0 = iSEM.GetStageAtY();
  2643. //float x1 = 0, y1 = 0;
  2644. //Straightening(degree, x_center_point, y_center_point, x0, y0, ref x1, ref y1);
  2645. //if (x1 < X_Min || x1 > X_Max || y1 < Y_Min || y1 > Y_Max)
  2646. //{
  2647. // return false;
  2648. //}
  2649. //iSEM.MoveStageXY(x1, y1);
  2650. #endregion
  2651. //4、拉直,旋转R轴
  2652. iSEM.SetStageDeltaR(degree);
  2653. while (true)
  2654. {
  2655. Thread.Sleep(5000);
  2656. if (iSEM.GetStageIs() == 0)
  2657. {
  2658. break;
  2659. }
  2660. }
  2661. arg.Message = "拉直操作完成";
  2662. arg.State = true;
  2663. SendMsg("1-4");
  2664. //华为接口,去掉人工干预
  2665. //MessageBox.Show("拉直操作完成,如果不正确请手动进行拉直然后点击OK按钮。", "确认消息", MessageBoxButtons.OK);
  2666. return true;
  2667. }
  2668. //角度补偿
  2669. public bool TiltCorrection(float a_fAngle)
  2670. {
  2671. if (!iSEM.SetTiltAngleOn())
  2672. {
  2673. return false;
  2674. }
  2675. //恢复原始状态
  2676. if (!iSEM.SetTiltAngle(a_fAngle))
  2677. {
  2678. return false;
  2679. }
  2680. return true;
  2681. }
  2682. //拍图
  2683. public bool GetImage(ImageMode a_mode, String a_fileName)
  2684. {
  2685. //3. 获取分辨率
  2686. int[] ImageSize = iSEM.GetImageStore();
  2687. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  2688. {
  2689. return false;
  2690. }
  2691. short width = (short)ImageSize[0];
  2692. short height = (short)ImageSize[1];
  2693. //4. 抓图
  2694. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  2695. {
  2696. return false;
  2697. }
  2698. return true;
  2699. }
  2700. //自动聚焦
  2701. public bool AutoFocus(FocusParam a_param, out int a_nWd, String step_code)
  2702. {
  2703. a_nWd = 0;
  2704. float wd = iSEM.GetWorkingDistance();
  2705. a_nWd = (int)Math.Ceiling(wd * 100000000 + 0.5);//获取当前的工作距离
  2706. if (a_param == null)
  2707. {
  2708. LogManager.AddHardwareLog("空参数", true);
  2709. return false;
  2710. }
  2711. string path = a_param.Path;
  2712. if (!Directory.Exists(path))
  2713. {
  2714. LogManager.AddHardwareLog("文件夹丢失", true);
  2715. return false;
  2716. }
  2717. string path_coarse = a_param.Path + "\\Coarse";
  2718. if (!Directory.Exists(path_coarse))
  2719. {
  2720. Directory.CreateDirectory(path_coarse);
  2721. }
  2722. string path_fine = a_param.Path + "\\Fine";
  2723. if (!Directory.Exists(path_fine))
  2724. {
  2725. Directory.CreateDirectory(path_fine);
  2726. }
  2727. //1. 拍照
  2728. //1.1, 粗拍照
  2729. //1.1.1, 根据参数计算拍照次数
  2730. double nUp = a_param.UP * 100.0 ;
  2731. double nDown = a_param.Down * 100.0;
  2732. double nStep = a_param.Step * 100.0;
  2733. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2734. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2735. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2736. //粗拍照
  2737. for (int i = 0; i < nTimes; i++)
  2738. {
  2739. int cWd =(int) Math.Ceiling(nUp + i * nStep + 0.5);
  2740. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2741. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2742. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2743. int swd = cWd / 100;
  2744. //SendMsg("wd = " + swd.ToString() +"um");
  2745. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2746. arg.Picture_Information.Picture_FullPath = fileName;
  2747. if (!GetImage(ImageMode.SEM, fileName))
  2748. {
  2749. return false;
  2750. }
  2751. arg.State = true;
  2752. arg.Message = "自动对焦";
  2753. SendMsg(step_code);
  2754. //判断是否停止进程
  2755. if (key_stop)
  2756. {
  2757. return false;
  2758. }
  2759. //Thread.Sleep(3000);
  2760. }
  2761. //1.2, 选定细拍照的工作距离
  2762. int CorWd;
  2763. ChooseBest(path_coarse,out CorWd);
  2764. a_nWd = CorWd;
  2765. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2766. //1.3, 细拍照
  2767. if ( (CorWd - a_param.Range * 100.0) <=0)
  2768. {
  2769. return false;
  2770. }
  2771. double nfUp = CorWd - a_param.Range * 100.0;
  2772. double nfStep = a_param.fStep * 100.0;
  2773. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2774. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2775. for (int i = 0; i < nfTimes; i++)
  2776. {
  2777. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2778. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2779. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2780. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  2781. int swd = cWd / 100;
  2782. //SendMsg("wd = " + swd.ToString() + "um");
  2783. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2784. arg.Picture_Information.Picture_FullPath = fileName;
  2785. if (!GetImage(ImageMode.SEM, fileName))
  2786. {
  2787. return false;
  2788. }
  2789. arg.State = true;
  2790. arg.Message = "自动对焦";
  2791. SendMsg(step_code);
  2792. //判断是否停止进程
  2793. if (key_stop)
  2794. {
  2795. return false;
  2796. }
  2797. //Thread.Sleep(2000);
  2798. }
  2799. int fineWd;
  2800. ChooseBest(path_fine, out fineWd);
  2801. //SendMsg("wd fine max = " + fineWd.ToString());
  2802. a_nWd = fineWd;
  2803. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2804. return true;
  2805. }
  2806. //自动消像散 AutoStig
  2807. public bool AutoStig(FocusParam a_param, out int a_nWd, String step_code)
  2808. {
  2809. a_nWd = 0;
  2810. float wd = 0;
  2811. if (a_param.TYPE == 2)
  2812. {
  2813. wd = iSEM.GetAstigmatismX();
  2814. }
  2815. else if (a_param.TYPE == 3)
  2816. {
  2817. wd = iSEM.GetAstigmatismY();
  2818. }
  2819. else
  2820. {
  2821. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2822. return false;
  2823. }
  2824. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2825. if (a_param == null)
  2826. {
  2827. LogManager.AddHardwareLog("空参数", true);
  2828. return false;
  2829. }
  2830. string path = a_param.Path;
  2831. if (!Directory.Exists(path))
  2832. {
  2833. LogManager.AddHardwareLog("文件夹丢失", true);
  2834. return false;
  2835. }
  2836. string path_coarse = a_param.Path + "\\Coarse";
  2837. if (!Directory.Exists(path_coarse))
  2838. {
  2839. Directory.CreateDirectory(path_coarse);
  2840. }
  2841. string path_fine = a_param.Path + "\\Fine";
  2842. if (!Directory.Exists(path_fine))
  2843. {
  2844. Directory.CreateDirectory(path_fine);
  2845. }
  2846. //1. 拍照
  2847. //1.1, 粗拍照
  2848. //1.1.1, 根据参数计算拍照次数
  2849. double nUp = a_param.UP * 100.0;
  2850. double nDown = a_param.Down * 100.0;
  2851. double nStep = a_param.Step * 100.0;
  2852. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2853. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2854. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2855. //粗拍照
  2856. for (int i = 0; i < nTimes; i++)
  2857. {
  2858. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  2859. if (a_param.TYPE == 2)
  2860. {
  2861. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2862. }
  2863. else if (a_param.TYPE == 3)
  2864. {
  2865. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2866. }
  2867. else
  2868. {
  2869. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2870. return false;
  2871. }
  2872. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2873. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2874. int swd = cWd / 100;
  2875. //SendMsg("wd = " + swd.ToString() +"um");
  2876. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2877. arg.Picture_Information.Picture_FullPath = fileName;
  2878. if (!GetImage(ImageMode.SEM, fileName))
  2879. {
  2880. return false;
  2881. }
  2882. arg.State = true;
  2883. arg.Message = "自动像散";
  2884. SendMsg(step_code);
  2885. //判断是否停止进程
  2886. if (key_stop)
  2887. {
  2888. return false;
  2889. }
  2890. //Thread.Sleep(3000);
  2891. }
  2892. //1.2, 选定细拍照的工作距离
  2893. int CorWd;
  2894. ChooseBest(path_coarse, out CorWd);
  2895. a_nWd = CorWd;
  2896. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2897. //1.3, 细拍照
  2898. if ((CorWd - a_param.Range * 100.0) <= -10000)
  2899. {
  2900. return false;
  2901. }
  2902. double nfUp = CorWd - a_param.Range * 100.0;
  2903. double nfStep = a_param.fStep * 100.0;
  2904. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2905. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2906. for (int i = 0; i < nfTimes; i++)
  2907. {
  2908. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2909. if (a_param.TYPE == 2)
  2910. {
  2911. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2912. }
  2913. else if (a_param.TYPE == 3)
  2914. {
  2915. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2916. }
  2917. else
  2918. {
  2919. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2920. return false;
  2921. }
  2922. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2923. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2924. int swd = cWd / 100;
  2925. //SendMsg("wd = " + swd.ToString() + "um");
  2926. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2927. arg.Picture_Information.Picture_FullPath = fileName;
  2928. if (!GetImage(ImageMode.SEM, fileName))
  2929. {
  2930. return false;
  2931. }
  2932. arg.State = true;
  2933. arg.Message = "自动像散";
  2934. SendMsg(step_code);
  2935. //判断是否停止进程
  2936. if (key_stop)
  2937. {
  2938. return false;
  2939. }
  2940. //Thread.Sleep(2000);
  2941. }
  2942. int fineWd;
  2943. ChooseBest(path_fine, out fineWd);
  2944. //SendMsg("wd fine max = " + fineWd.ToString());
  2945. a_nWd = fineWd;
  2946. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2947. return true;
  2948. }
  2949. //自动FIB对焦 AutoFIBFocus
  2950. public bool AutoFIBFocus(FocusParam a_param, out int a_nWd, String step_code)
  2951. {
  2952. a_nWd = 0;
  2953. float wd = 0;
  2954. if (a_param.TYPE == 4)
  2955. {
  2956. wd = iSEM.GetFIBObjectivePotential();
  2957. }
  2958. else
  2959. {
  2960. LogManager.AddHardwareLog("FIB自动聚焦参数设置有误", true);
  2961. return false;
  2962. }
  2963. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2964. if (a_param == null)
  2965. {
  2966. LogManager.AddHardwareLog("空参数", true);
  2967. return false;
  2968. }
  2969. string path = a_param.Path;
  2970. if (!Directory.Exists(path))
  2971. {
  2972. LogManager.AddHardwareLog("文件夹丢失", true);
  2973. return false;
  2974. }
  2975. string path_coarse = a_param.Path + "\\Coarse";
  2976. if (!Directory.Exists(path_coarse))
  2977. {
  2978. Directory.CreateDirectory(path_coarse);
  2979. }
  2980. string path_fine = a_param.Path + "\\Fine";
  2981. if (!Directory.Exists(path_fine))
  2982. {
  2983. Directory.CreateDirectory(path_fine);
  2984. }
  2985. //1. 拍照
  2986. //1.1, 粗拍照
  2987. //1.1.1, 根据参数计算拍照次数
  2988. double nUp = a_param.UP * 100.0;
  2989. double nDown = a_param.Down * 100.0;
  2990. double nStep = a_param.Step * 100.0;
  2991. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2992. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2993. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2994. //粗拍照
  2995. for (int i = 0; i < nTimes; i++)
  2996. {
  2997. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  2998. if (a_param.TYPE == 4)
  2999. {
  3000. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3001. }
  3002. else
  3003. {
  3004. LogManager.AddHardwareLog("FIB对焦参数设置有误,对焦类型错", true);
  3005. return false;
  3006. }
  3007. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3008. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3009. int swd = cWd / 100;
  3010. //SendMsg("wd = " + swd.ToString() +"um");
  3011. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  3012. arg.Picture_Information.Picture_FullPath = fileName;
  3013. if (!GetImage(ImageMode.SEM, fileName))
  3014. {
  3015. return false;
  3016. }
  3017. arg.State = true;
  3018. arg.Message = "FIB自动对焦";
  3019. SendMsg(step_code);
  3020. //判断是否停止进程
  3021. if (key_stop)
  3022. {
  3023. return false;
  3024. }
  3025. //Thread.Sleep(3000);
  3026. }
  3027. //1.2, 选定细拍照的工作距离
  3028. int CorWd;
  3029. ChooseBest(path_coarse, out CorWd);
  3030. a_nWd = CorWd;
  3031. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  3032. //1.3, 细拍照
  3033. if ((CorWd - a_param.Range * 100.0) <0)
  3034. {
  3035. return false;
  3036. }
  3037. double nfUp = CorWd - a_param.Range * 100.0;
  3038. double nfStep = a_param.fStep * 100.0;
  3039. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  3040. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  3041. for (int i = 0; i < nfTimes; i++)
  3042. {
  3043. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  3044. if (a_param.TYPE == 4)
  3045. {
  3046. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3047. }
  3048. else
  3049. {
  3050. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  3051. return false;
  3052. }
  3053. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3054. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3055. int swd = cWd / 100;
  3056. //SendMsg("wd = " + swd.ToString() + "um");
  3057. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  3058. arg.Picture_Information.Picture_FullPath = fileName;
  3059. if (!GetImage(ImageMode.SEM, fileName))
  3060. {
  3061. return false;
  3062. }
  3063. arg.State = true;
  3064. arg.Message = "FIB自动对焦";
  3065. SendMsg(step_code);
  3066. //判断是否停止进程
  3067. if (key_stop)
  3068. {
  3069. return false;
  3070. }
  3071. //Thread.Sleep(2000);
  3072. }
  3073. int fineWd;
  3074. ChooseBest(path_fine, out fineWd);
  3075. //SendMsg("wd fine max = " + fineWd.ToString());
  3076. a_nWd = fineWd;
  3077. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  3078. return true;
  3079. }
  3080. //LoG算子计算
  3081. private double LoGMean(string a_strImgPath)
  3082. {
  3083. //读入Img文件
  3084. if (!File.Exists(a_strImgPath))
  3085. {
  3086. return 0;
  3087. }
  3088. Mat src, gray_src;
  3089. int kernel_size = 3;
  3090. src = Cv2.ImRead(a_strImgPath);
  3091. gray_src = new Mat();
  3092. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3093. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3094. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3095. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3096. Cv2.Laplacian(src, src, MatType.CV_8UC3, kernel_size);
  3097. Cv2.ConvertScaleAbs(src, src);
  3098. //图像的平均灰度
  3099. double meanValue = 0.0;
  3100. meanValue = Cv2.Mean(src)[0];
  3101. return meanValue;
  3102. }
  3103. //梯度计算
  3104. private double Tenengrad(string a_strImgPath)
  3105. {
  3106. //读入Img文件
  3107. if (!File.Exists(a_strImgPath))
  3108. {
  3109. return 0;
  3110. }
  3111. Mat src;
  3112. src = Cv2.ImRead(a_strImgPath);
  3113. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3114. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3115. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3116. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3117. Cv2.Sobel(src, src, MatType.CV_8UC1, 1, 1);
  3118. //图像的平均灰度
  3119. double meanValue = 0.0;
  3120. meanValue = Cv2.Mean(src)[0];
  3121. return meanValue;
  3122. }
  3123. //梯度计算
  3124. private double TTgrad(string a_strImgPath)
  3125. {
  3126. //读入Img文件
  3127. if (!File.Exists(a_strImgPath))
  3128. {
  3129. return 0;
  3130. }
  3131. Mat src;
  3132. src = Cv2.ImRead(a_strImgPath);
  3133. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3134. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3135. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3136. Mat scalex = new Mat();
  3137. Mat scaley = new Mat();
  3138. Cv2.Scharr(src, src, src.Depth(), 1, 0);
  3139. Cv2.ConvertScaleAbs(src, scalex);
  3140. Cv2.Scharr(src, src, src.Depth(), 0, 1);
  3141. Cv2.ConvertScaleAbs(src, scaley);
  3142. Cv2.AddWeighted(scalex, 0.5, scaley, 0.5, 0, src);
  3143. //图像的平均灰度
  3144. double meanValue = 0.0;
  3145. meanValue = Cv2.Mean(src)[0];
  3146. return meanValue;
  3147. }
  3148. //三选二算法
  3149. private void ChooseBest(string a_strImgPath, out int a_nWd)
  3150. {
  3151. a_nWd = -1;
  3152. var files = Directory.GetFiles(a_strImgPath, "*.tif");
  3153. float[] values = new float[files.Length];
  3154. double smax1 = LoGMean(files[0]);
  3155. int wdmax1 = int.Parse(System.IO.Path.GetFileNameWithoutExtension(files[0]));
  3156. double smax2 = Tenengrad(files[0]);
  3157. int wdmax2 = wdmax1;
  3158. double smax3 = TTgrad(files[0]);
  3159. int wdmax3 = wdmax1;
  3160. int x = 0;
  3161. foreach (var file in files)
  3162. {
  3163. int wd = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file));
  3164. double svalue1 = LoGMean(file);
  3165. double svalue2 = Tenengrad(file);
  3166. double svalue3 = TTgrad(file);
  3167. if (smax1 < svalue1)
  3168. {
  3169. smax1 = svalue1;
  3170. wdmax1 = wd;
  3171. }
  3172. if (smax2 < svalue2)
  3173. {
  3174. smax2 = svalue2;
  3175. wdmax2 = wd;
  3176. }
  3177. if (smax3 < svalue3)
  3178. {
  3179. smax3 = svalue3;
  3180. wdmax3 = wd;
  3181. }
  3182. x++;
  3183. }
  3184. //SendMsg("LoG = " + wdmax1.ToString() + ",梯度 = " + wdmax2.ToString() + ",滤波 = " + wdmax3.ToString());
  3185. if (wdmax1 == wdmax2 || wdmax1 == wdmax3)
  3186. {
  3187. a_nWd = wdmax1;
  3188. //SendMsg("焦距 = " + wdmax1.ToString());
  3189. }
  3190. else if (wdmax1 == wdmax2 || wdmax2 == wdmax3)
  3191. {
  3192. a_nWd = wdmax2;
  3193. //SendMsg("焦距 = " + wdmax2.ToString());
  3194. }
  3195. else if (wdmax3 == wdmax2 || wdmax1 == wdmax3)
  3196. {
  3197. a_nWd = wdmax3;
  3198. //SendMsg("焦距 = " + wdmax3.ToString());
  3199. }
  3200. else
  3201. {
  3202. //SendMsg("对焦失败。");
  3203. }
  3204. }
  3205. //移动到像素位置
  3206. bool MoveToPix(float xc, float yc)
  3207. {
  3208. float pixSize = iSEM.GetPixelSize();
  3209. Thread.Sleep(500);
  3210. //0:width, 1:height
  3211. int[] imageSize = iSEM.GetImageStore();
  3212. int width = imageSize[0]/2;
  3213. int height = imageSize[1]/2;
  3214. float deltX = (xc - (float)width) * pixSize;
  3215. float deltY = (yc - (float)height) * pixSize;
  3216. float xpCur = iSEM.GetStageAtX();
  3217. float ypCur = iSEM.GetStageAtY();
  3218. float xpNew = xpCur - deltX;
  3219. float ypNew = ypCur - deltY;
  3220. LogManager.AddHardwareLog("样品台移动信息:deltx=" + deltX.ToString() +
  3221. ",delty=" + deltY.ToString() + ",xpNew=" + xpNew.ToString() + ",ypNew=" + ypNew.ToString(), true);
  3222. if (deltX > 10)//使用移动样品台实现
  3223. {
  3224. if (!iSEM.SetStageGotoX(xpNew))
  3225. {
  3226. return false;
  3227. }
  3228. //判断是否移动完成
  3229. while (true)
  3230. {
  3231. Thread.Sleep(5000);
  3232. if (iSEM.GetStageIs() == 0)
  3233. {
  3234. break;
  3235. }
  3236. }
  3237. //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  3238. //arg.State = true;
  3239. //SendMsg("1-7");
  3240. }
  3241. else//使用移动光束实现
  3242. {
  3243. float beamX = deltX * (float)0.66;
  3244. if (!iSEM.SetBeamShiftX(beamX))
  3245. {
  3246. return false;
  3247. }
  3248. }
  3249. if (deltY > 10)//使用移动样品台实现
  3250. {
  3251. if (!iSEM.SetStageGotoY(ypNew))
  3252. {
  3253. return false;
  3254. }
  3255. //判断是否移动完成
  3256. while (true)
  3257. {
  3258. Thread.Sleep(5000);
  3259. if (iSEM.GetStageIs() == 0)
  3260. {
  3261. break;
  3262. }
  3263. }
  3264. }
  3265. else//使用移动光束实现
  3266. {
  3267. float beamY = deltY * (float)0.671;
  3268. if (!iSEM.SetBeamShiftY(beamY))
  3269. {
  3270. return false;
  3271. }
  3272. }
  3273. return true;
  3274. }
  3275. }
  3276. }