OTSBSEImageFun.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using OTSCLRINTERFACE;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using OTSModelSharp.ServiceInterface;
  9. using OTSDataType;
  10. namespace OTSMeasureApp
  11. {
  12. public class OTSBSEImageFun
  13. {
  14. //OTSIncAMeasureAppForm m_MsrApp = null;
  15. NLog.Logger log ;
  16. CImageHandler imageHandle;
  17. public OTSBSEImageFun()
  18. {
  19. log = NLog.LogManager.GetCurrentClassLogger();
  20. imageHandle = new CImageHandler();
  21. }
  22. public bool GetBSEImage(COTSImageProcParam ImgProcPrm,double pixelSize, byte[] BSEImage, int iHeight, int iWidth, ref byte[] BSEImageNoBG)
  23. {
  24. return imageHandle.GetBSEImage(ImgProcPrm,pixelSize, BSEImage, iHeight, iWidth,ref BSEImageNoBG);
  25. }
  26. public bool GetBSEImage(byte[] BSEImage, int iHeight, int iWidth, int grayStart, int grayEnd, ref byte[] BSEImageNoBG)
  27. {
  28. return imageHandle.GetBSEImage(BSEImage, iHeight, iWidth, grayStart, grayEnd,ref BSEImageNoBG);
  29. }
  30. public int GetScanImage(int iWidth, int iHeigh, int iDwellTime, ref byte[] bImageData)
  31. {
  32. if (FileHelper.GetXMLInformations("SemControllerName") == "FEI")
  33. {
  34. ScanController m_ScanHardwareMgr = ScanController.GetScanController();
  35. m_ScanHardwareMgr.Init();
  36. m_ScanHardwareMgr.SetImageSize(iWidth, iHeigh);
  37. bImageData = m_ScanHardwareMgr.AcquireBSEImage(0, 0, iDwellTime).GetImageDataPtr();
  38. return 1;
  39. }
  40. else
  41. {
  42. //电镜设置对象
  43. COTSControlFunExport cfun = COTSControlFunExport.GetControllerInstance();
  44. int GetImgCount = 0;
  45. try
  46. {
  47. //连接电镜
  48. bool IsConnec = cfun.ConncetSem();
  49. if (!IsConnec)
  50. {
  51. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ConncetSem() = false Failed";
  52. log.Error(strErrorInfo);
  53. return 0;
  54. }
  55. //实例电镜初始化
  56. bool IsScan = cfun.ScanInit();
  57. if (!IsScan)
  58. {
  59. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ScanInit = false Failed";
  60. log.Error(strErrorInfo);
  61. return 0;
  62. }
  63. int a_ExternalMode = 0;
  64. //获取终止模式
  65. a_ExternalMode = cfun.GetSemExternalMode();
  66. //保存初始模式变量
  67. int a_oldMode = 0;
  68. //获取初始模式
  69. if (!cfun.GetSemScanMode(ref a_oldMode))
  70. {
  71. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemScanMode = false Failed";
  72. log.Error(strErrorInfo);
  73. return 0;
  74. }
  75. //设置当前模式
  76. if (!cfun.SetSemScanMode(a_ExternalMode))
  77. {
  78. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetSemScanMode = false Failed";
  79. log.Error(strErrorInfo);
  80. return 0;
  81. }
  82. #region BeamBlank
  83. int a_nBeamBlank = 0;
  84. //获取参数
  85. if (!cfun.GetSemBeamBlank(ref a_nBeamBlank))
  86. {
  87. cfun.SetSemScanMode(a_oldMode);
  88. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemBeamBlank = false Failed";
  89. log.Error(strErrorInfo);
  90. return 0;
  91. }
  92. //设置参数
  93. if (!cfun.SetSemBeamBlank(false))
  94. {
  95. cfun.SetSemScanMode(a_oldMode);
  96. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetSemBeamBlank = false Failed";
  97. log.Error(strErrorInfo);
  98. return 0;
  99. }
  100. #endregion
  101. #region 获得放大倍数
  102. //获得放大倍数
  103. double a_dMagnification = 0;
  104. //获取参数
  105. if (!cfun.GetSemMagnification(ref a_dMagnification))
  106. {
  107. cfun.SetSemScanMode(a_oldMode);
  108. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemMagnification = false Failed";
  109. log.Error(strErrorInfo);
  110. return 0;
  111. }
  112. #endregion
  113. #region 获取 电镜 X、Y轴 与角度
  114. //获取 电镜 X、Y轴 与角度
  115. double PositionX = 0;
  116. double PositionY = 0;
  117. double PositionR = 0;
  118. //获取参数
  119. if (!cfun.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR))
  120. {
  121. cfun.SetSemScanMode(a_oldMode);
  122. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.GetSemPositionXY = false Failed";
  123. log.Error(strErrorInfo);
  124. return 0;
  125. }
  126. #endregion
  127. #region 设置图像分辨率
  128. //设置宽度
  129. if (!cfun.SetImageSize(iWidth, iHeigh))
  130. {
  131. cfun.SetSemScanMode(a_oldMode);
  132. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetImageSize = false Failed";
  133. log.Error(strErrorInfo);
  134. return 0;
  135. }
  136. #endregion
  137. #region 采集时间
  138. //采集时间
  139. int nDwellTime = 4;
  140. if (!cfun.SetDwellTime(nDwellTime))
  141. {
  142. cfun.SetSemScanMode(a_oldMode);
  143. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.SetDwellTime = false Failed";
  144. log.Error(strErrorInfo);
  145. return 0;
  146. }
  147. #endregion
  148. #region MatrixSize
  149. //获得放大倍数
  150. int a_MatrixSize = 0;
  151. Size size = new Size();
  152. //获取参数
  153. size = cfun.GetMatrixSize(a_MatrixSize);
  154. size = cfun.GetMatrixSize(a_MatrixSize);
  155. #endregion
  156. //获取图像数据
  157. int resultCount = iWidth * iHeigh;
  158. GetImgCount = cfun.AcquireBSEImage(0, 0, 0, ref bImageData);
  159. //记录日志
  160. if (resultCount == GetImgCount)
  161. {
  162. //设置为原始 扫描模式
  163. cfun.SetSemScanMode(a_oldMode);
  164. }
  165. else
  166. {
  167. cfun.SetSemScanMode(a_oldMode);
  168. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.AcquireBSEImage = 0 Failed";
  169. log.Error(strErrorInfo);
  170. }
  171. }
  172. catch (Exception ex)
  173. {
  174. //记录日志
  175. log.Error(ex.Message.ToString());
  176. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) Exception Error Happend";
  177. log.Error(strErrorInfo);
  178. }
  179. return GetImgCount;
  180. }
  181. }
  182. }
  183. }