示例#1
0
        public static double GetEndFreq(UnitsFrequency _units)
        {
            double res;

            try
            {
                res = Converter.Transform(Points[m_StopPoint].Frequency, UnitsFrequency.Hz, _units);
            }
            catch (Exception) { return(double.MaxValue); }
            return(res);
        }
示例#2
0
        private void mmImportTemplates_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "Файлы Конфигурации(*.ini)|options.ini";
            ofd.DefaultExt       = "ini";
            ofd.InitialDirectory = Properties.Settings.Default.OpenPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string  filename = ofd.FileName;
                var     parser   = new FileIniDataParser();
                IniData data     = parser.ReadFile(filename, Encoding.Default);
                List <MeasConfigurator.MeasPoint> ImportPoints = new List <MeasConfigurator.MeasPoint>();
                MeasConfigurator.MeasPoint        NewPoint;
                UnitsFrequency FreqUnits = UnitsFrequency.Hz;
                string         sTemp;
                string         SectionName = "";
                foreach (var section in data.Sections)
                {
                    ImportPoints.Clear();
                    SectionName = section.SectionName;
                    try
                    {
                        foreach (var key in section.Keys.ToList().FindAll(k => k.KeyName.Contains("Строка")))
                        {
                            if (key.KeyName == "Строка0") // Читаем заголовок таблицы
                            {
                                sTemp     = key.Value.Split('#')[2].Split(' ')[1];
                                FreqUnits = Converter.ToUnits <UnitsFrequency>(sTemp);
                            }
                            else
                            {
                                NewPoint           = new MeasConfigurator.MeasPoint(0);
                                sTemp              = key.Value.Split('#')[2];
                                NewPoint.Frequency = (long)Converter.Transform(double.Parse(sTemp), FreqUnits, UnitsFrequency.Hz);
                                sTemp              = key.Value.Split('#')[4];
                                NewPoint.Amplitude = int.Parse(sTemp);
                                sTemp              = key.Value.Split('#')[6];
                                NewPoint.Time_ms   = int.Parse(sTemp) * 1000;
                                ImportPoints.Add(NewPoint);
                            }
                        }
                        if (ImportPoints.Count > 0)
                        {
                            string path = Application.StartupPath + "\\templates\\" + SectionName + ".bin";
                            using (BinaryWriter writer = new BinaryWriter(File.Create(path)))
                            {
                                foreach (var Point in ImportPoints)
                                {
                                    writer.Write(Point.Frequency);
                                    writer.Write(Point.Amplitude);
                                    writer.Write(Point.Time_ms);
                                    writer.Write((int)Point.Band);
                                }
                            }
                        }
                    }
                    catch (Exception) { }
                }
                UpdateTemplateList();
            }
        }
