Measure.cs 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722
  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. return false;
  1144. }
  1145. //判断是否停止进程
  1146. if (key_stop)
  1147. {
  1148. return false;
  1149. }
  1150. //1.1大于10000倍进行消像散处理
  1151. float dMag = iSEM.GetMagnification();
  1152. if (dMag > 10000)//需要消像散
  1153. {
  1154. if (!ImageStig("1-6"))
  1155. {
  1156. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1157. arg.Message = "拉直操作自动消像散失败!";
  1158. arg.State = false;
  1159. SendMsg("1-6");
  1160. return false;
  1161. }
  1162. arg.Message = "拉直操作自动消像散成功!";
  1163. arg.State = true;
  1164. SendMsg("1-6");
  1165. }
  1166. //3.控制SEM拍照,找到切割位置
  1167. String fileName1 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Location_Magnification.ToString("0") + "_" + ImageName1;
  1168. arg.Picture_Information.Picture_FullPath = fileName1;
  1169. arg.Picture_Information.Work_Voltage = m_MsParam.Location_Voltage;
  1170. arg.Picture_Information.Magnification = m_MsParam.Location_Magnification;
  1171. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1172. Thread.Sleep(1000);
  1173. //拍照前改变速度,延时
  1174. iSEM.CmdSaveRate();
  1175. cycle_time = iSEM.GetCycleTime();
  1176. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1177. if (!GetImage(ImageMode.SEM, fileName1))
  1178. {
  1179. arg.Message = "SEM拍照失败";
  1180. arg.State = false;
  1181. SendMsg("1-7");
  1182. return false;
  1183. }
  1184. arg.State = true;
  1185. arg.Message = "SEM拍照成功";
  1186. SendMsg("1-7");
  1187. iSEM.CmdFocusRate();
  1188. cycle_time = iSEM.GetCycleTime();
  1189. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1190. //判断是否停止进程
  1191. if (key_stop)
  1192. {
  1193. return false;
  1194. }
  1195. //判断是否为仅拍照,不是则执行FIB操作
  1196. if (!m_MsParam.Is_Photograph)
  1197. {
  1198. //6.设置FIB拍照参数——扫描时间、束流等
  1199. //7.控制FIB自动亮度、对比度
  1200. if (!iSEM.CmdFIBModeFIB())
  1201. {
  1202. arg.Message = "FIB模式切换失败";
  1203. arg.State = false;
  1204. SendMsg("1-8");
  1205. return false;
  1206. }
  1207. arg.State = true;
  1208. arg.Picture_Information.Work_Status = "FIB";
  1209. arg.Message = "FIB模式切换成功";
  1210. SendMsg("1-8");
  1211. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1212. //判断是否停止进程
  1213. if (key_stop)
  1214. {
  1215. return false;
  1216. }
  1217. //8.控制FIB拍照
  1218. //9.保存照片======更改路径
  1219. String fileName2 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString("0") + "_" + ImageName2;
  1220. arg.Picture_Information.Picture_FullPath = fileName2;
  1221. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1222. Thread.Sleep(1000);
  1223. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1224. Thread.Sleep(1000);
  1225. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1226. Thread.Sleep(1000);
  1227. //FIB的放大位数,将来会改
  1228. if(!iSEM.SetFIBMagnification(m_MsParam.FIB_Magnification))
  1229. {
  1230. arg.Message = "FIB放大倍数设置失败";
  1231. arg.State = false;
  1232. SendMsg("1-9");
  1233. return false;
  1234. }
  1235. arg.Message = "FIB放大倍数设置成功";
  1236. arg.State = true;
  1237. SendMsg("1-9");
  1238. Thread.Sleep(1000);
  1239. //增加FIB对焦
  1240. //2.控制SEM自动对焦、亮度、对比度
  1241. if (FIBFocus("1-10"))
  1242. {
  1243. arg.Message = "自动FIB对焦完成";
  1244. arg.State = true;
  1245. SendMsg("1-10");
  1246. }
  1247. else
  1248. {
  1249. LogManager.AddHardwareLog("设置观测点后,自动FIB对焦失败。", true);
  1250. arg.Message = "自动FIB对焦失败";
  1251. arg.State = false;
  1252. SendMsg("1-10");
  1253. return false;
  1254. }
  1255. //判断是否停止进程
  1256. if (key_stop)
  1257. {
  1258. return false;
  1259. }
  1260. //拍照前改变速度,延时
  1261. iSEM.CmdSaveRate();
  1262. cycle_time = iSEM.GetCycleTime();
  1263. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1264. if (!GetImage(ImageMode.FIB, fileName2))
  1265. {
  1266. arg.Message = "FIB拍照失败";
  1267. arg.State = false;
  1268. SendMsg("1-11");
  1269. return false;
  1270. }
  1271. arg.State = true;
  1272. arg.Message = "FIB拍照成功";
  1273. SendMsg("1-11");
  1274. iSEM.CmdFocusRate();
  1275. cycle_time = iSEM.GetCycleTime();
  1276. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1277. //判断是否停止进程
  1278. if (key_stop)
  1279. {
  1280. return false;
  1281. }
  1282. //10.将照片传给客户,返回梯形位置坐标,及样品类型参数(是否需要PT沉积,PT坐标位置,PT宽度、PT高度、梯形上、下边及深度、扫描时间、束流、样品放大倍数1、样品放大倍数2等切割参数)
  1283. LogManager.AddHardwareLog("准备移动样品台", true);
  1284. LogManager.AddHardwareLog("文件名="+fileName2, true);
  1285. LogManager.AddHardwareLog("样品类型="+m_MsParam.SampleName, true);
  1286. LogManager.AddHardwareLog("供应商名称="+m_MsParam.Firm, true);
  1287. wr.Img_Cut_Position(fileName2, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out x1, out y1, out x2, out y2, out state);
  1288. LogManager.AddHardwareLog("FIB梯形左上角和右上角位置信息= " + x1.ToString() + ", " + y1.ToString() + ", " + x2.ToString() + ", " + y2.ToString(), true);
  1289. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1290. if (state == 1)
  1291. {
  1292. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1293. float xc = (x1 + x2) / 2;
  1294. float yc = (y1 + y2) / 2;
  1295. if (!MoveToPix(xc,yc))
  1296. {
  1297. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置失败";
  1298. arg.State = false;
  1299. SendMsg("1-12");
  1300. return false;
  1301. }
  1302. arg.Message = "移动到新(" + x1.ToString() + "," + y1.ToString() + ")位置成功";
  1303. arg.State = true;
  1304. SendMsg("1-12");
  1305. if (hand_intervene == 1)
  1306. {
  1307. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1308. }
  1309. }
  1310. else
  1311. {
  1312. arg.Message = "图像接口参数state返回值为零";
  1313. arg.State = false;
  1314. SendMsg("1-12");
  1315. if(hand_intervene==1)
  1316. {
  1317. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1318. {
  1319. return false;
  1320. }
  1321. }
  1322. else
  1323. {
  1324. return false;
  1325. }
  1326. }
  1327. //判断是否停止进程
  1328. if (key_stop)
  1329. {
  1330. return false;
  1331. }
  1332. //11.自动工具样品类型参数确定是否需要PT沉积
  1333. if (m_MsParam.PT)
  1334. {
  1335. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1336. //第10步已经移动好位置
  1337. //2. 验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否一定正确
  1338. //x0 = iSEM.GetStageAtX();
  1339. //y0 = iSEM.GetStageAtY();
  1340. //if (Math.Abs(x0 - x1) > fMin && Math.Abs(y0 - y1) > fMin)
  1341. //{
  1342. // arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动失败";
  1343. // arg.State = false;
  1344. // SendMsg("1-1");
  1345. // return false;
  1346. //}
  1347. //arg.State = true;
  1348. //arg.Message = "目标位置(" + x0.ToString() + "," + y0.ToString() + ")移动成功";
  1349. //SendMsg("1-8");
  1350. //判断是否停止进程
  1351. //if (key_stop)
  1352. //{
  1353. // return false;
  1354. //}
  1355. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  1356. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1357. {
  1358. if (!InsertPT())
  1359. {
  1360. arg.Message = "插入PT针失败";
  1361. arg.State = false;
  1362. SendMsg("1-13");
  1363. return false;
  1364. }
  1365. arg.State = true;
  1366. arg.Message = "插入PT针成功";
  1367. SendMsg("1-13");
  1368. }
  1369. //判断是否停止进程
  1370. if (key_stop)
  1371. {
  1372. return false;
  1373. }
  1374. //3. 根据坐标进行PT沉积
  1375. if (!PTWork())
  1376. {
  1377. arg.Message = "PT沉积失败";
  1378. arg.State = false;
  1379. SendMsg("1-14");
  1380. return false;
  1381. }
  1382. arg.State = true;
  1383. arg.Message = "PT沉积成功";
  1384. SendMsg("1-14");
  1385. //判断是否停止进程
  1386. if (key_stop)
  1387. {
  1388. return false;
  1389. }
  1390. //15.根据样品类型决定是否撤出PT针
  1391. if (m_MsParam.Is_Photograph == false && m_MsParam.PT == true)
  1392. {
  1393. if (!RetractPT())
  1394. {
  1395. arg.Message = "撤出PT针失败";
  1396. arg.State = false;
  1397. SendMsg("1-15");
  1398. return false;
  1399. }
  1400. arg.State = true;
  1401. arg.Message = "撤出PT针成功";
  1402. SendMsg("1-15");
  1403. }
  1404. //判断是否停止进程
  1405. if (key_stop)
  1406. {
  1407. return false;
  1408. }
  1409. }
  1410. }
  1411. //12.根据梯形坐标控制FIB调整到中心位置
  1412. //13.验证移动准确性:获取当前FIB中心位置坐标,与客户返回坐标对比,验证是否移动正确
  1413. //以上两步已经将程序移动到11内部去做
  1414. //14.保存样品1第1号孔中心位置6轴坐标1 XYZMRT到数据库,保存客户返回值信息到数据库
  1415. float[] firstPosition = iSEM.GetStagePosition();
  1416. m_cutHoles[0].Position.X = firstPosition[0];
  1417. m_cutHoles[0].Position.Y = firstPosition[1];
  1418. m_cutHoles[0].Position.Z = firstPosition[2];
  1419. m_cutHoles[0].Position.T = firstPosition[3];
  1420. m_cutHoles[0].Position.R = firstPosition[4];
  1421. m_cutHoles[0].Position.M = firstPosition[5];
  1422. //这里要调用文件保存功能
  1423. arg.Message = "坐标1(" + firstPosition[0].ToString() + ","
  1424. + firstPosition[1].ToString() + ","
  1425. + firstPosition[2].ToString() + ","
  1426. + firstPosition[3].ToString() + ","
  1427. + firstPosition[4].ToString() + ","
  1428. + firstPosition[5].ToString() + ")";
  1429. arg.State = true;
  1430. SendMsg("1-16");
  1431. //判断是否停止进程
  1432. if (key_stop)
  1433. {
  1434. return false;
  1435. }
  1436. return true;
  1437. }
  1438. /// <summary>
  1439. /// 14. FIB切割
  1440. /// </summary>
  1441. /// <returns></returns>
  1442. public bool FIBCross()
  1443. {
  1444. int state = 0;
  1445. //这里不知道PT沉积之后是否变回SEM,所以这里加一句切换到FIB命令
  1446. if (!iSEM.CmdFIBModeFIB())
  1447. {
  1448. return false;
  1449. }
  1450. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  1451. //增加FIB对焦
  1452. if (FIBFocus("1-17"))
  1453. {
  1454. arg.Message = "FIB自动对焦完成";
  1455. arg.State = true;
  1456. SendMsg("1-17");
  1457. }
  1458. else
  1459. {
  1460. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1461. arg.Message = "自动对焦失败";
  1462. arg.State = false;
  1463. SendMsg("1-17");
  1464. return false;
  1465. }
  1466. //判断是否停止进程
  1467. if (key_stop)
  1468. {
  1469. return false;
  1470. }
  1471. String fileName31 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName31;
  1472. arg.Picture_Information.Picture_FullPath = fileName31;
  1473. arg.Picture_Information.Work_Status = "FIB";
  1474. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1475. Thread.Sleep(1000);
  1476. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1477. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1478. Thread.Sleep(1000);
  1479. //拍照前改变速度,延时
  1480. iSEM.CmdSaveRate();
  1481. cycle_time = iSEM.GetCycleTime();
  1482. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1483. if (!GetImage(ImageMode.SEM, fileName31))
  1484. {
  1485. arg.Message = "FIB切割前拍照SEM模式照失败";
  1486. arg.State = false;
  1487. SendMsg("1-18");
  1488. return false;
  1489. }
  1490. arg.State = true;
  1491. arg.Message = "FIB切割前拍照SEM模式照成功";
  1492. SendMsg("1-18");
  1493. iSEM.CmdFocusRate();
  1494. cycle_time = iSEM.GetCycleTime();
  1495. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1496. //判断是否停止进程
  1497. if (key_stop)
  1498. {
  1499. return false;
  1500. }
  1501. //14.自动控制FIB切割
  1502. //1.根据参数设置FIB草率时间(使图清晰),设置梯形上下边及深度、设置束流
  1503. //2.控制FIB进行切割
  1504. //以上1、2步全部用ELY文件代替
  1505. if (!FIBWork())
  1506. {
  1507. arg.Message = "FIB切割失败";
  1508. arg.State = false;
  1509. SendMsg("1-19");
  1510. return false;
  1511. }
  1512. arg.State = true;
  1513. arg.Message = "FIB切割成功";
  1514. SendMsg("1-19");
  1515. Thread.Sleep(1000);
  1516. //判断是否停止进程
  1517. if (key_stop)
  1518. {
  1519. return false;
  1520. }
  1521. //切割后会切换到SEM,所以需要再切换回FIB模式
  1522. if (!iSEM.CmdFIBModeFIB())
  1523. {
  1524. return false;
  1525. }
  1526. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1527. //3.控制FIB拍照600X
  1528. //底层没有控制方法。
  1529. //4.保存图片
  1530. String fileName32 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.FIB_Magnification.ToString() + "_" + ImageName32;
  1531. arg.Picture_Information.Picture_FullPath = fileName32;
  1532. arg.Picture_Information.Work_Status = "FIB";
  1533. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1534. Thread.Sleep(1000);
  1535. arg.Picture_Information.Magnification = m_MsParam.FIB_Magnification;
  1536. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1537. Thread.Sleep(1000);
  1538. //增加FIB对焦
  1539. if (FIBFocus("1-20"))
  1540. {
  1541. arg.Message = "FIB自动对焦完成";
  1542. arg.State = true;
  1543. SendMsg("1-20");
  1544. }
  1545. else
  1546. {
  1547. LogManager.AddHardwareLog("设置观测点后,自动对焦失败。", true);
  1548. arg.Message = "自动对焦失败";
  1549. arg.State = false;
  1550. SendMsg("1-20");
  1551. return false;
  1552. }
  1553. //拍照前改变速度,延时
  1554. iSEM.CmdSaveRate();
  1555. cycle_time = iSEM.GetCycleTime();
  1556. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1557. if (!GetImage(ImageMode.FIB, fileName32))
  1558. {
  1559. arg.Message = "FIB切割后拍照失败";
  1560. arg.State = false;
  1561. SendMsg("1-21");
  1562. return false;
  1563. }
  1564. arg.State = true;
  1565. arg.Message = "FIB切割后拍照成功";
  1566. SendMsg("1-21");
  1567. iSEM.CmdFocusRate();
  1568. cycle_time = iSEM.GetCycleTime();
  1569. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1570. //判断是否停止进程
  1571. if (key_stop)
  1572. {
  1573. return false;
  1574. }
  1575. //5.验证切割准确性:与切割前对比,如果对比误差大,则停止自动执行,进行报警
  1576. wr.Img_Cut_Success(fileName31, fileName32, out state);
  1577. if(state == 0)
  1578. {
  1579. arg.Message = "图像接口参数state返回值为零";
  1580. arg.State = false;
  1581. SendMsg("1-22");
  1582. if (hand_intervene == 1)
  1583. {
  1584. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1585. {
  1586. return false;
  1587. }
  1588. }
  1589. else
  1590. {
  1591. return false;
  1592. }
  1593. }
  1594. arg.State = true;
  1595. arg.Message = "FIB切割校验成功";
  1596. SendMsg("1-22");
  1597. //判断是否停止进程
  1598. if (key_stop)
  1599. {
  1600. return false;
  1601. }
  1602. return true;
  1603. }
  1604. /// <summary>
  1605. /// 16.自动调整SEM找到切割位置,这里不是简单的拉直旋转
  1606. /// </summary>
  1607. /// <returns></returns>
  1608. public bool FindCross()
  1609. {
  1610. float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  1611. int state = 0;
  1612. //切换到SEM模式
  1613. if (!iSEM.CmdFIBModeSEM())
  1614. {
  1615. arg.Message = "SEM模式切换失败";
  1616. arg.State = false;
  1617. SendMsg("1-23");
  1618. return false;
  1619. }
  1620. arg.State = true;
  1621. arg.Message = "SEM模式切换成功";
  1622. SendMsg("1-23");
  1623. arg.Picture_Information.Work_Status = "SEM";
  1624. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1625. //判断是否停止进程
  1626. if (key_stop)
  1627. {
  1628. return false;
  1629. }
  1630. //1.控制SEM放大到300倍
  1631. if (!iSEM.SetSEMVoltage(m_MsParam.Location_Voltage))
  1632. {
  1633. arg.Message = "电压设置" + m_MsParam.Location_Voltage.ToString("0.0") + "失败";
  1634. arg.State = false;
  1635. SendMsg("1-24");
  1636. return false;
  1637. }
  1638. if (!iSEM.SetMagnification(m_measureFile.MParam.Location_Magnification/3))
  1639. {
  1640. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification / 3).ToString("0.0") + "倍失败";
  1641. arg.State = false;
  1642. SendMsg("1-24");
  1643. return false;
  1644. }
  1645. arg.State = true;
  1646. arg.Message = "放大" + (m_measureFile.MParam.Location_Magnification/3).ToString("0.0") + "倍成功";
  1647. SendMsg("1-24");
  1648. //判断是否停止进程
  1649. if (key_stop)
  1650. {
  1651. return false;
  1652. }
  1653. //3.控制SEM拍照
  1654. String fileName4 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + (m_MsParam.Location_Magnification/3).ToString("0") + "_" + ImageName4;
  1655. arg.Picture_Information.Picture_FullPath = fileName4;
  1656. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1657. Thread.Sleep(1000);
  1658. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1659. Thread.Sleep(1000);
  1660. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1661. Thread.Sleep(1000);
  1662. //拍照前改变速度,延时
  1663. iSEM.CmdSaveRate();
  1664. cycle_time = iSEM.GetCycleTime();
  1665. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1666. if (!GetImage(ImageMode.SEM, fileName4))
  1667. {
  1668. arg.State = false;
  1669. arg.Message = "SEM拍照失败";
  1670. SendMsg("1-25");
  1671. return false;
  1672. }
  1673. arg.State = true;
  1674. arg.Message = "SEM拍照成功";
  1675. SendMsg("1-25");
  1676. iSEM.CmdFocusRate();
  1677. cycle_time = iSEM.GetCycleTime();
  1678. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1679. //判断是否停止进程
  1680. if (key_stop)
  1681. {
  1682. return false;
  1683. }
  1684. //4.将照片传给客户,获取偏移坐标,以及偏移角度
  1685. //5.根据坐标控制SEM移动到切孔位置,居中
  1686. LogManager.AddHardwareLog("准备移动样品台", true);
  1687. LogManager.AddHardwareLog("文件名=" + fileName4, true);
  1688. wr.Img_Trapezoid_Top_Center_Position(fileName4,out x2, out y2, out state);
  1689. LogManager.AddHardwareLog("梯形中心点返回数据=" + x2.ToString() + ", " + y2.ToString(), true);
  1690. LogManager.AddHardwareLog("准备移动样品台返回状态=" + state.ToString(), true);
  1691. if (state == 1)
  1692. {
  1693. //1. 根据客户PT沉积坐标控制FIB调整到中心位置???????
  1694. if (!MoveToPix(x2, y2))
  1695. {
  1696. arg.State = false;
  1697. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1698. SendMsg("1-26");
  1699. return false;
  1700. }
  1701. //判断是否移动完成
  1702. while (true)
  1703. {
  1704. Thread.Sleep(5000);
  1705. if (iSEM.GetStageIs() == 0)
  1706. {
  1707. break;
  1708. }
  1709. }
  1710. arg.State = true;
  1711. arg.Message = "移动到新(" + x2.ToString() + "," + y2.ToString() + ")位置失败";
  1712. SendMsg("1-26");
  1713. if (hand_intervene == 1)
  1714. {
  1715. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1716. }
  1717. }
  1718. else
  1719. {
  1720. arg.Message = "图像接口参数state返回值为零";
  1721. arg.State = false;
  1722. SendMsg("1-26");
  1723. if (hand_intervene == 1)
  1724. {
  1725. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1726. {
  1727. return false;
  1728. }
  1729. }
  1730. else
  1731. {
  1732. return false;
  1733. }
  1734. }
  1735. //判断是否停止进程
  1736. if (key_stop)
  1737. {
  1738. return false;
  1739. }
  1740. return true;
  1741. }
  1742. /// <summary>
  1743. /// 17.自动控制SEM拍截面照
  1744. /// </summary>
  1745. /// <returns></returns>
  1746. public bool ShotSection(ref String image18)
  1747. {
  1748. float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
  1749. int state = 0;
  1750. //1、放大6000倍,放大倍数参数photograph_
  1751. if (!iSEM.SetSEMVoltage(m_MsParam.Photograph_Voltage))
  1752. {
  1753. arg.Message = "电压设置" + m_MsParam.Photograph_Voltage.ToString("0.0") + "失败";
  1754. arg.State = false;
  1755. SendMsg("1-27");
  1756. return false;
  1757. }
  1758. if (!iSEM.SetMagnification(m_MsParam.Photograph_Magnification))
  1759. {
  1760. arg.Message = "放大倍数调整失败";
  1761. arg.State = false;
  1762. SendMsg("1-27");
  1763. return false;
  1764. }
  1765. arg.Message = "放大倍数调整成功";
  1766. arg.State = true;
  1767. SendMsg("1-27");
  1768. //判断是否停止进程
  1769. if (key_stop)
  1770. {
  1771. return false;
  1772. }
  1773. //2.控制SEM自动对焦、亮度、对比度-接口
  1774. if (ImageFocus("1-28"))
  1775. {
  1776. arg.Message = "自动对焦完成";
  1777. arg.State = true;
  1778. SendMsg("1-28");
  1779. }
  1780. else
  1781. {
  1782. arg.Message = "自动对焦失败";
  1783. arg.State = false;
  1784. SendMsg("1-28");
  1785. return false;
  1786. }
  1787. //判断是否停止进程
  1788. if (key_stop)
  1789. {
  1790. return false;
  1791. }
  1792. //1.1大于10000倍进行消像散处理
  1793. float dMag = iSEM.GetMagnification();
  1794. if (dMag > 10000)//需要消像散
  1795. {
  1796. if (!ImageStig("1-28"))
  1797. {
  1798. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1799. arg.Message = "拉直操作自动消像散失败!";
  1800. arg.State = false;
  1801. SendMsg("1-28");
  1802. return false;
  1803. }
  1804. arg.Message = "拉直操作自动消像散成功!";
  1805. arg.State = true;
  1806. SendMsg("1-28");
  1807. }
  1808. //3、设置SEM补偿角度
  1809. if (m_MsParam.Is_Photograph == false)
  1810. {
  1811. if (!TiltCorrection(m_measureFile.MParam.Correction_Angle))
  1812. {
  1813. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度失败";
  1814. arg.State = false;
  1815. SendMsg("1-29");
  1816. return false;
  1817. }
  1818. arg.State = true;
  1819. arg.Message = "设置SEM进行角度补偿" + m_measureFile.MParam.Correction_Angle.ToString("0") + "度成功";
  1820. SendMsg("1-29");
  1821. Thread.Sleep(2000);
  1822. //判断是否停止进程
  1823. if (key_stop)
  1824. {
  1825. return false;
  1826. }
  1827. }
  1828. //4、拍照,5、保存照片
  1829. String fileName5 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName5;
  1830. arg.Picture_Information.Picture_FullPath = fileName5;
  1831. arg.Picture_Information.Work_Status = "SEM";
  1832. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1833. Thread.Sleep(1000);
  1834. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1835. Thread.Sleep(1000);
  1836. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1837. Thread.Sleep(1000);
  1838. //拍照前改变速度,延时
  1839. iSEM.CmdSaveRate();
  1840. cycle_time = iSEM.GetCycleTime();
  1841. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1842. if (!GetImage(ImageMode.SEM, fileName5))
  1843. {
  1844. arg.Message = "SEM拍照失败";
  1845. arg.State = false;
  1846. SendMsg("1-30");
  1847. return false;
  1848. }
  1849. arg.State = true;
  1850. arg.Message = "SEM拍照成功";
  1851. SendMsg("1-30");
  1852. iSEM.CmdFocusRate();
  1853. cycle_time = iSEM.GetCycleTime();
  1854. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1855. //判断是否停止进程
  1856. if (key_stop)
  1857. {
  1858. return false;
  1859. }
  1860. if (m_MsParam.Is_Photograph == false)
  1861. {
  1862. //8,计算切割面区域偏移角度及方向
  1863. float degree = 0;
  1864. int direction = 0;
  1865. wr.Img_Center_Position_OffsetAngle_Direction(fileName5, out degree, out direction, out state);
  1866. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "计算切割面区域的角度=" + degree.ToString(), true);
  1867. //接口返回像素,*pixelsize,得到坐标点。判断移动方式
  1868. if (state == 1)
  1869. {
  1870. //梯形角度
  1871. iSEM.SetScanRotationOn();
  1872. Thread.Sleep(1000);
  1873. iSEM.SetScanRotation(degree);
  1874. Thread.Sleep(1000);
  1875. arg.State = true;
  1876. arg.Message = "图像接口返回角度为:" + degree.ToString();
  1877. SendMsg("1-31");
  1878. if (hand_intervene == 1)
  1879. {
  1880. MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  1881. }
  1882. }
  1883. else
  1884. {
  1885. arg.Message = "图像接口参数State返回值为零";
  1886. arg.State = false;
  1887. SendMsg("1-31");
  1888. if(hand_intervene == 1)
  1889. {
  1890. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  1891. {
  1892. return false;
  1893. }
  1894. }
  1895. else
  1896. {
  1897. return false;
  1898. }
  1899. }
  1900. //判断是否停止进程
  1901. if (key_stop)
  1902. {
  1903. return false;
  1904. }
  1905. //11、自动对焦。与之前操作相同
  1906. if (ImageFocus("1-32"))
  1907. {
  1908. arg.Message = "自动对焦完成";
  1909. arg.State = true;
  1910. SendMsg("1-32");
  1911. }
  1912. else
  1913. {
  1914. arg.Message = "自动对焦失败";
  1915. arg.State = false;
  1916. SendMsg("1-32");
  1917. return false;
  1918. }
  1919. //判断是否停止进程
  1920. if (key_stop)
  1921. {
  1922. return false;
  1923. }
  1924. //1.1大于10000倍进行消像散处理
  1925. dMag = iSEM.GetMagnification();
  1926. if (dMag > 10000)//需要消像散
  1927. {
  1928. if (!ImageStig("1-32"))
  1929. {
  1930. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  1931. arg.Message = "拉直操作自动消像散失败!";
  1932. arg.State = false;
  1933. SendMsg("1-32");
  1934. return false;
  1935. }
  1936. arg.Message = "拉直操作自动消像散成功!";
  1937. arg.State = true;
  1938. SendMsg("1-32");
  1939. }
  1940. //12拍照
  1941. String fileName6 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Photograph_Magnification.ToString("0") + "_" + ImageName6;
  1942. arg.Picture_Information.Picture_FullPath = fileName6;
  1943. arg.Picture_Information.Work_Status = "SEM";
  1944. arg.Picture_Information.Work_Voltage = iSEM.GetSEMVoltage();
  1945. Thread.Sleep(1000);
  1946. arg.Picture_Information.Magnification = iSEM.GetMagnification();
  1947. Thread.Sleep(1000);
  1948. arg.Picture_Information.Work_Distance = iSEM.GetWorkingDistance();
  1949. Thread.Sleep(1000);
  1950. //拍照前改变速度,延时
  1951. iSEM.CmdSaveRate();
  1952. cycle_time = iSEM.GetCycleTime();
  1953. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1954. if (!GetImage(ImageMode.SEM, fileName6))
  1955. {
  1956. arg.Message = "SEM拍照失败";
  1957. arg.State = false;
  1958. SendMsg("1-33");
  1959. return false;
  1960. }
  1961. arg.State = true;
  1962. image18 = fileName6;
  1963. arg.Message = "SEM拍照成功";
  1964. SendMsg("1-33");
  1965. iSEM.CmdFocusRate();
  1966. cycle_time = iSEM.GetCycleTime();
  1967. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  1968. //判断是否停止进程
  1969. if (key_stop)
  1970. {
  1971. return false;
  1972. }
  1973. //华为程序还没有做出来
  1974. }
  1975. //14光束复位和Rotation关闭开关
  1976. arg.Message = "光束复位成功";
  1977. arg.State = true;
  1978. SendMsg("1-36");
  1979. iSEM.SetTiltAngleOff();
  1980. Thread.Sleep(1000);
  1981. iSEM.SetScanRotationOff();
  1982. Thread.Sleep(1000);
  1983. iSEM.SetBeamShiftX(0);
  1984. Thread.Sleep(1000);
  1985. iSEM.SetBeamShiftY(0);
  1986. Thread.Sleep(3000);
  1987. //判断是否停止进程
  1988. if (key_stop)
  1989. {
  1990. return false;
  1991. }
  1992. return true;
  1993. }
  1994. //第一个孔的测试过程
  1995. public bool FirstHole()
  1996. {
  1997. MeasureData.CutHole firstHole = m_cutHoles[0];
  1998. //设置拉直的放大倍数
  1999. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2000. {
  2001. arg.Message = "拉直放大倍数设置失败!";
  2002. arg.State = false;
  2003. SendMsg("1-0");
  2004. return false;
  2005. }
  2006. arg.Message = "拉直放大倍数设置成功!";
  2007. arg.State = true;
  2008. SendMsg("1-0");
  2009. Thread.Sleep(1000);
  2010. //自动化流程-每个点都需要补偿54度
  2011. if (m_MsParam.Is_Photograph == false)
  2012. {
  2013. if (!TiltCorrection(54.0f))
  2014. {
  2015. arg.Message = "角度补偿54度失败!";
  2016. arg.State = false;
  2017. SendMsg("1-1");
  2018. return false;
  2019. }
  2020. Thread.Sleep(2000);
  2021. arg.Message = "角度补偿54度成功!";
  2022. arg.State = true;
  2023. SendMsg("1-1");
  2024. //判断是否停止进程
  2025. if (key_stop)
  2026. {
  2027. return false;
  2028. }
  2029. }
  2030. //2、拉直操作
  2031. if (!Straighten_Handle())
  2032. {
  2033. LogManager.AddHardwareLog("拉直操作失败。", true);
  2034. return false;
  2035. }
  2036. //判断是否停止进程
  2037. if (key_stop)
  2038. {
  2039. return false;
  2040. }
  2041. //13. 自动 定位功能
  2042. if (!GetPoistion())
  2043. {
  2044. LogManager.AddHardwareLog("自动定位失败,程序退出。", true);
  2045. return false;
  2046. }
  2047. //判断是否停止进程
  2048. if (key_stop)
  2049. {
  2050. return false;
  2051. }
  2052. //14.自动控制FIB切割
  2053. if (m_MsParam.Is_Photograph == false)
  2054. {
  2055. if (!FIBCross())
  2056. {
  2057. return false;
  2058. }
  2059. }
  2060. //判断是否停止进程
  2061. if (key_stop)
  2062. {
  2063. return false;
  2064. }
  2065. //16.找到切割位置
  2066. if (m_MsParam.Is_Photograph == false)
  2067. {
  2068. if (!FindCross())
  2069. {
  2070. return false;
  2071. }
  2072. //判断是否停止进程
  2073. if (key_stop)
  2074. {
  2075. return false;
  2076. }
  2077. }
  2078. //将过程17最后的拍照图片提出给18步进行调用
  2079. String img18 = "";
  2080. //17.自动控制SEM拍截面照
  2081. if (!ShotSection(ref img18))
  2082. {
  2083. return false;
  2084. }
  2085. //判断是否停止进程
  2086. if (key_stop)
  2087. {
  2088. return false;
  2089. }
  2090. //18.自动层高分析
  2091. if (m_MsParam.Is_Photograph == false)
  2092. {
  2093. float size = iSEM.GetPixelSize();
  2094. float mag = iSEM.GetMagnification();
  2095. int state = 1;
  2096. //wr.Img_Measure_Size(img18, mag, size, out state);
  2097. if (state == 0)
  2098. {
  2099. arg.Message = "测量尺寸失败";
  2100. arg.State = false;
  2101. SendMsg("1-40");
  2102. return false;
  2103. }
  2104. arg.State = true;
  2105. arg.Message = "测量尺寸成功";
  2106. SendMsg("1-40");
  2107. }
  2108. #region 测试程序
  2109. //最后保存测量数据-测量文件、测量状态,m_cutHoles[i].STATE!=MeasureData.CutHole.State.Success.
  2110. //中间停止更新状态为Unmeasured,过程中return false时,更新状态为failed,保存测量文件
  2111. //if (DialogResult.Yes == MessageBox.Show("图像拍摄已完成?", "确认消息", MessageBoxButtons.YesNo))
  2112. //{
  2113. // SendMsg("拍摄照片完成");
  2114. // //return true;
  2115. //}
  2116. //else
  2117. //{
  2118. // SendMsg("拍摄照片失败");
  2119. // return false;
  2120. //}
  2121. //SendMsg("图像校正36度");
  2122. ////3.设置SEM角度补偿cos36度
  2123. //if (!TiltCorrection(36))
  2124. //{
  2125. // return false;
  2126. //}
  2127. //Thread.Sleep(3000);
  2128. //string fn;
  2129. //用宏抓一般图
  2130. //Thread.Sleep(5000);
  2131. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2132. //SendMsg("用宏抓一般图" + fn);
  2133. //iSEM.CMDMCFFilename(fn);
  2134. ////延时1s??
  2135. //Thread.Sleep(5000);
  2136. ////用宏抓好图
  2137. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2138. //SendMsg("用宏抓好图" + fn);
  2139. //iSEM.CMDMCFFilename(fn);
  2140. ////延时1s??
  2141. //Thread.Sleep(30000);
  2142. //Thread.Sleep(10000);
  2143. //WorkingFolder = m_measureFile.FilePath;
  2144. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2145. //SendMsg("SEM拍照存储到" + fileName6);
  2146. //if (!GetImage(ImageMode.SEM, fileName6))
  2147. //{
  2148. // SendMsg("SEM拍照失败");
  2149. // return false;
  2150. //}
  2151. ////用宏抓标志图
  2152. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2153. //SendMsg("用宏抓标志图" + fn);
  2154. //iSEM.CMDMCFFilename(fn);
  2155. ////延时1s??
  2156. //Thread.Sleep(30000);
  2157. //Thread.Sleep(5000);
  2158. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2159. //SendMsg("用宏抓一般图" + fn);
  2160. //iSEM.CMDMCFFilename(fn);
  2161. ////延时1s??
  2162. //Thread.Sleep(5000);
  2163. //SendMsg("所有图结束");
  2164. ////17.自动控制SEM拍截面照
  2165. //{
  2166. // //1.控制SEM放大到指定参数大小范围,6000x
  2167. // if (!iSEM.SetMagnification(6000))
  2168. // {
  2169. // return false;
  2170. // }
  2171. // //2.控制SEM自动对焦、消像散、亮度、对比度
  2172. // if (!MeasParam.FocusMode)
  2173. // {
  2174. // //弹出手动对焦的窗口
  2175. // }
  2176. // else
  2177. // {
  2178. // //调用自动对焦模块
  2179. // }
  2180. // //3.设置SEM角度补偿cos36度
  2181. // if (!TiltCorrection(36))
  2182. // {
  2183. // return false;
  2184. // }
  2185. // //4.控制SEM拍照
  2186. // //5.保存照片4
  2187. // String fileName5 = WorkingFolder + ImageName5;
  2188. // if (!GetImage(ImageMode.SEM, fileName5))
  2189. // {
  2190. // return false;
  2191. // }
  2192. // //6.将照片传给客户,获取偏移坐标
  2193. // float x6 = 0, y6 = 0;
  2194. // float angle1 = 0;
  2195. // float mage = 10000;
  2196. // //7.根据坐标控制SEM移动到分析位置
  2197. // if (!iSEM.MoveStageXY(x6, y6))
  2198. // {
  2199. // return false;
  2200. // }
  2201. // //8.验证移动准确性:获取当前SEM中心位置坐标,与客户返回坐标对比,验证是否移动正确
  2202. // float x7 = iSEM.GetStageAtX();
  2203. // float y7 = iSEM.GetStageAtY();
  2204. // if (Math.Abs(x6 - x7) > fMin && Math.Abs(y6 - y7) > fMin)
  2205. // {
  2206. // return false;
  2207. // }
  2208. // //9.控制SEM平行校正,并记录校正前初始值
  2209. // float foldAnagle = iSEM.GetScanRotation();
  2210. // if (foldAnagle == float.NaN)
  2211. // {
  2212. // return false;
  2213. // }
  2214. // if (!iSEM.SetScanRotation(angle1))
  2215. // {
  2216. // return false;
  2217. // }
  2218. // //10.控制SEM放大到指定参数大小范围
  2219. // if (!iSEM.SetMagnification(mage))
  2220. // {
  2221. // return false;
  2222. // }
  2223. // //11.控制SEM自动对焦、消像散、亮度、对比度
  2224. // if (!MeasParam.FocusMode)
  2225. // {
  2226. // //弹出手动对焦的窗口
  2227. // }
  2228. // else
  2229. // {
  2230. // //调用自动对焦模块
  2231. // }
  2232. // //12.控制SEM对分析位置拍照
  2233. // String fileName6 = WorkingFolder + ImageName6;
  2234. // if (!GetImage(ImageMode.SEM, fileName6))
  2235. // {
  2236. // return false;
  2237. // }
  2238. // //13.保存照片
  2239. // //14.控制SEM取消电子束校正,回到初始值
  2240. // if (!iSEM.SetScanRotation(foldAnagle))
  2241. // {
  2242. // return false;
  2243. // }
  2244. //}
  2245. ////18.自动层高分析
  2246. //{
  2247. // //1.获取SEM Pixel Size给客户传入参数
  2248. // if (iSEM.GetPixelSize() == float.NaN)
  2249. // {
  2250. // return false;
  2251. // }
  2252. // //2.将照片传给客户,客户进行层高分析(返回分析后的图像、相对坐标、分辨率、各层编号以及各层对应的层高数据),如果客户自行出分析报告则无需返回数据
  2253. //}
  2254. ////19.自动能谱分析
  2255. //{
  2256. // //1. 确定能谱位置
  2257. // //2. 控制牛津打能谱
  2258. // //3. 能谱分析——面扫+线扫描
  2259. //}
  2260. #endregion
  2261. return true;
  2262. }
  2263. //非第一个孔的测试过程
  2264. public bool OtherHole()
  2265. {
  2266. //设置拉直的放大倍数
  2267. if (!iSEM.SetMagnification(m_measureFile.MParam.Stretch_Magnification))
  2268. {
  2269. LogManager.AddHardwareLog("拉直放大倍数设置失败,程序退出。", true);
  2270. arg.Message = "拉直放大倍数设置失败!";
  2271. arg.State = false;
  2272. SendMsg("1-0");
  2273. return false;
  2274. }
  2275. arg.Message = "拉直放大倍数设置成功!";
  2276. arg.State = true;
  2277. SendMsg("1-0");
  2278. Thread.Sleep(1000);
  2279. //自动化流程-每个点都需要补偿54度
  2280. if (m_MsParam.Is_Photograph == false)
  2281. {
  2282. if (!TiltCorrection(54.0f))
  2283. {
  2284. arg.Message = "角度补偿54度失败!";
  2285. arg.State = false;
  2286. SendMsg("1-1");
  2287. return false;
  2288. }
  2289. arg.Message = "角度补偿54度成功!";
  2290. arg.State = true;
  2291. SendMsg("1-1");
  2292. Thread.Sleep(2000);
  2293. //判断是否停止进程
  2294. if (key_stop)
  2295. {
  2296. return false;
  2297. }
  2298. }
  2299. //拉直操作
  2300. if (!Straighten_Handle())
  2301. {
  2302. return false;
  2303. }
  2304. //判断是否停止进程
  2305. if (key_stop)
  2306. {
  2307. return false;
  2308. }
  2309. //13. 自动 定位功能
  2310. if (!GetPoistion())
  2311. {
  2312. return false;
  2313. }
  2314. //判断是否停止进程
  2315. if (key_stop)
  2316. {
  2317. return false;
  2318. }
  2319. //14.自动控制FIB切割
  2320. if (m_MsParam.Is_Photograph == false)
  2321. {
  2322. if (!FIBCross())
  2323. {
  2324. return false;
  2325. }
  2326. }
  2327. //判断是否停止进程
  2328. if (key_stop)
  2329. {
  2330. return false;
  2331. }
  2332. // 16.找到切割位置
  2333. if (m_MsParam.Is_Photograph == false)
  2334. {
  2335. if (!FindCross())
  2336. {
  2337. return false;
  2338. }
  2339. //判断是否停止进程
  2340. if (key_stop)
  2341. {
  2342. return false;
  2343. }
  2344. }
  2345. //将过程17最后的拍照图片提出给18步进行调用
  2346. String img18 = "";
  2347. //17.自动控制SEM拍截面照
  2348. if (!ShotSection(ref img18))
  2349. {
  2350. return false;
  2351. }
  2352. //判断是否停止进程
  2353. if (key_stop)
  2354. {
  2355. return false;
  2356. }
  2357. //18.自动层高分析
  2358. if (m_MsParam.Is_Photograph == false)
  2359. {
  2360. float size = iSEM.GetPixelSize();
  2361. float mag = iSEM.GetMagnification();
  2362. int state = 1;
  2363. //wr.Img_Measure_Size(img18, mag, size, out state);
  2364. if (state == 0)
  2365. {
  2366. arg.Message = "测量尺寸失败";
  2367. SendMsg("1-40");
  2368. return false;
  2369. }
  2370. arg.Message = "测量尺寸成功";
  2371. SendMsg("1-40");
  2372. }
  2373. #region 测试程序
  2374. //string fn;
  2375. //用宏抓一般图
  2376. //Thread.Sleep(5000);
  2377. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2378. //SendMsg("用宏抓一般图" + fn);
  2379. //iSEM.CMDMCFFilename(fn);
  2380. ////延时1s??
  2381. //Thread.Sleep(5000);
  2382. ////用宏抓好图
  2383. //fn = m_ProgramFolder + "\\Macro\\" + MacoGoodPic;
  2384. //SendMsg("用宏抓好图" + fn);
  2385. //iSEM.CMDMCFFilename(fn);
  2386. ////延时1s??
  2387. //Thread.Sleep(30000);
  2388. //Thread.Sleep(10000);
  2389. //WorkingFolder = m_measureFile.FilePath;
  2390. //String fileName6 = WorkingFolder + "\\" + m_nWorkHoleNo.ToString() + "Hole" + ImageName6;
  2391. //SendMsg("SEM拍照存储到" + fileName6);
  2392. //if (!GetImage(ImageMode.SEM, fileName6))
  2393. //{
  2394. // SendMsg("SEM拍照失败");
  2395. // return false;
  2396. //}
  2397. ////用宏抓标志图
  2398. //fn = m_ProgramFolder + "\\Macro\\" + MacoExportTif;
  2399. //SendMsg("用宏抓标志图" + fn);
  2400. //iSEM.CMDMCFFilename(fn);
  2401. ////延时1s??
  2402. //Thread.Sleep(30000);
  2403. ////恢复简单抓图
  2404. //Thread.Sleep(5000);
  2405. //fn = m_ProgramFolder + "\\Macro\\" + MacoScanPic;
  2406. //SendMsg("用宏抓一般图" + fn);
  2407. //iSEM.CMDMCFFilename(fn);
  2408. //SendMsg("所有图结束");
  2409. #endregion
  2410. return true;
  2411. }
  2412. //测试完第一个孔后的样品台初始化操作。
  2413. //再调用CommonWork执行非第一个孔的测试过程
  2414. public bool OtherHole_Init()
  2415. {
  2416. CutHole currentHole = m_cutHoles[m_nWorkHoleNo];
  2417. #region 初始化
  2418. //1、不只拍照,且不是倾斜观测,则移动T轴
  2419. if (m_MsParam.Is_Photograph == false && m_MsParam.Title == false)
  2420. {
  2421. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2422. if (!iSEM.SetStageGotoT(0))
  2423. {
  2424. return false;
  2425. }
  2426. while (true)
  2427. {
  2428. Thread.Sleep(5000);
  2429. if (iSEM.GetStageIs() == 0)
  2430. {
  2431. break;
  2432. }
  2433. }
  2434. //判断是否停止进程
  2435. if (key_stop)
  2436. {
  2437. return false;
  2438. }
  2439. }
  2440. //2、如果是倾斜观测,则移动Z轴
  2441. if(m_MsParam.Title==true)
  2442. {
  2443. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2444. if (!iSEM.SetStageGotoZ(currentHole.Position.Z - m_MsParam.ZDistance/1000))
  2445. {
  2446. return false;
  2447. }
  2448. while (true)
  2449. {
  2450. Thread.Sleep(5000);
  2451. if (iSEM.GetStageIs() == 0)
  2452. {
  2453. break;
  2454. }
  2455. }
  2456. //判断是否停止进程
  2457. if (key_stop)
  2458. {
  2459. return false;
  2460. }
  2461. }
  2462. //3. 根据光镜坐标控制样品台移动
  2463. if (!iSEM.SetStageGotoR(currentHole.Position.R))
  2464. {
  2465. //SendMsg("移动失败");
  2466. return false;
  2467. }
  2468. LogManager.AddHardwareLog("移动R轴到="+ currentHole.Position.R.ToString(), true);
  2469. while (true)
  2470. {
  2471. Thread.Sleep(5000);
  2472. if (iSEM.GetStageIs() == 0)
  2473. {
  2474. break;
  2475. }
  2476. }
  2477. //判断是否停止进程
  2478. if (key_stop)
  2479. {
  2480. return false;
  2481. }
  2482. if(!iSEM.MoveStageXY(currentHole.Position.X, currentHole.Position.Y))
  2483. {
  2484. //SendMsg("移动失败");
  2485. return false;
  2486. }
  2487. LogManager.AddHardwareLog("移动X轴Y轴=" + currentHole.Position.X.ToString() + " " + currentHole.Position.Y.ToString(), true);
  2488. while (true)
  2489. {
  2490. Thread.Sleep(10000);
  2491. if (iSEM.GetStageIs() == 0)
  2492. {
  2493. break;
  2494. }
  2495. }
  2496. //判断是否停止进程
  2497. if (key_stop)
  2498. {
  2499. return false;
  2500. }
  2501. //4、倾斜观测时恢复Z轴
  2502. if (m_MsParam.Title == true)
  2503. {
  2504. //4. 控制样品台T轴归0,R轴变为坐标1、Z/M轴作为坐标2保存不变
  2505. if (!iSEM.SetStageGotoZ(currentHole.Position.Z))
  2506. {
  2507. return false;
  2508. }
  2509. while (true)
  2510. {
  2511. Thread.Sleep(5000);
  2512. if (iSEM.GetStageIs() == 0)
  2513. {
  2514. break;
  2515. }
  2516. }
  2517. //判断是否停止进程
  2518. if (key_stop)
  2519. {
  2520. return false;
  2521. }
  2522. }
  2523. //5. 控制样品台,调整T轴54度、M/Z/R轴不变
  2524. if (m_MsParam.Is_Photograph == false)
  2525. {
  2526. if (!iSEM.SetStageGotoT(54))
  2527. {
  2528. return false;
  2529. }
  2530. while (true)
  2531. {
  2532. Thread.Sleep(5000);
  2533. if (iSEM.GetStageIs() == 0)
  2534. {
  2535. break;
  2536. }
  2537. }
  2538. }
  2539. //判断是否停止进程
  2540. if (key_stop)
  2541. {
  2542. return false;
  2543. }
  2544. #endregion
  2545. return true;
  2546. }
  2547. //初始化拉直操作
  2548. public bool Straighten_Handle()
  2549. {
  2550. //1、自动对焦
  2551. if (!ImageFocus("1-2"))
  2552. {
  2553. LogManager.AddHardwareLog("拉直操作自动对焦失败,程序退出。", true);
  2554. arg.Message = "拉直操作自动对焦失败!";
  2555. arg.State = false;
  2556. SendMsg("1-2");
  2557. return false;
  2558. }
  2559. arg.Message = "拉直操作自动对焦成功!";
  2560. arg.State = true;
  2561. SendMsg("1-2");
  2562. //判断是否停止进程
  2563. if (key_stop)
  2564. {
  2565. return false;
  2566. }
  2567. //1.1大于10000倍进行消像散处理
  2568. float dMag = iSEM.GetMagnification();
  2569. if (dMag > 10000)//需要消像散
  2570. {
  2571. if (!ImageStig("1-2"))
  2572. {
  2573. LogManager.AddHardwareLog("拉直操作消像散失败,程序退出。", true);
  2574. arg.Message = "拉直操作自动消像散失败!";
  2575. arg.State = false;
  2576. SendMsg("1-2");
  2577. return false;
  2578. }
  2579. arg.Message = "拉直操作自动消像散成功!";
  2580. arg.State = true;
  2581. SendMsg("1-2");
  2582. }
  2583. //2、拍张照片
  2584. String fileName0 = data_path + "\\" + m_cutHoles[m_nWorkHoleNo].HoleName + "_" + m_MsParam.Stretch_Magnification.ToString("0") + "_" + ImageName0;
  2585. //拍照前改变速度,延时
  2586. iSEM.CmdSaveRate();
  2587. cycle_time = iSEM.GetCycleTime();
  2588. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2589. if (!GetImage(ImageMode.SEM, fileName0))
  2590. {
  2591. arg.Message = "拉直拍照成功";
  2592. arg.State = false;
  2593. SendMsg("1-3");
  2594. return false;
  2595. }
  2596. arg.Message = "拉直拍照成功!";
  2597. arg.State = true;
  2598. SendMsg("1-3");
  2599. iSEM.CmdFocusRate();
  2600. cycle_time = iSEM.GetCycleTime();
  2601. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2602. //3、华为接口,获取旋转角度
  2603. float degree = 0;
  2604. int direction = 0;
  2605. int state = 1;
  2606. wr.Img_OffsetAngle_Direction(fileName0, Convert.ToInt32(m_MsParam.SampleName), m_MsParam.Firm, out degree, out direction, out state);
  2607. LogManager.AddHardwareLog("样品" + m_nWorkHoleNo.ToString() + "初始化拉直角度=" + degree.ToString(), true);
  2608. if (state == 0)
  2609. {
  2610. arg.Message = "华为接口参数state返回为零";
  2611. arg.State = false;
  2612. SendMsg("1-4");
  2613. if (hand_intervene == 1)
  2614. {
  2615. if (DialogResult.Yes != MessageBox.Show("网络参数State返回为0。\n是否继续操作?。", "确认消息", MessageBoxButtons.YesNo))
  2616. {
  2617. return false;
  2618. }
  2619. }
  2620. else
  2621. {
  2622. return false;
  2623. }
  2624. }
  2625. if (direction == 2)
  2626. {
  2627. degree = -degree;
  2628. }
  2629. #region//暂时不用这个拉直
  2630. //旋转R轴
  2631. //float getr = iSEM.GetStageAtR();
  2632. //getr = getr + degree;
  2633. //if(getr>R_Max)
  2634. //{
  2635. // getr = getr - 360;
  2636. //}
  2637. //if(getr<R_Min)
  2638. //{
  2639. // getr = getr + 360;
  2640. //}
  2641. //iSEM.SetStageGotoR(getr);
  2642. //while (true)
  2643. //{
  2644. // Thread.Sleep(5000);
  2645. // if (iSEM.GetStageIs() == 0)
  2646. // {
  2647. // break;
  2648. // }
  2649. //}
  2650. //MessageBox.Show("Web返回数据移动是否正确?\n如果错误请手动移动到指定位置后按确认", "确认消息", MessageBoxButtons.OK);
  2651. //////3、拉直
  2652. //float x0 = iSEM.GetStageAtX();
  2653. //float y0 = iSEM.GetStageAtY();
  2654. //float x1 = 0, y1 = 0;
  2655. //Straightening(degree, x_center_point, y_center_point, x0, y0, ref x1, ref y1);
  2656. //if (x1 < X_Min || x1 > X_Max || y1 < Y_Min || y1 > Y_Max)
  2657. //{
  2658. // return false;
  2659. //}
  2660. //iSEM.MoveStageXY(x1, y1);
  2661. #endregion
  2662. //4、拉直,旋转R轴
  2663. iSEM.SetStageDeltaR(degree);
  2664. while (true)
  2665. {
  2666. Thread.Sleep(5000);
  2667. if (iSEM.GetStageIs() == 0)
  2668. {
  2669. break;
  2670. }
  2671. }
  2672. arg.Message = "拉直操作完成";
  2673. arg.State = true;
  2674. SendMsg("1-4");
  2675. //华为接口,去掉人工干预
  2676. //MessageBox.Show("拉直操作完成,如果不正确请手动进行拉直然后点击OK按钮。", "确认消息", MessageBoxButtons.OK);
  2677. return true;
  2678. }
  2679. //角度补偿
  2680. public bool TiltCorrection(float a_fAngle)
  2681. {
  2682. if (!iSEM.SetTiltAngleOn())
  2683. {
  2684. return false;
  2685. }
  2686. //恢复原始状态
  2687. if (!iSEM.SetTiltAngle(a_fAngle))
  2688. {
  2689. return false;
  2690. }
  2691. return true;
  2692. }
  2693. //拍图
  2694. public bool GetImage(ImageMode a_mode, String a_fileName)
  2695. {
  2696. //3. 获取分辨率
  2697. int[] ImageSize = iSEM.GetImageStore();
  2698. if (ImageSize[0] == 0 || ImageSize[1] == 0)
  2699. {
  2700. return false;
  2701. }
  2702. short width = (short)ImageSize[0];
  2703. short height = (short)ImageSize[1];
  2704. //4. 抓图
  2705. if (!iSEM.GrabImage(a_fileName, 0, 0, width, height, 0))
  2706. {
  2707. return false;
  2708. }
  2709. return true;
  2710. }
  2711. //自动聚焦
  2712. public bool AutoFocus(FocusParam a_param, out int a_nWd, String step_code)
  2713. {
  2714. a_nWd = 0;
  2715. float wd = iSEM.GetWorkingDistance();
  2716. a_nWd = (int)Math.Ceiling(wd * 100000000 + 0.5);//获取当前的工作距离
  2717. if (a_param == null)
  2718. {
  2719. LogManager.AddHardwareLog("空参数", true);
  2720. return false;
  2721. }
  2722. string path = a_param.Path;
  2723. if (!Directory.Exists(path))
  2724. {
  2725. LogManager.AddHardwareLog("文件夹丢失", true);
  2726. return false;
  2727. }
  2728. string path_coarse = a_param.Path + "\\Coarse";
  2729. if (!Directory.Exists(path_coarse))
  2730. {
  2731. Directory.CreateDirectory(path_coarse);
  2732. }
  2733. string path_fine = a_param.Path + "\\Fine";
  2734. if (!Directory.Exists(path_fine))
  2735. {
  2736. Directory.CreateDirectory(path_fine);
  2737. }
  2738. //1. 拍照
  2739. //1.1, 粗拍照
  2740. //1.1.1, 根据参数计算拍照次数
  2741. double nUp = a_param.UP * 100.0 ;
  2742. double nDown = a_param.Down * 100.0;
  2743. double nStep = a_param.Step * 100.0;
  2744. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2745. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2746. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2747. //粗拍照
  2748. for (int i = 0; i < nTimes; i++)
  2749. {
  2750. int cWd =(int) Math.Ceiling(nUp + i * nStep + 0.5);
  2751. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2752. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2753. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2754. int swd = cWd / 100;
  2755. //SendMsg("wd = " + swd.ToString() +"um");
  2756. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2757. arg.Picture_Information.Picture_FullPath = fileName;
  2758. if (!GetImage(ImageMode.SEM, fileName))
  2759. {
  2760. return false;
  2761. }
  2762. arg.State = true;
  2763. arg.Message = "自动对焦";
  2764. SendMsg(step_code);
  2765. //判断是否停止进程
  2766. if (key_stop)
  2767. {
  2768. return false;
  2769. }
  2770. //Thread.Sleep(3000);
  2771. }
  2772. //1.2, 选定细拍照的工作距离
  2773. int CorWd;
  2774. ChooseBest(path_coarse,out CorWd);
  2775. a_nWd = CorWd;
  2776. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2777. //1.3, 细拍照
  2778. if ( (CorWd - a_param.Range * 100.0) <=0)
  2779. {
  2780. return false;
  2781. }
  2782. double nfUp = CorWd - a_param.Range * 100.0;
  2783. double nfStep = a_param.fStep * 100.0;
  2784. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2785. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2786. for (int i = 0; i < nfTimes; i++)
  2787. {
  2788. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2789. iSEM.SetWorkingDistance((float)(cWd * 0.00000001));
  2790. arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2791. Thread.Sleep(Convert.ToInt32(cycle_time)+1000);
  2792. int swd = cWd / 100;
  2793. //SendMsg("wd = " + swd.ToString() + "um");
  2794. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2795. arg.Picture_Information.Picture_FullPath = fileName;
  2796. if (!GetImage(ImageMode.SEM, fileName))
  2797. {
  2798. return false;
  2799. }
  2800. arg.State = true;
  2801. arg.Message = "自动对焦";
  2802. SendMsg(step_code);
  2803. //判断是否停止进程
  2804. if (key_stop)
  2805. {
  2806. return false;
  2807. }
  2808. //Thread.Sleep(2000);
  2809. }
  2810. int fineWd;
  2811. ChooseBest(path_fine, out fineWd);
  2812. //SendMsg("wd fine max = " + fineWd.ToString());
  2813. a_nWd = fineWd;
  2814. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2815. return true;
  2816. }
  2817. //自动消像散 AutoStig
  2818. public bool AutoStig(FocusParam a_param, out int a_nWd, String step_code)
  2819. {
  2820. a_nWd = 0;
  2821. float wd = 0;
  2822. if (a_param.TYPE == 2)
  2823. {
  2824. wd = iSEM.GetAstigmatismX();
  2825. }
  2826. else if (a_param.TYPE == 3)
  2827. {
  2828. wd = iSEM.GetAstigmatismY();
  2829. }
  2830. else
  2831. {
  2832. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2833. return false;
  2834. }
  2835. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2836. if (a_param == null)
  2837. {
  2838. LogManager.AddHardwareLog("空参数", true);
  2839. return false;
  2840. }
  2841. string path = a_param.Path;
  2842. if (!Directory.Exists(path))
  2843. {
  2844. LogManager.AddHardwareLog("文件夹丢失", true);
  2845. return false;
  2846. }
  2847. string path_coarse = a_param.Path + "\\Coarse";
  2848. if (!Directory.Exists(path_coarse))
  2849. {
  2850. Directory.CreateDirectory(path_coarse);
  2851. }
  2852. string path_fine = a_param.Path + "\\Fine";
  2853. if (!Directory.Exists(path_fine))
  2854. {
  2855. Directory.CreateDirectory(path_fine);
  2856. }
  2857. //1. 拍照
  2858. //1.1, 粗拍照
  2859. //1.1.1, 根据参数计算拍照次数
  2860. double nUp = a_param.UP * 100.0;
  2861. double nDown = a_param.Down * 100.0;
  2862. double nStep = a_param.Step * 100.0;
  2863. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  2864. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  2865. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  2866. //粗拍照
  2867. for (int i = 0; i < nTimes; i++)
  2868. {
  2869. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  2870. if (a_param.TYPE == 2)
  2871. {
  2872. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2873. }
  2874. else if (a_param.TYPE == 3)
  2875. {
  2876. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2877. }
  2878. else
  2879. {
  2880. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2881. return false;
  2882. }
  2883. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2884. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2885. int swd = cWd / 100;
  2886. //SendMsg("wd = " + swd.ToString() +"um");
  2887. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  2888. arg.Picture_Information.Picture_FullPath = fileName;
  2889. if (!GetImage(ImageMode.SEM, fileName))
  2890. {
  2891. return false;
  2892. }
  2893. arg.State = true;
  2894. arg.Message = "自动像散";
  2895. SendMsg(step_code);
  2896. //判断是否停止进程
  2897. if (key_stop)
  2898. {
  2899. return false;
  2900. }
  2901. //Thread.Sleep(3000);
  2902. }
  2903. //1.2, 选定细拍照的工作距离
  2904. int CorWd;
  2905. ChooseBest(path_coarse, out CorWd);
  2906. a_nWd = CorWd;
  2907. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  2908. //1.3, 细拍照
  2909. if ((CorWd - a_param.Range * 100.0) <= -10000)
  2910. {
  2911. return false;
  2912. }
  2913. double nfUp = CorWd - a_param.Range * 100.0;
  2914. double nfStep = a_param.fStep * 100.0;
  2915. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  2916. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  2917. for (int i = 0; i < nfTimes; i++)
  2918. {
  2919. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  2920. if (a_param.TYPE == 2)
  2921. {
  2922. iSEM.SetAstigmatismX((float)(cWd * 0.01));
  2923. }
  2924. else if (a_param.TYPE == 3)
  2925. {
  2926. iSEM.SetAstigmatismY((float)(cWd * 0.01));
  2927. }
  2928. else
  2929. {
  2930. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  2931. return false;
  2932. }
  2933. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  2934. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  2935. int swd = cWd / 100;
  2936. //SendMsg("wd = " + swd.ToString() + "um");
  2937. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  2938. arg.Picture_Information.Picture_FullPath = fileName;
  2939. if (!GetImage(ImageMode.SEM, fileName))
  2940. {
  2941. return false;
  2942. }
  2943. arg.State = true;
  2944. arg.Message = "自动像散";
  2945. SendMsg(step_code);
  2946. //判断是否停止进程
  2947. if (key_stop)
  2948. {
  2949. return false;
  2950. }
  2951. //Thread.Sleep(2000);
  2952. }
  2953. int fineWd;
  2954. ChooseBest(path_fine, out fineWd);
  2955. //SendMsg("wd fine max = " + fineWd.ToString());
  2956. a_nWd = fineWd;
  2957. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  2958. return true;
  2959. }
  2960. //自动FIB对焦 AutoFIBFocus
  2961. public bool AutoFIBFocus(FocusParam a_param, out int a_nWd, String step_code)
  2962. {
  2963. a_nWd = 0;
  2964. float wd = 0;
  2965. if (a_param.TYPE == 4)
  2966. {
  2967. wd = iSEM.GetFIBObjectivePotential();
  2968. }
  2969. else
  2970. {
  2971. LogManager.AddHardwareLog("FIB自动聚焦参数设置有误", true);
  2972. return false;
  2973. }
  2974. a_nWd = (int)Math.Ceiling(wd * 100 + 0.5);//获取当前的工作距离
  2975. if (a_param == null)
  2976. {
  2977. LogManager.AddHardwareLog("空参数", true);
  2978. return false;
  2979. }
  2980. string path = a_param.Path;
  2981. if (!Directory.Exists(path))
  2982. {
  2983. LogManager.AddHardwareLog("文件夹丢失", true);
  2984. return false;
  2985. }
  2986. string path_coarse = a_param.Path + "\\Coarse";
  2987. if (!Directory.Exists(path_coarse))
  2988. {
  2989. Directory.CreateDirectory(path_coarse);
  2990. }
  2991. string path_fine = a_param.Path + "\\Fine";
  2992. if (!Directory.Exists(path_fine))
  2993. {
  2994. Directory.CreateDirectory(path_fine);
  2995. }
  2996. //1. 拍照
  2997. //1.1, 粗拍照
  2998. //1.1.1, 根据参数计算拍照次数
  2999. double nUp = a_param.UP * 100.0;
  3000. double nDown = a_param.Down * 100.0;
  3001. double nStep = a_param.Step * 100.0;
  3002. double nTimes = Math.Ceiling((nDown - nUp) / nStep + 0.5);
  3003. LogManager.AddHardwareLog("初调拍照次数=" + nTimes.ToString(), true);
  3004. //SendMsg("粗对焦:最小值" + nUp.ToString() + ",最大值" + nDown.ToString() + ",步长" + nStep.ToString() + "拍照张数" + nTimes.ToString());
  3005. //粗拍照
  3006. for (int i = 0; i < nTimes; i++)
  3007. {
  3008. int cWd = (int)Math.Ceiling(nUp + i * nStep + 0.5);
  3009. if (a_param.TYPE == 4)
  3010. {
  3011. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3012. }
  3013. else
  3014. {
  3015. LogManager.AddHardwareLog("FIB对焦参数设置有误,对焦类型错", true);
  3016. return false;
  3017. }
  3018. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3019. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3020. int swd = cWd / 100;
  3021. //SendMsg("wd = " + swd.ToString() +"um");
  3022. String fileName = path_coarse + "\\" + cWd.ToString() + ".tif";
  3023. arg.Picture_Information.Picture_FullPath = fileName;
  3024. if (!GetImage(ImageMode.SEM, fileName))
  3025. {
  3026. return false;
  3027. }
  3028. arg.State = true;
  3029. arg.Message = "FIB自动对焦";
  3030. SendMsg(step_code);
  3031. //判断是否停止进程
  3032. if (key_stop)
  3033. {
  3034. return false;
  3035. }
  3036. //Thread.Sleep(3000);
  3037. }
  3038. //1.2, 选定细拍照的工作距离
  3039. int CorWd;
  3040. ChooseBest(path_coarse, out CorWd);
  3041. a_nWd = CorWd;
  3042. //SendMsg("粗选工作距离wd = " + a_nWd.ToString() );
  3043. //1.3, 细拍照
  3044. if ((CorWd - a_param.Range * 100.0) <0)
  3045. {
  3046. return false;
  3047. }
  3048. double nfUp = CorWd - a_param.Range * 100.0;
  3049. double nfStep = a_param.fStep * 100.0;
  3050. double nfTimes = Math.Ceiling((a_param.Range * 100.0 * 2) / nfStep + 0.5);
  3051. //SendMsg("粗对焦:最小值" + nfUp.ToString() + ",步长" + nfStep.ToString() + "拍照张数" + nfTimes.ToString());
  3052. for (int i = 0; i < nfTimes; i++)
  3053. {
  3054. int cWd = (int)Math.Ceiling(nfUp + i * nfStep + 0.5);
  3055. if (a_param.TYPE == 4)
  3056. {
  3057. iSEM.SetFIBObjectivePotential((float)(cWd * 0.01));
  3058. }
  3059. else
  3060. {
  3061. LogManager.AddHardwareLog("自动消像散参数设置有误", true);
  3062. return false;
  3063. }
  3064. //arg.Picture_Information.Work_Distance = (float)(cWd * 0.00000001);
  3065. Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
  3066. int swd = cWd / 100;
  3067. //SendMsg("wd = " + swd.ToString() + "um");
  3068. String fileName = path_fine + "\\" + cWd.ToString() + ".tif";
  3069. arg.Picture_Information.Picture_FullPath = fileName;
  3070. if (!GetImage(ImageMode.SEM, fileName))
  3071. {
  3072. return false;
  3073. }
  3074. arg.State = true;
  3075. arg.Message = "FIB自动对焦";
  3076. SendMsg(step_code);
  3077. //判断是否停止进程
  3078. if (key_stop)
  3079. {
  3080. return false;
  3081. }
  3082. //Thread.Sleep(2000);
  3083. }
  3084. int fineWd;
  3085. ChooseBest(path_fine, out fineWd);
  3086. //SendMsg("wd fine max = " + fineWd.ToString());
  3087. a_nWd = fineWd;
  3088. //SendMsg("细选工作距离wd = " + a_nWd.ToString());
  3089. return true;
  3090. }
  3091. //LoG算子计算
  3092. private double LoGMean(string a_strImgPath)
  3093. {
  3094. //读入Img文件
  3095. if (!File.Exists(a_strImgPath))
  3096. {
  3097. return 0;
  3098. }
  3099. Mat src, gray_src;
  3100. int kernel_size = 3;
  3101. src = Cv2.ImRead(a_strImgPath);
  3102. gray_src = new Mat();
  3103. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3104. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3105. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3106. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3107. Cv2.Laplacian(src, src, MatType.CV_8UC3, kernel_size);
  3108. Cv2.ConvertScaleAbs(src, src);
  3109. //图像的平均灰度
  3110. double meanValue = 0.0;
  3111. meanValue = Cv2.Mean(src)[0];
  3112. return meanValue;
  3113. }
  3114. //梯度计算
  3115. private double Tenengrad(string a_strImgPath)
  3116. {
  3117. //读入Img文件
  3118. if (!File.Exists(a_strImgPath))
  3119. {
  3120. return 0;
  3121. }
  3122. Mat src;
  3123. src = Cv2.ImRead(a_strImgPath);
  3124. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3125. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3126. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3127. Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
  3128. Cv2.Sobel(src, src, MatType.CV_8UC1, 1, 1);
  3129. //图像的平均灰度
  3130. double meanValue = 0.0;
  3131. meanValue = Cv2.Mean(src)[0];
  3132. return meanValue;
  3133. }
  3134. //梯度计算
  3135. private double TTgrad(string a_strImgPath)
  3136. {
  3137. //读入Img文件
  3138. if (!File.Exists(a_strImgPath))
  3139. {
  3140. return 0;
  3141. }
  3142. Mat src;
  3143. src = Cv2.ImRead(a_strImgPath);
  3144. src.CvtColor(ColorConversionCodes.BGR2GRAY);
  3145. Mat kernel = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(10, 10));
  3146. Cv2.MorphologyEx(src, src, MorphTypes.Close, kernel);
  3147. Mat scalex = new Mat();
  3148. Mat scaley = new Mat();
  3149. Cv2.Scharr(src, src, src.Depth(), 1, 0);
  3150. Cv2.ConvertScaleAbs(src, scalex);
  3151. Cv2.Scharr(src, src, src.Depth(), 0, 1);
  3152. Cv2.ConvertScaleAbs(src, scaley);
  3153. Cv2.AddWeighted(scalex, 0.5, scaley, 0.5, 0, src);
  3154. //图像的平均灰度
  3155. double meanValue = 0.0;
  3156. meanValue = Cv2.Mean(src)[0];
  3157. return meanValue;
  3158. }
  3159. //三选二算法
  3160. private void ChooseBest(string a_strImgPath, out int a_nWd)
  3161. {
  3162. a_nWd = -1;
  3163. var files = Directory.GetFiles(a_strImgPath, "*.tif");
  3164. float[] values = new float[files.Length];
  3165. double smax1 = LoGMean(files[0]);
  3166. int wdmax1 = int.Parse(System.IO.Path.GetFileNameWithoutExtension(files[0]));
  3167. double smax2 = Tenengrad(files[0]);
  3168. int wdmax2 = wdmax1;
  3169. double smax3 = TTgrad(files[0]);
  3170. int wdmax3 = wdmax1;
  3171. int x = 0;
  3172. foreach (var file in files)
  3173. {
  3174. int wd = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file));
  3175. double svalue1 = LoGMean(file);
  3176. double svalue2 = Tenengrad(file);
  3177. double svalue3 = TTgrad(file);
  3178. if (smax1 < svalue1)
  3179. {
  3180. smax1 = svalue1;
  3181. wdmax1 = wd;
  3182. }
  3183. if (smax2 < svalue2)
  3184. {
  3185. smax2 = svalue2;
  3186. wdmax2 = wd;
  3187. }
  3188. if (smax3 < svalue3)
  3189. {
  3190. smax3 = svalue3;
  3191. wdmax3 = wd;
  3192. }
  3193. x++;
  3194. }
  3195. //SendMsg("LoG = " + wdmax1.ToString() + ",梯度 = " + wdmax2.ToString() + ",滤波 = " + wdmax3.ToString());
  3196. if (wdmax1 == wdmax2 || wdmax1 == wdmax3)
  3197. {
  3198. a_nWd = wdmax1;
  3199. //SendMsg("焦距 = " + wdmax1.ToString());
  3200. }
  3201. else if (wdmax1 == wdmax2 || wdmax2 == wdmax3)
  3202. {
  3203. a_nWd = wdmax2;
  3204. //SendMsg("焦距 = " + wdmax2.ToString());
  3205. }
  3206. else if (wdmax3 == wdmax2 || wdmax1 == wdmax3)
  3207. {
  3208. a_nWd = wdmax3;
  3209. //SendMsg("焦距 = " + wdmax3.ToString());
  3210. }
  3211. else
  3212. {
  3213. //SendMsg("对焦失败。");
  3214. }
  3215. }
  3216. //移动到像素位置
  3217. bool MoveToPix(float xc, float yc)
  3218. {
  3219. float pixSize = iSEM.GetPixelSize();
  3220. Thread.Sleep(500);
  3221. //0:width, 1:height
  3222. int[] imageSize = iSEM.GetImageStore();
  3223. int width = imageSize[0]/2;
  3224. int height = imageSize[1]/2;
  3225. float deltX = (xc - (float)width) * pixSize;
  3226. float deltY = (yc - (float)height) * pixSize;
  3227. float xpCur = iSEM.GetStageAtX();
  3228. float ypCur = iSEM.GetStageAtY();
  3229. float xpNew = xpCur - deltX;
  3230. float ypNew = ypCur - deltY;
  3231. LogManager.AddHardwareLog("样品台移动信息:deltx=" + deltX.ToString() +
  3232. ",delty=" + deltY.ToString() + ",xpNew=" + xpNew.ToString() + ",ypNew=" + ypNew.ToString(), true);
  3233. if (deltX > 10)//使用移动样品台实现
  3234. {
  3235. if (!iSEM.SetStageGotoX(xpNew))
  3236. {
  3237. return false;
  3238. }
  3239. //判断是否移动完成
  3240. while (true)
  3241. {
  3242. Thread.Sleep(5000);
  3243. if (iSEM.GetStageIs() == 0)
  3244. {
  3245. break;
  3246. }
  3247. }
  3248. //arg.Message = "移动到新x" + xpNew.ToString() + "位置失败";
  3249. //arg.State = true;
  3250. //SendMsg("1-7");
  3251. }
  3252. else//使用移动光束实现
  3253. {
  3254. float beamX = deltX * (float)0.66;
  3255. if (!iSEM.SetBeamShiftX(beamX))
  3256. {
  3257. return false;
  3258. }
  3259. }
  3260. if (deltY > 10)//使用移动样品台实现
  3261. {
  3262. if (!iSEM.SetStageGotoY(ypNew))
  3263. {
  3264. return false;
  3265. }
  3266. //判断是否移动完成
  3267. while (true)
  3268. {
  3269. Thread.Sleep(5000);
  3270. if (iSEM.GetStageIs() == 0)
  3271. {
  3272. break;
  3273. }
  3274. }
  3275. }
  3276. else//使用移动光束实现
  3277. {
  3278. float beamY = deltY * (float)0.671;
  3279. if (!iSEM.SetBeamShiftY(beamY))
  3280. {
  3281. return false;
  3282. }
  3283. }
  3284. return true;
  3285. }
  3286. }
  3287. }