Measure.cs 125 KB

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