PTWork.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9. namespace MeasureThread
  10. {
  11. class PTWork
  12. {
  13. NLog.Logger log;
  14. SmartSEMControl.ISEMControl iSEM;
  15. string PTTemp;
  16. private string m_ProgramFolder = Directory.GetCurrentDirectory();
  17. const String MacoInsertPt = "GIS Insert.MLF"; //传入PT针
  18. const String MacoRetractPt = "GIS Retract.MLF"; //退出PT针
  19. public PTWork(SmartSEMControl.ISEMControl aSEM, string a_PTTemp)
  20. {
  21. log = NLog.LogManager.GetCurrentClassLogger();
  22. iSEM = aSEM;
  23. PTTemp = a_PTTemp;
  24. }
  25. public bool DoWholePTWork()
  26. {
  27. if (!iSEM.CmdFIBModeFIB())
  28. {
  29. log.Error("测量线程报错:切换到SEM模式失败", false);
  30. return false;
  31. }
  32. Thread.Sleep(200);
  33. //12.根据样品类型参数确定是否需要PT沉积,控制PT针插入
  34. log.Info("测量线程:插入PT针", true);
  35. if (!InsertPT())
  36. {
  37. log.Error("测量线程报错:插入PT针失败", false);
  38. return false;
  39. }
  40. Thread.Sleep(200);
  41. //3. 根据坐标进行PT沉积
  42. log.Info("测量线程: 进行PT沉积");
  43. if (!DoPTWork())
  44. {
  45. log.Error("测量线程报错: PT沉积失败");
  46. return false;
  47. }
  48. Thread.Sleep(200);
  49. log.Info ("测量线程:撤出PT针", false);
  50. if (!RetractPT())
  51. {
  52. log.Error("测量线程报错:撤出PT针失败", false);
  53. return false;
  54. }
  55. Thread.Sleep(200);
  56. if (!iSEM.CmdFIBModeSEM())
  57. {
  58. log.Error("测量线程报错:切换到SEM模式失败", false);
  59. return false;
  60. }
  61. Thread.Sleep(200);
  62. return true;
  63. }
  64. public bool ModifyPTTemp(float x1,float y1,float x2,float y2)
  65. {
  66. var px = iSEM.GetPixelSize();
  67. float x0 = 0, y0 = 0;
  68. float xc = (x1 + x2) / 2;
  69. float yc = (y1 + y2) / 2;
  70. x0 = xc - 512;
  71. y0 = 384 - yc;
  72. var xmlDoc = new XmlDocument();
  73. xmlDoc.Load(PTTemp);//加载baixml文件,xmlpath 为XML文件的路径du
  74. var xns = xmlDoc.SelectSingleNode("ELAYOUT/STRUCTURE_LIST/STRUCTURE/LAYER_REFERENCE/RECT");
  75. if (xns != null)
  76. {
  77. XmlAttributeCollection attributeCol = xns.Attributes;
  78. double width = Convert.ToDouble(attributeCol.GetNamedItem("width").Value) / 2.0;
  79. //因为ELY文件里的矩形高就是负值,所以在下面的Y值加上这个值就好。
  80. double height = Convert.ToDouble(attributeCol.GetNamedItem("height").Value) / 1.5;
  81. //遍历自己点属性
  82. foreach (XmlAttribute attri in attributeCol)
  83. {
  84. if (attri.Name == "x")
  85. {
  86. attri.InnerText = ((x0 * px) * 1000000 - width).ToString();
  87. }
  88. else if (attri.Name == "y")
  89. {
  90. attri.InnerText = ((y0 * px) * 1000000 - 2.791 - height).ToString();
  91. }
  92. }
  93. }
  94. xmlDoc.Save(PTTemp);
  95. return true;
  96. }
  97. //插入PT针
  98. public bool InsertPT()
  99. {
  100. string fn = m_ProgramFolder + "\\Macro\\" + MacoInsertPt;
  101. iSEM.CMDMCFFilename(fn);
  102. Thread.Sleep(1000);
  103. return true;
  104. }
  105. //撤出PT针
  106. public bool RetractPT()
  107. {
  108. string fn = m_ProgramFolder + "\\Macro\\" + MacoRetractPt;
  109. //SendMsg("调用宏撤出PT针宏文件" + fn);
  110. iSEM.CMDMCFFilename(fn);
  111. //延时1s??
  112. Thread.Sleep(1000);
  113. return true;
  114. }
  115. //PT沉积
  116. public bool DoPTWork()
  117. {
  118. //执行PT沉积的ELY文件
  119. if (!ExcuteEly(PTTemp))
  120. {
  121. return false;
  122. }
  123. //等待沉积完成
  124. while (true)
  125. {
  126. Thread.Sleep(7000);
  127. if (iSEM.GetFIBMode() == 0)
  128. {
  129. break;
  130. }
  131. }
  132. return true;
  133. }
  134. //执行ELY文件的步骤
  135. public bool ExcuteEly(string a_filename)
  136. {
  137. //执行ELy文件有三个动作
  138. //1. 选择ELY文件
  139. //SendMsg("选择ELY文件");
  140. if (!iSEM.CmdFIBLoadELY(a_filename))
  141. {
  142. //SendMsg("选择ELY文件失败");
  143. return false;
  144. }
  145. Thread.Sleep(1000);
  146. //2. 确认ELY文件
  147. //SendMsg("确认ELY文件");
  148. if (!iSEM.CmdFIBEXPOSUREELY())
  149. {
  150. //SendMsg("确认ELY文件失败");
  151. return false;
  152. }
  153. Thread.Sleep(1000);
  154. //3. 执行ELY文件
  155. //SendMsg("执行ELY文件");
  156. if (!iSEM.CmdFIBSTARTELY())
  157. {
  158. //SendMsg("执行ELY文件失败");
  159. return false;
  160. }
  161. Thread.Sleep(1000);
  162. return true;
  163. }
  164. }
  165. }