FEIEDSController.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. public FEIEDSController(int ResolutionWidth, int ResolutionHeight, int MaxCounts)
  16. {
  17. ApiClass = new APIClass();
  18. SetResolution(ResolutionWidth, ResolutionHeight);
  19. SetAnalyExpCount(MaxCounts);
  20. }
  21. public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  22. {
  23. for (int i = 0; i < a_listParticles.Count; i++)
  24. {
  25. Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();
  26. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  27. uint[] spectrumItems = new uint[2000];
  28. if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  29. {
  30. return false;
  31. }
  32. a_listParticles[i].GetXray().SetXrayData(spectrumItems);
  33. if (a_bElementInfo)
  34. {
  35. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  36. for (int j = 0; j < eleItems.Count; j++)
  37. {
  38. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  39. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  40. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  41. elementChemistryClrs.Add(chemistryClr);
  42. }
  43. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  44. }
  45. }
  46. return true;
  47. }
  48. public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
  49. {
  50. for (int i = 0; i < a_listParticles.Count; i++)
  51. {
  52. Point point = (Point)a_listParticles[i].GetXRayPos();
  53. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  54. uint[] spectrumItems = new uint[2000];
  55. if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  56. {
  57. return false;
  58. }
  59. a_listParticles[i].GetXray().SetXrayData(spectrumItems);
  60. if (a_bElementInfo)
  61. {
  62. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  63. for (int j = 0; j < eleItems.Count; j++)
  64. {
  65. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  66. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  67. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  68. elementChemistryClrs.Add(chemistryClr);
  69. }
  70. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  71. }
  72. }
  73. return true;
  74. }
  75. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  76. {
  77. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  78. return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
  79. }
  80. public bool Init()
  81. {
  82. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  83. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  84. if (FEIIP == "" || FEIPORT == "")
  85. {
  86. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  87. return false;
  88. }
  89. if (ApiClass.isConnect())
  90. {
  91. return true;
  92. }
  93. return ApiClass.Connect(FEIIP, FEIPORT);
  94. }
  95. private bool SetResolution(int ResolutionWidth, int ResolutionHeight)
  96. {
  97. strResolution = ResolutionWidth + "x" + ResolutionHeight;
  98. return true;
  99. }
  100. private bool SetAnalyExpCount(int MaxCounts)
  101. {
  102. AnalyExpCount = MaxCounts;
  103. return true;
  104. }
  105. public EDSTYPE GetEDSType()
  106. {
  107. return EDSTYPE.FEI;
  108. }
  109. public void SetFilterKeyEleNames(List<string> KeyNameList)
  110. {
  111. throw new NotImplementedException();
  112. }
  113. }
  114. }