ScanController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. 
  2. using FEIApiControl;
  3. using OTSCLRINTERFACE;
  4. using OTSDataType;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace OTSModelSharp.ServiceInterface
  13. {
  14. public class ScanController : IScanController
  15. {
  16. private OTSCLRINTERFACE.COTSControlFunExport scan;
  17. static ScanController scanctrl=null;
  18. public static APIClass ApiClass = null;
  19. private static bool isFEI = false;
  20. int imageWidth = 0;
  21. int imageHeight = 0;
  22. public static ScanController GetScanController()
  23. {
  24. if (FileHelper.GetXMLInformations("SemControllerName") == "FEI")
  25. {
  26. isFEI = true;
  27. }
  28. if (scanctrl == null)
  29. {
  30. scanctrl = new ScanController();
  31. }
  32. return scanctrl;
  33. }
  34. private ScanController()
  35. {
  36. if (isFEI)
  37. {
  38. ApiClass = new APIClass();
  39. }
  40. else
  41. {
  42. this.scan = SemController.hw;
  43. }
  44. }
  45. public CBSEImgClr AcquireBSEImage(int matrixIndex, int reads, int dwell)
  46. {
  47. if (isFEI)
  48. {
  49. Rectangle r = new Rectangle();
  50. CBSEImgClr bse = new CBSEImgClr(r);
  51. bse.InitImageData(imageWidth, imageHeight);
  52. byte[] imgData = new byte[imageWidth * imageHeight];
  53. if (!ApiClass.RunAcquireImage(imageWidth, imageHeight, dwell, "", ref imgData))
  54. {
  55. return null;
  56. }
  57. bse.SetImageData(imgData, imageWidth, imageHeight);
  58. return bse;
  59. }
  60. else
  61. {
  62. if (!scan.IsConnected())
  63. {
  64. return null;
  65. }
  66. Rectangle r = new Rectangle();
  67. CBSEImgClr bse = new CBSEImgClr(r);
  68. if (!scan.AcquireBSEImage(matrixIndex, reads, dwell, ref bse))
  69. {
  70. return null;
  71. }
  72. return bse;
  73. }
  74. }
  75. public bool Init()
  76. {
  77. if (isFEI)
  78. {
  79. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  80. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  81. if (FEIIP == "" || FEIPORT == "")
  82. {
  83. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  84. return false;
  85. }
  86. if (ApiClass.isConnect())
  87. {
  88. return true;
  89. }
  90. return ApiClass.Connect(FEIIP, FEIPORT);
  91. }
  92. else
  93. {
  94. return scan.ScanInit();
  95. }
  96. }
  97. public bool SetDwellTime(long val)
  98. {
  99. if (isFEI)
  100. {
  101. return true;
  102. }
  103. else
  104. {
  105. if (!scan.IsConnected())
  106. {
  107. return false;
  108. }
  109. return scan.SetDwellTime((int)val);
  110. }
  111. }
  112. public bool SetImageSize(int width,int height)
  113. {
  114. imageWidth = width;
  115. imageHeight = height;
  116. if (isFEI)
  117. {
  118. return ApiClass.SetResolution(imageWidth, imageHeight);
  119. }
  120. else
  121. {
  122. if (!scan.IsConnected())
  123. {
  124. return false;
  125. }
  126. return scan.SetImageSize(width, height);
  127. }
  128. }
  129. }
  130. }