FEIEDSController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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,bool ifautoid,string knownelements)
  22. {
  23. ApiClass = FEISemController.GetApiClassInstance();
  24. ApiClass.SetQuantificationParam(ifautoid, knownelements);
  25. SetAnalyExpCount(MaxCounts);
  26. Connect();
  27. }
  28. public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  29. {
  30. for (int i = 0; i < a_listParticles.Count; i++)
  31. {
  32. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  33. uint[] spectrumItems = new uint[2000];
  34. if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫
  35. {
  36. List<Point> points = CImageHandler.FindContoursBySegment(width, height, a_listParticles[i].GetFeature().GetSegmentsList());
  37. if (!ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
  38. {
  39. return false;
  40. }
  41. }
  42. else
  43. {
  44. Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();
  45. if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
  46. {
  47. return false;
  48. }
  49. }
  50. var xray = a_listParticles[i].GetXray();
  51. xray.SetXrayData(spectrumItems);
  52. a_listParticles[i].SetXray(xray);
  53. if (a_bElementInfo)
  54. {
  55. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  56. for (int j = 0; j < eleItems.Count; j++)
  57. {
  58. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  59. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  60. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  61. elementChemistryClrs.Add(chemistryClr);
  62. }
  63. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  64. }
  65. }
  66. return true;
  67. }
  68. public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
  69. {
  70. for (int i = 0; i < a_listParticles.Count; i++)
  71. {
  72. Point point = (Point)a_listParticles[i].GetXRayPos();
  73. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  74. uint[] spectrumItems = new uint[2000];
  75. if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  76. {
  77. return false;
  78. }
  79. var xray = a_listParticles[i].GetXray();
  80. xray.SetXrayData(spectrumItems);
  81. a_listParticles[i].SetXray(xray);
  82. if (a_bElementInfo)
  83. {
  84. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  85. for (int j = 0; j < eleItems.Count; j++)
  86. {
  87. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  88. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  89. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  90. elementChemistryClrs.Add(chemistryClr);
  91. }
  92. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  93. }
  94. }
  95. return true;
  96. }
  97. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  98. {
  99. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  100. return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
  101. }
  102. public bool Connect()
  103. {
  104. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  105. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  106. if (FEIIP == "" || FEIPORT == "")
  107. {
  108. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  109. return false;
  110. }
  111. if (ApiClass.isConnect())
  112. {
  113. return true;
  114. }
  115. return ApiClass.Connect(FEIIP, FEIPORT);
  116. }
  117. private bool SetAnalyExpCount(int MaxCounts)
  118. {
  119. AnalyExpCount = MaxCounts;
  120. return true;
  121. }
  122. public EDSTYPE GetEDSType()
  123. {
  124. return EDSTYPE.FEI;
  125. }
  126. public void SetFilterKeyEleNames(List<string> KeyNameList)
  127. {
  128. throw new NotImplementedException();
  129. }
  130. void IEDSController.SetResolution(int ResolutionWidth, int ResolutionHeight)
  131. {
  132. ApiClass.SetResolution(ResolutionWidth, ResolutionHeight);
  133. width = ResolutionWidth;
  134. height = ResolutionHeight;
  135. strResolution = ResolutionWidth.ToString() + "x" + ResolutionHeight.ToString();
  136. }
  137. public bool QuantifyXrayByPart(COTSParticleClr part)
  138. {
  139. return true;
  140. }
  141. public int GetExpectCount()
  142. {
  143. return AnalyExpCount;
  144. }
  145. public bool GetIfDelayQuantify()
  146. {
  147. return false;
  148. }
  149. public void SetQuantifiCationParam(bool IfAutoId, string knownElements)
  150. {
  151. ApiClass.SetQuantificationParam(IfAutoId, knownElements);
  152. }
  153. public bool GetXRayByExpandFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  154. {
  155. throw new NotImplementedException();
  156. }
  157. }
  158. }