FEIEDSController.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. namespace OTSMeasureApp.ServiceCenter
  9. {
  10. class FEIEDSController : IEDSController
  11. {
  12. private APIClass ApiClass = null;
  13. private int AnalyExpCount = 100000;
  14. private string strResolution = "";
  15. private int width = 0;
  16. private int height = 0;
  17. /// <summary>
  18. /// fei面扫这个参数作用是达到这个数值后采集xray操作停止,而ots期望计数率是lowcount的判断标准,两者概念不同,所以此处用常数5000而非ots期望计数率
  19. /// </summary>
  20. const int maxCounts = 8000;
  21. public FEIEDSController(int MaxCounts)
  22. {
  23. ApiClass = FEISemController.GetApiClassInstance();
  24. SetAnalyExpCount(MaxCounts);
  25. Connect();
  26. }
  27. public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  28. {
  29. for (int i = 0; i < a_listParticles.Count; i++)
  30. {
  31. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  32. uint[] spectrumItems = new uint[2000];
  33. if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫
  34. {
  35. List<Point> points = CImageHandler.FindContoursBySegment(width, height, a_listParticles[i].GetFeature().GetSegmentsList());
  36. if (!ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
  37. {
  38. return false;
  39. }
  40. }
  41. else
  42. {
  43. Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();
  44. if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
  45. {
  46. return false;
  47. }
  48. }
  49. var xray = a_listParticles[i].GetXray();
  50. xray.SetXrayData(spectrumItems);
  51. a_listParticles[i].SetXray(xray);
  52. if (a_bElementInfo)
  53. {
  54. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  55. for (int j = 0; j < eleItems.Count; j++)
  56. {
  57. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  58. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  59. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  60. elementChemistryClrs.Add(chemistryClr);
  61. }
  62. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  63. }
  64. }
  65. return true;
  66. }
  67. public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
  68. {
  69. for (int i = 0; i < a_listParticles.Count; i++)
  70. {
  71. Point point = (Point)a_listParticles[i].GetXRayPos();
  72. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  73. uint[] spectrumItems = new uint[2000];
  74. if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  75. {
  76. return false;
  77. }
  78. var xray = a_listParticles[i].GetXray();
  79. xray.SetXrayData(spectrumItems);
  80. a_listParticles[i].SetXray(xray);
  81. if (a_bElementInfo)
  82. {
  83. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  84. for (int j = 0; j < eleItems.Count; j++)
  85. {
  86. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  87. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  88. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  89. elementChemistryClrs.Add(chemistryClr);
  90. }
  91. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  92. }
  93. }
  94. return true;
  95. }
  96. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  97. {
  98. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  99. return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
  100. }
  101. public bool Connect()
  102. {
  103. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  104. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  105. if (FEIIP == "" || FEIPORT == "")
  106. {
  107. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  108. return false;
  109. }
  110. if (ApiClass.isConnect())
  111. {
  112. return true;
  113. }
  114. return ApiClass.Connect(FEIIP, FEIPORT);
  115. }
  116. private bool SetAnalyExpCount(int MaxCounts)
  117. {
  118. AnalyExpCount = MaxCounts;
  119. return true;
  120. }
  121. public EDSTYPE GetEDSType()
  122. {
  123. return EDSTYPE.FEI;
  124. }
  125. public void SetFilterKeyEleNames(List<string> KeyNameList)
  126. {
  127. throw new NotImplementedException();
  128. }
  129. void IEDSController.SetResolution(int ResolutionWidth, int ResolutionHeight)
  130. {
  131. ApiClass.SetResolution(ResolutionWidth, ResolutionHeight);
  132. width = ResolutionWidth;
  133. height = ResolutionHeight;
  134. strResolution = ResolutionWidth.ToString() + "x" + ResolutionHeight.ToString();
  135. }
  136. public bool QuantifyXrayByPart(COTSParticleClr part)
  137. {
  138. return true;
  139. }
  140. public int GetExpectCount()
  141. {
  142. return AnalyExpCount;
  143. }
  144. public bool GetIfDelayQuantify()
  145. {
  146. return false;
  147. }
  148. }
  149. }