示例#3
0
        public void Load(string _FileName, string _NamePrefix, out MeasList _ml)
        {
            string tmpStr;
            int    CurrentRow;
            int    CurrentColumn;
            double tmpValue;
            string measname;

            bool AnData  = false;
            bool MonData = false;

            _ml = null;

            using (var comApplication = new ComObject <Application>(new Application()))
            {
                var excelInstance = comApplication.Instance;
                excelInstance.Visible       = false;
                excelInstance.DisplayAlerts = false;

                try
                {
                    using (var workbooks = new ComObject <Workbooks>(excelInstance.Workbooks))
                        using (var workbook = new ComObject <_Workbook>(workbooks.Instance.Open(_FileName)))
                            using (var comSheets = new ComObject <Sheets>(workbook.Instance.Sheets))
                            {
                                foreach (_Worksheet sh in comSheets.Instance)
                                {
                                    if (sh.Name == "Анализатор.Данные")
                                    {
                                        AnData = true;
                                    }
                                    else if (sh.Name == "Монитор.Данные")
                                    {
                                        MonData = true;
                                    }
                                    Marshal.ReleaseComObject(sh);
                                }

                                if (AnData || MonData)
                                {
                                    _ml = new MeasList();
                                    List <long>    freqs     = new List <long>();
                                    UnitsFrequency frequnits = UnitsFrequency.Hz;

                                    if (AnData)
                                    {
                                        this.worksheet = (Worksheet)comSheets.Instance.get_Item("Анализатор.Данные");
                                        Range rangeCells = this.worksheet.Cells;

                                        var currentCell = (Range)rangeCells[1, 1];
                                        tmpStr = currentCell.Text;
                                        Marshal.ReleaseComObject(currentCell);
                                        if (tmpStr.Split(',').Count() > 1)
                                        {
                                            frequnits = Converter.ToUnits <UnitsFrequency>(tmpStr.Split(',')[1].Trim());
                                        }

                                        currentCell = (Range)rangeCells[1, 2];
                                        tmpStr      = currentCell.Text;
                                        Marshal.ReleaseComObject(currentCell);
                                        if (tmpStr.Split(',').Count() > 1)
                                        {
                                            _ml.AmplitudeUnits = Converter.ToUnits <UnitsAmplitude>(tmpStr.Split(',')[1].Trim());
                                        }
                                        else
                                        {
                                            _ml.AmplitudeUnits = UnitsAmplitude.dBm;
                                        }


                                        CurrentRow = 2;
                                        do // Читаем частоты
                                        {
                                            currentCell = (Range)rangeCells[CurrentRow, 1];
                                            tmpStr      = currentCell.Text;
                                            Marshal.ReleaseComObject(currentCell);
                                            if (double.TryParse(tmpStr, out tmpValue))
                                            {
                                                freqs.Add((long)Converter.Transform(tmpValue, frequnits, UnitsFrequency.Hz));
                                            }
                                            else
                                            {
                                                break;
                                            }
                                            CurrentRow++;
                                        } while (tmpStr != "");
                                        _ml.SetFrequency(freqs);

                                        CurrentColumn = 2;

                                        currentCell = (Range)rangeCells[1, CurrentColumn];
                                        measname    = currentCell.Text;
                                        Marshal.ReleaseComObject(currentCell);

                                        try
                                        {
                                            _ml.AmplitudeUnits = Converter.ToUnits <UnitsAmplitude>(measname.Split(',')[1].Trim());
                                        }
                                        catch (Exception)
                                        {
                                            _ml.AmplitudeUnits = UnitsAmplitude.dBm;
                                        }

                                        while (measname != "") // пока в заголовке измерения не пусто
                                        {
                                            CurrentRow = 2;
                                            _ml.AddMeasure(_NamePrefix + measname.Split(',')[0], false, false, true); // создаем измерение
                                            do                                                                        // Читаем измерение
                                            {
                                                currentCell = (Range)rangeCells[CurrentRow, CurrentColumn];
                                                tmpStr      = currentCell.Text;
                                                Marshal.ReleaseComObject(currentCell);

                                                if (double.TryParse(tmpStr, out tmpValue)) // если парсится, добавляем точку
                                                {
                                                    _ml.AddToAnalyzer(tmpValue);
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                                CurrentRow++;
                                            } while (tmpStr != "");
                                            CurrentColumn++;

                                            currentCell = (Range)rangeCells[1, CurrentColumn];
                                            measname    = currentCell.Text;
                                            Marshal.ReleaseComObject(currentCell);
                                        }

                                        Marshal.ReleaseComObject(rangeCells);
                                        Marshal.ReleaseComObject(this.worksheet);
                                    }



                                    if (MonData)
                                    {
                                        this.worksheet = (Worksheet)comSheets.Instance.get_Item("Монитор.Данные");
                                        Range rangeCells = this.worksheet.Cells;

                                        Range currentCell;

                                        if (!AnData)
                                        {
                                            currentCell = (Range)rangeCells[1, 1];
                                            tmpStr      = currentCell.Text;
                                            Marshal.ReleaseComObject(currentCell);
                                            if (tmpStr.Split(',').Count() > 1)
                                            {
                                                frequnits = Converter.ToUnits <UnitsFrequency>(tmpStr.Split(',')[1].Trim());
                                            }

                                            _ml.AmplitudeUnits = UnitsAmplitude.dBm;

                                            CurrentRow = 2;
                                            do // Читаем частоты
                                            {
                                                currentCell = (Range)rangeCells[CurrentRow, 1];
                                                tmpStr      = currentCell.Text;
                                                Marshal.ReleaseComObject(currentCell);
                                                if (double.TryParse(tmpStr, out tmpValue))
                                                {
                                                    freqs.Add((long)Converter.Transform(tmpValue, frequnits, UnitsFrequency.Hz));
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                                CurrentRow++;
                                            } while (tmpStr != "");
                                            _ml.SetFrequency(freqs);
                                        }

                                        CurrentColumn = 2;

                                        currentCell = (Range)rangeCells[1, CurrentColumn];
                                        measname    = currentCell.Text;
                                        Marshal.ReleaseComObject(currentCell);

                                        while (measname != "") // пока в заголовке измерения не пусто
                                        {
                                            CurrentRow = 2;
                                            _ml.AddMeasure(_NamePrefix + measname.Split(',')[0], true, false, true); // создаем измерение
                                            do                                                                       // Читаем измерение
                                            {
                                                currentCell = (Range)rangeCells[CurrentRow, CurrentColumn];
                                                tmpStr      = currentCell.Text;
                                                Marshal.ReleaseComObject(currentCell);

                                                if (double.TryParse(tmpStr, out tmpValue)) // если парсится, добавляем точку
                                                {
                                                    _ml.AddToMonitor(tmpValue);
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                                CurrentRow++;
                                            } while (tmpStr != "");
                                            CurrentColumn++;

                                            currentCell = (Range)rangeCells[1, CurrentColumn];
                                            measname    = currentCell.Text;
                                            Marshal.ReleaseComObject(currentCell);
                                        }

                                        Marshal.ReleaseComObject(rangeCells);
                                        Marshal.ReleaseComObject(this.worksheet);
                                    }
                                }
                            }
                }
                catch (Exception)
                {
                }
                finally
                {
                    // Close Excel instance
                    excelInstance.Quit();
                }
            }
        }