FEIScanController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. CBSEImgClr bse = new CBSEImgClr(r);
  41. bse.InitImageData(imageWidth, imageHeight);
  42. byte[] imgData = new byte[imageWidth * imageHeight];
  43. double mag=0;
  44. if (!ApiClass.RunAcquireImageRect(fieldWidth, fieldHeight, rec,ref mag, 2, "", ref imgData))
  45. {
  46. return null;
  47. }
  48. bse.SetImageData(imgData, (int)(rec.Width*mag), (int)(rec.Height*mag));
  49. return bse;
  50. }
  51. public bool Init()
  52. {
  53. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  54. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  55. if (FEIIP == "" || FEIPORT == "")
  56. {
  57. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  58. return false;
  59. }
  60. if (ApiClass.isConnect())
  61. {
  62. return true;
  63. }
  64. return ApiClass.Connect(FEIIP, FEIPORT);
  65. }
  66. public bool SetDwellTime(DwellTimeLevel val)
  67. {
  68. dwelltime = 0.5;
  69. switch (val)
  70. {
  71. case DwellTimeLevel.Low:
  72. dwelltime = 0.5;
  73. break;
  74. case DwellTimeLevel.Medium:
  75. dwelltime = 1;
  76. break;
  77. case DwellTimeLevel.High:
  78. dwelltime = 4;
  79. break;
  80. }
  81. return true;
  82. }
  83. public bool SetImageSize(int nWidth, int nHeight)
  84. {
  85. imageWidth = nWidth;
  86. imageHeight = nHeight;
  87. return ApiClass.SetResolution(imageWidth, imageHeight); ;
  88. }
  89. }
  90. }