Measure.cs 124 KB

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