FEIScanController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using FEIApiControl;
  2. using OTSCLRINTERFACE;
  3. using OTSModelSharp.ServiceCenter;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace OTSMeasureApp.ServiceCenter
  11. {
  12. class FEIScanController : IScanController
  13. {
  14. int imageWidth = 0;
  15. int imageHeight = 0;
  16. double dwelltime = 0;
  17. private APIClass ApiClass = null;
  18. public FEIScanController()
  19. {
  20. ApiClass = FEISemController.GetApiClassInstance();
  21. }
  22. public CBSEImgClr AcquireBSEImage()
  23. {
  24. Rectangle r = new Rectangle();
  25. CBSEImgClr bse = new CBSEImgClr(r);
  26. bse.InitImageData(imageWidth, imageHeight);
  27. byte[] imgData = new byte[imageWidth * imageHeight];
  28. if (!ApiClass.RunAcquireImage(imageWidth, imageHeight, dwelltime, "", ref imgData))
  29. {
  30. return null;
  31. }
  32. bse.SetImageData(imgData, imageWidth, imageHeight);
  33. return bse;
  34. }
  35. public CBSEImgClr AcquireRectangleBSEImage(System.Drawing.Rectangle rec)
  36. {
  37. int fieldWidth = 3072;
  38. int fieldHeight = 2048;
  39. //Rectangle r = new Rectangle();
  40. //double curwidth=0, curheight=0;
  41. //ApiClass.GetCurrentResolution(ref curwidth, ref curheight);
  42. double mag =0;
  43. CBSEImgClr bse = new CBSEImgClr(rec);
  44. //bse.InitImageDa/*t*/a(imageWidth, imageHeight);
  45. byte[] imgData= new byte[0];
  46. //double mag=0;
  47. if (!ApiClass.RunAcquireImageRect(fieldWidth, fieldHeight, rec,ref mag, 2, "", ref imgData))
  48. {
  49. return null;
  50. }
  51. bse.SetImageData(imgData, (int)(rec.Width*mag), (int)(rec.Height*mag));
  52. return bse;
  53. }
  54. public bool Init()
  55. {
  56. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  57. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  58. if (FEIIP == "" || FEIPORT == "")
  59. {
  60. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  61. return false;
  62. }
  63. if (ApiClass.isConnect())
  64. {
  65. return true;
  66. }
  67. return ApiClass.Connect(FEIIP, FEIPORT);
  68. }
  69. public bool SetDwellTime(DwellTimeLevel val)
  70. {
  71. dwelltime = 0.5;
  72. switch (val)
  73. {
  74. case DwellTimeLevel.Low:
  75. dwelltime = 0.5;
  76. break;
  77. case DwellTimeLevel.Medium:
  78. dwelltime = 1;
  79. break;
  80. case DwellTimeLevel.High:
  81. dwelltime = 4;
  82. break;
  83. }
  84. return true;
  85. }
  86. public bool SetImageSize(int nWidth, int nHeight)
  87. {
  88. imageWidth = nWidth;
  89. imageHeight = nHeight;
  90. return ApiClass.SetResolution(imageWidth, imageHeight); ;
  91. }
  92. }
  93. }