Measure.cs 127 KB

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