using FEIApiControl; using OTSCLRINTERFACE; using OTSModelSharp.ServiceCenter; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; namespace OTSMeasureApp.ServiceCenter { class FEIEDSController : IEDSController { private APIClass ApiClass = null; private int AnalyExpCount = 100000; private string strResolution = ""; public FEIEDSController(int ResolutionWidth, int ResolutionHeight, int MaxCounts) { ApiClass = new APIClass(); SetResolution(ResolutionWidth, ResolutionHeight); SetAnalyExpCount(MaxCounts); } public bool GetXRayByFeatures(List a_listParticles, double a_nXRayAQTime, bool a_bElementInfo) { for (int i = 0; i < a_listParticles.Count; i++) { Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect(); Dictionary eleItems = new Dictionary(); uint[] spectrumItems = new uint[2000]; if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems)) { return false; } a_listParticles[i].GetXray().SetXrayData(spectrumItems); if (a_bElementInfo) { List elementChemistryClrs = new List(); for (int j = 0; j < eleItems.Count; j++) { CElementChemistryClr chemistryClr = new CElementChemistryClr(); chemistryClr.SetName(eleItems.ElementAt(j).Key); chemistryClr.SetPercentage(eleItems.ElementAt(j).Value); elementChemistryClrs.Add(chemistryClr); } a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs); } } return true; } public bool GetXRayByParts(List a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo) { for (int i = 0; i < a_listParticles.Count; i++) { Point point = (Point)a_listParticles[i].GetXRayPos(); Dictionary eleItems = new Dictionary(); uint[] spectrumItems = new uint[2000]; if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems)) { return false; } a_listParticles[i].GetXray().SetXrayData(spectrumItems); if (a_bElementInfo) { List elementChemistryClrs = new List(); for (int j = 0; j < eleItems.Count; j++) { CElementChemistryClr chemistryClr = new CElementChemistryClr(); chemistryClr.SetName(eleItems.ElementAt(j).Key); chemistryClr.SetPercentage(eleItems.ElementAt(j).Value); elementChemistryClrs.Add(chemistryClr); } a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs); } } return true; } public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData) { Dictionary eleItems = new Dictionary(); return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData); } public bool Init() { string FEIIP = FileHelper.GetXMLInformations("FEIIP"); string FEIPORT = FileHelper.GetXMLInformations("FEIPORT"); if (FEIIP == "" || FEIPORT == "") { NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!"); return false; } if (ApiClass.isConnect()) { return true; } return ApiClass.Connect(FEIIP, FEIPORT); } private bool SetResolution(int ResolutionWidth, int ResolutionHeight) { strResolution = ResolutionWidth + "x" + ResolutionHeight; return true; } private bool SetAnalyExpCount(int MaxCounts) { AnalyExpCount = MaxCounts; return true; } public EDSTYPE GetEDSType() { return EDSTYPE.FEI; } public void SetFilterKeyEleNames(List KeyNameList) { throw new NotImplementedException(); } } }