コード例 #1
0
        /// <summary>
        /// Will write large, complex, multi-sweep CSV file
        /// </summary>
        /// <param name="sFilename"></param>
        /// <param name="cCSVDelimiter"></param>
        public void SaveFileCSV(string sFilename, char cCSVDelimiter, RFEAmplitudeTableData AmplitudeCorrection)
        {
            if (m_nUpperBound <= 0)
            {
                return;
            }

            RFESweepData objFirst = m_arrData[0];

            using (StreamWriter myFile = new StreamWriter(sFilename, false))
            {
                myFile.WriteLine("RF Explorer CSV data file: " + FileHeaderVersioned());
                myFile.WriteLine("Start Frequency: " + objFirst.StartFrequencyMHZ.ToString() + "MHZ" + Environment.NewLine +
                                 "Step Frequency: " + (objFirst.StepFrequencyMHZ * 1000).ToString() + "KHZ" + Environment.NewLine +
                                 "Total data entries: " + m_nUpperBound.ToString() + Environment.NewLine +
                                 "Steps per entry: " + objFirst.TotalSteps.ToString());

                string sHeader = "Sweep" + cCSVDelimiter + "Date" + cCSVDelimiter + "Time" + cCSVDelimiter + "Milliseconds";

                for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                {
                    double dFrequency = objFirst.StartFrequencyMHZ + nStep * (objFirst.StepFrequencyMHZ);
                    sHeader += cCSVDelimiter + dFrequency.ToString("0000.000");
                }

                myFile.WriteLine(sHeader);

                for (int nSweepInd = 0; nSweepInd < m_nUpperBound; nSweepInd++)
                {
                    myFile.Write(nSweepInd.ToString() + cCSVDelimiter);

                    myFile.Write(m_arrData[nSweepInd].CaptureTime.ToShortDateString() + cCSVDelimiter +
                                 m_arrData[nSweepInd].CaptureTime.ToString("HH:mm:ss") + cCSVDelimiter +
                                 m_arrData[nSweepInd].CaptureTime.ToString("\\.fff") + cCSVDelimiter);

                    if (!m_arrData[nSweepInd].IsSameConfiguration(objFirst))
                    {
                        break;
                    }

                    for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                    {
                        myFile.Write(m_arrData[nSweepInd].GetAmplitudeDBM(nStep, AmplitudeCorrection, AmplitudeCorrection != null));
                        if (nStep != (objFirst.TotalSteps - 1))
                        {
                            myFile.Write(cCSVDelimiter);
                        }
                    }
                    myFile.Write(Environment.NewLine);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Save a CSV file using one frequency point/dBm value per line
 /// </summary>
 /// <param name="sFilename">full path filename</param>
 /// <param name="cCSVDelimiter">comma delimiter to use</param>
 /// <param name="AmplitudeCorrection"></param>
 public void SaveFileCSV(string sFilename, char cCSVDelimiter, RFEAmplitudeTableData AmplitudeCorrection)
 {
     using (StreamWriter myFile = new StreamWriter(sFilename, false))
     {
         for (UInt16 nDataPoint = 0; nDataPoint < TotalDataPoints; nDataPoint++)
         {
             myFile.Write(GetFrequencyMHZ(nDataPoint).ToString("f3"));
             myFile.Write(cCSVDelimiter);
             myFile.Write(GetAmplitudeDBM(nDataPoint, AmplitudeCorrection, AmplitudeCorrection != null).ToString("f1"));
             myFile.Write(Environment.NewLine);
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Returns amplitude data in dBm. This is the value as it was read from the device or from a file
 /// so it is not adjusted by offset or additionally compensated in any way. If the value was read from a device,
 /// it may already be an adjusted value including device configured offset.
 /// </summary>
 /// <param name="nStep">Internal frequency step or bucket to read data from</param>
 /// <param name="AmplitudeCorrection">Optional parameter, can be null. If different than null, use the amplitude correction table</param>
 /// <param name="bUseCorrection">If the AmplitudeCorrection is not null, this boolean will tell whether to use it or not</param>
 /// <returns>Value in dBm</returns>
 public float GetAmplitudeDBM(UInt16 nStep, RFEAmplitudeTableData AmplitudeCorrection, bool bUseCorrection)
 {
     if (nStep < m_nTotalSteps)
     {
         if ((AmplitudeCorrection != null) && bUseCorrection)
         {
             return(m_arrAmplitude[nStep] + AmplitudeCorrection.GetAmplitudeCalibration((int)GetFrequencyMHZ(nStep)));
         }
         else
         {
             return(m_arrAmplitude[nStep]);
         }
     }
     else
     {
         return(RFECommunicator.MIN_AMPLITUDE_DBM);
     }
 }
コード例 #4
0
 /// <summary>
 /// Returns amplitude data in dBm. This is the value as it was read from the device or from a file
 /// so it is not adjusted by offset or additionally compensated in any way. If the value was read from a device,
 /// it may already be an adjusted value including device configured offset.
 /// </summary>
 /// <param name="nDataPoint">Internal frequency data point to read data from</param>
 /// <param name="AmplitudeCorrection">Optional parameter, can be null. If different than null, use the amplitude correction table</param>
 /// <param name="bUseCorrection">If the AmplitudeCorrection is not null, this boolean will tell whether to use it or not</param>
 /// <returns>Value in dBm</returns>
 public float GetAmplitudeDBM(UInt16 nDataPoint, RFEAmplitudeTableData AmplitudeCorrection, bool bUseCorrection)
 {
     if (nDataPoint < m_nTotalDataPoints)
     {
         if ((AmplitudeCorrection != null) && bUseCorrection)
         {
             return(m_arrAmplitude[nDataPoint] + AmplitudeCorrection.GetAmplitudeCalibration((int)GetFrequencyMHZ(nDataPoint)));
         }
         else
         {
             return(m_arrAmplitude[nDataPoint]);
         }
     }
     else
     {
         return(RFECommunicator.MIN_AMPLITUDE_DBM + m_fOffsetDB);
     }
 }
コード例 #5
0
        public void GetTopBottomDataRange(out double dTopRangeDBM, out double dBottomRangeDBM, RFEAmplitudeTableData AmplitudeCorrection)
        {
            dTopRangeDBM = RFECommunicator.MIN_AMPLITUDE_DBM;
            dBottomRangeDBM = RFECommunicator.MAX_AMPLITUDE_DBM;

            if (m_nUpperBound <= 0)
                return;

            for (UInt32 nIndSample = 0; nIndSample < m_nUpperBound; nIndSample++)
            {
                for (UInt16 nIndStep = 0; nIndStep < m_arrData[0].TotalSteps; nIndStep++)
                {
                    double dValueDBM = m_arrData[nIndSample].GetAmplitudeDBM(nIndStep,AmplitudeCorrection,AmplitudeCorrection!=null);
                    if (dTopRangeDBM < dValueDBM)
                        dTopRangeDBM = dValueDBM;
                    if (dBottomRangeDBM > dValueDBM)
                        dBottomRangeDBM = dValueDBM;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Saves a file in RFE standard format. Note it will not handle exceptions so the calling application can deal with GUI details
        /// Note: if there are sweeps with different start/stop frequencies, only the first one will be saved to disk
        /// </summary>
        /// <param name="sFilename"></param>
        public void SaveFile(string sFilename, string sModelText, string sConfigurationText, RFEAmplitudeTableData AmplitudeCorrection)
        {
            if (m_nUpperBound < 0)
            {
                return;
            }

            RFESweepData objFirst = m_arrData[0];
            int nTotalSweepsActuallySaved = 0;

            //Save file
            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFilename, FileMode.Create);

                using (BinaryWriter binStream = new BinaryWriter(myFile))
                {
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    //NOTE: if we have different values for start/stop, we are saying we have more than we actually saved
                    //This is why we will save these parameters later again with nTotalSweepsActuallySaved
                    binStream.Write((UInt32)m_nUpperBound);

                    binStream.Write((UInt16)objFirst.TotalSteps);
                    binStream.Write((string)sConfigurationText);
                    binStream.Write((string)sModelText);

                    for (int nSweepInd = 0; nSweepInd <= m_nUpperBound; nSweepInd++)
                    {
                        if (!m_arrData[nSweepInd].IsSameConfiguration(objFirst))
                            break;

                        //new in v002 - save date/time for each captured sweep
                        string sTime = m_arrData[nSweepInd].CaptureTime.ToString("o");
                        binStream.Write((Int32)sTime.Length);
                        binStream.Write((string)sTime);

                        nTotalSweepsActuallySaved++;
                        for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                        {
                            binStream.Write((double)m_arrData[nSweepInd].GetAmplitudeDBM(nStep,AmplitudeCorrection,AmplitudeCorrection!=null));
                        }
                    }

                    //Save file fields again (will overwrite old ones), just to make sure nTotalSweepsActuallySaved is properly saved with actual value used
                    myFile.Seek(0, SeekOrigin.Begin);
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    binStream.Write((Int32)nTotalSweepsActuallySaved);
                }
            }
            finally
            {
                if (myFile != null)
                    myFile.Dispose();
            }

            try
            {
                myFile = new FileStream(sFilename, FileMode.Open);

                using (BinaryWriter binStream = new BinaryWriter(myFile))
                {
                    myFile = null;

                    binStream.Write(FileHeaderVersioned());
                    binStream.Write(objFirst.StartFrequencyMHZ);
                    binStream.Write(objFirst.StepFrequencyMHZ);
                    binStream.Write(nTotalSweepsActuallySaved);
                }
            }
            finally
            {
                if (myFile != null)
                    myFile.Dispose();
            }
        }
コード例 #7
0
        /// <summary>
        /// Will write large, complex, multi-sweep CSV file
        /// </summary>
        /// <param name="sFilename"></param>
        /// <param name="cCSVDelimiter"></param>
        public void SaveFileCSV(string sFilename, char cCSVDelimiter, RFEAmplitudeTableData AmplitudeCorrection)
        {
            if (m_nUpperBound <= 0)
            {
                return;
            }

            RFESweepData objFirst = m_arrData[0];

            using (StreamWriter myFile = new StreamWriter(sFilename, true))
            {
                myFile.WriteLine("RF Explorer CSV data file: " + FileHeaderVersioned());
                myFile.WriteLine("Start Frequency: " + objFirst.StartFrequencyMHZ.ToString() + "MHZ" + Environment.NewLine +
                    "Step Frequency: " + (objFirst.StepFrequencyMHZ * 1000).ToString() + "KHZ" + Environment.NewLine +
                    "Total data entries: " + m_nUpperBound.ToString() + Environment.NewLine +
                    "Steps per entry: " + objFirst.TotalSteps.ToString());

                string sHeader = "Sweep" + cCSVDelimiter + "Date" + cCSVDelimiter + "Time" + cCSVDelimiter + "Milliseconds";

                for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                {
                    double dFrequency = objFirst.StartFrequencyMHZ + nStep * (objFirst.StepFrequencyMHZ);
                    sHeader += cCSVDelimiter + dFrequency.ToString("0000.000");
                }

                myFile.WriteLine(sHeader);

                for (int nSweepInd = 0; nSweepInd < m_nUpperBound; nSweepInd++)
                {
                    myFile.Write(nSweepInd.ToString() + cCSVDelimiter);

                    myFile.Write(m_arrData[nSweepInd].CaptureTime.ToShortDateString() + cCSVDelimiter +
                        m_arrData[nSweepInd].CaptureTime.ToString("HH:mm:ss") + cCSVDelimiter +
                        m_arrData[nSweepInd].CaptureTime.ToString("\\.fff") + cCSVDelimiter);

                    if (!m_arrData[nSweepInd].IsSameConfiguration(objFirst))
                        break;

                    for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                    {
                        myFile.Write(m_arrData[nSweepInd].GetAmplitudeDBM(nStep, AmplitudeCorrection, AmplitudeCorrection!=null));
                        if (nStep != (objFirst.TotalSteps - 1))
                            myFile.Write(cCSVDelimiter);
                    }
                    myFile.Write(Environment.NewLine);
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Returns amplitude data in dBm. This is the value as it was read from the device or from a file
 /// so it is not adjusted by offset or additionally compensated in any way. If the value was read from a device,
 /// it may already be an adjusted value including device configured offset.
 /// </summary>
 /// <param name="nStep">Internal frequency step or bucket to read data from</param>
 /// <param name="AmplitudeCorrection">Optional parameter, can be null. If different than null, use the amplitude correction table</param>
 /// <param name="bUseCorrection">If the AmplitudeCorrection is not null, this boolean will tell whether to use it or not</param>
 /// <returns>Value in dBm</returns>
 public float GetAmplitudeDBM(UInt16 nStep, RFEAmplitudeTableData AmplitudeCorrection, bool bUseCorrection)
 {
     if (nStep < m_nTotalSteps)
     {
         if ((AmplitudeCorrection != null) && bUseCorrection)
         {
             return m_arrAmplitude[nStep] + AmplitudeCorrection.GetAmplitudeCalibration((int)GetFrequencyMHZ(nStep));
         }
         else
         {
             return m_arrAmplitude[nStep];
         }
     }
     else
         return RFECommunicator.MIN_AMPLITUDE_DBM;
 }
コード例 #9
0
        public void GetTopBottomDataRange(out double dTopRangeDBM, out double dBottomRangeDBM, RFEAmplitudeTableData AmplitudeCorrection)
        {
            dTopRangeDBM    = RFECommunicator.MIN_AMPLITUDE_DBM;
            dBottomRangeDBM = RFECommunicator.MAX_AMPLITUDE_DBM;

            if (m_nUpperBound <= 0)
            {
                return;
            }

            for (UInt32 nIndSample = 0; nIndSample < m_nUpperBound; nIndSample++)
            {
                for (UInt16 nIndStep = 0; nIndStep < m_arrData[0].TotalSteps; nIndStep++)
                {
                    double dValueDBM = m_arrData[nIndSample].GetAmplitudeDBM(nIndStep, AmplitudeCorrection, AmplitudeCorrection != null);
                    if (dTopRangeDBM < dValueDBM)
                    {
                        dTopRangeDBM = dValueDBM;
                    }
                    if (dBottomRangeDBM > dValueDBM)
                    {
                        dBottomRangeDBM = dValueDBM;
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Saves a file in RFE standard format. Note it will not handle exceptions so the calling application can deal with GUI details
        /// Note: if there are sweeps with different start/stop frequencies, only the first one will be saved to disk
        /// </summary>
        /// <param name="sFilename"></param>
        public void SaveFile(string sFilename, string sModelText, string sConfigurationText, RFEAmplitudeTableData AmplitudeCorrection)
        {
            if (m_nUpperBound < 0)
            {
                return;
            }

            RFESweepData objFirst = m_arrData[0];
            int          nTotalSweepsActuallySaved = 0;

            //Save file
            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFilename, FileMode.Create);

                using (BinaryWriter binStream = new BinaryWriter(myFile))
                {
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    //NOTE: if we have different values for start/stop, we are saying we have more than we actually saved
                    //This is why we will save these parameters later again with nTotalSweepsActuallySaved
                    binStream.Write((UInt32)m_nUpperBound);

                    binStream.Write((UInt16)objFirst.TotalSteps);
                    binStream.Write((string)sConfigurationText);
                    binStream.Write((string)sModelText);

                    for (int nSweepInd = 0; nSweepInd <= m_nUpperBound; nSweepInd++)
                    {
                        if (!m_arrData[nSweepInd].IsSameConfiguration(objFirst))
                        {
                            break;
                        }

                        //new in v002 - save date/time for each captured sweep
                        string sTime = m_arrData[nSweepInd].CaptureTime.ToString("o");
                        binStream.Write((Int32)sTime.Length);
                        binStream.Write((string)sTime);

                        nTotalSweepsActuallySaved++;
                        for (UInt16 nStep = 0; nStep < objFirst.TotalSteps; nStep++)
                        {
                            binStream.Write((double)m_arrData[nSweepInd].GetAmplitudeDBM(nStep, AmplitudeCorrection, AmplitudeCorrection != null));
                        }
                    }

                    //Save file fields again (will overwrite old ones), just to make sure nTotalSweepsActuallySaved is properly saved with actual value used
                    myFile.Seek(0, SeekOrigin.Begin);
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    binStream.Write((Int32)nTotalSweepsActuallySaved);
                }
            }
            finally
            {
                if (myFile != null)
                {
                    myFile.Dispose();
                }
            }

            try
            {
                myFile = new FileStream(sFilename, FileMode.Open);

                using (BinaryWriter binStream = new BinaryWriter(myFile))
                {
                    myFile = null;

                    binStream.Write(FileHeaderVersioned());
                    binStream.Write(objFirst.StartFrequencyMHZ);
                    binStream.Write(objFirst.StepFrequencyMHZ);
                    binStream.Write(nTotalSweepsActuallySaved);
                }
            }
            finally
            {
                if (myFile != null)
                {
                    myFile.Dispose();
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Saves a file in RFE standard format. Note it will not handle exceptions so the calling application can deal with GUI details
        /// Note: if there are sweeps with different start/stop frequencies, only the first one will be saved to disk
        /// </summary>
        /// <param name="sFilename"></param>
        public void SaveFile(string sFilename, string sModelText, string sConfigurationText, RFEAmplitudeTableData AmplitudeCorrection)
        {
            if (m_nUpperBound < 0)
            {
                return;
            }

            RFESweepData objFirst = m_arrData[0];
            int          nTotalSweepsActuallySaved = 0;

            //Save file
            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFilename, FileMode.Create);

                using (BinaryWriter binStream = new BinaryWriter(myFile))
                {
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    //NOTE: if we have different values for start/stop, we are saying we have more than we actually saved
                    //This is why we will save these parameters later again with nTotalSweepsActuallySaved
                    binStream.Write((UInt32)m_nUpperBound);

                    binStream.Write((UInt16)objFirst.TotalDataPoints);
                    binStream.Write((string)sConfigurationText);
                    binStream.Write((string)sModelText);

                    var memoryStream = new MemoryStream();
                    using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
                    {
                        int nUncompressedSize = 0;
                        using (BinaryWriter ZipStream = new BinaryWriter(gZipStream))
                        {
                            //Save all the sweeps consecutively
                            for (int nSweepInd = 0; nSweepInd <= m_nUpperBound; nSweepInd++)
                            {
                                if (!m_arrData[nSweepInd].IsSameConfiguration(objFirst))
                                {
                                    break;
                                }

                                //new in v002 - save date/time for each captured sweep
                                string sTime = m_arrData[nSweepInd].CaptureTime.ToString("o");
                                ZipStream.Write((Int32)sTime.Length);
                                byte[] arrText = Encoding.ASCII.GetBytes(sTime); //From v003 we encode string to byte for Date/time data
                                ZipStream.Write(arrText, 0, arrText.Length);
                                nUncompressedSize += arrText.Length + sizeof(System.Int32);

                                nTotalSweepsActuallySaved++;
                                for (UInt16 nDataPoint = 0; nDataPoint < objFirst.TotalDataPoints; nDataPoint++)
                                {
                                    ZipStream.Write((double)m_arrData[nSweepInd].GetAmplitudeDBM(nDataPoint, AmplitudeCorrection, AmplitudeCorrection != null));
                                }
                                nUncompressedSize += sizeof(System.Double) * objFirst.TotalDataPoints;
                            }
                        }
                        memoryStream.Position = 0;

                        byte[] arrCompressedBuffer = new byte[memoryStream.Length];
                        memoryStream.Read(arrCompressedBuffer, 0, arrCompressedBuffer.Length);

                        binStream.Write(nUncompressedSize);
                        binStream.Write(arrCompressedBuffer.Length);
                        binStream.Write(arrCompressedBuffer, 0, arrCompressedBuffer.Length);
                    }

                    //Save file fields again (will overwrite old ones), just to make sure nTotalSweepsActuallySaved is properly saved with actual value used
                    myFile.Seek(0, SeekOrigin.Begin);
                    binStream.Write((string)FileHeaderVersioned());
                    binStream.Write((double)objFirst.StartFrequencyMHZ);
                    binStream.Write((double)objFirst.StepFrequencyMHZ);
                    binStream.Write((Int32)nTotalSweepsActuallySaved);
                }
            }
            finally
            {
                if (myFile != null)
                {
                    myFile.Dispose();
                }
            }
        }
コード例 #12
0
 public void SaveFileXML(string sFilename, char cCSVDelimiter, RFEAmplitudeTableData AmplitudeCorrection)
 {
     //TODO: create a self-contained structure, including all member variables, and a list of all amplitude values in a single element <ScanData>y1,y2,...</ScanData>
 }