Measure.cs 123 KB

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