コード例 #1
0
        public unsafe void Start()
        {
            if (NativeMethods.LMS_Open(out _device, null, null) != 0)
            {
                throw new ApplicationException("Cannot open LimeSDR device. Is the device locked somewhere?");
            }

            NativeMethods.LMS_Init(_device);

            if (NativeMethods.LMS_EnableChannel(_device, LMS_CH_RX, _channel, true) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }


            if (NativeMethods.LMS_SetAntenna(_device, LMS_CH_RX, _channel, _ant) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            this.SampleRate = _sampleRate;
            this.Frequency  = (long)_centerFrequency;


            if (NativeMethods.LMS_SetGaindB(_device, LMS_CH_RX, _channel, _gain) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }


            lms_stream_t streamId = new lms_stream_t();

            streamId.handle              = 0;
            streamId.channel             = _channel;   //channel number
            streamId.fifoSize            = 128 * 1024; //fifo size in samples
            streamId.throughputVsLatency = 1.0f;       //optimize for max throughput
            streamId.isTx    = false;                  //RX channel
            streamId.dataFmt = dataFmt.LMS_FMT_F32;
            _stream          = Marshal.AllocHGlobal(Marshal.SizeOf(streamId));

            Marshal.StructureToPtr(streamId, _stream, false);
            if (NativeMethods.LMS_SetupStream(_device, _stream) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            if (NativeMethods.LMS_StartStream(_stream) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            _sampleThread          = new Thread(ReceiveSamples_sync);
            _sampleThread.Name     = "limesdr_samples_rx";
            _sampleThread.Priority = ThreadPriority.Highest;
            _isStreaming           = true;
            _sampleThread.Start();
        }
コード例 #2
0
        public unsafe void Start(uint ch, double lpbw, double gain, uint ant, double sr, float specOffset)
        {
            _ant           = ant;
            _channel       = ch;
            _lpbw          = lpbw;
            _gain          = (uint)gain;
            _sampleRate    = sr;
            SpectrumOffset = specOffset;

            NativeMethods.LMS_Init(_device);

            if (NativeMethods.LMS_EnableChannel(_device, LMS_CH_RX, _channel, true) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            if (NativeMethods.LMS_SetAntenna(_device, LMS_CH_RX, _channel, _ant) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            this.SampleRate = _sampleRate;

            if (SampleRate < 384000)
            {
                if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 32) != 0)
                {
                    throw new ApplicationException(NativeMethods.limesdr_strerror());
                }
            }
            else
            {
                if (SampleRate > 32000000)
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 0) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
                else if (SampleRate > 16000000)
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 4) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
                else if (SampleRate > 8000000)
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 8) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
                else if (SampleRate > 4000000)
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, (double)(SampleRate), 16) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
                else if (SampleRate > 2000000)
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 32) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
                else
                {
                    if (NativeMethods.LMS_SetSampleRateDir(_device, LMS_CH_RX, SampleRate, 32) != 0)
                    {
                        throw new ApplicationException(NativeMethods.limesdr_strerror());
                    }
                }
            }

            if (NativeMethods.LMS_SetGaindB(_device, LMS_CH_RX, _channel, _gain) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            LPBW = _lpbw;

            lms_stream_t streamId = new lms_stream_t();

            streamId.handle              = 0;
            streamId.channel             = _channel;    //channel number
            streamId.fifoSize            = 16 * 1024;   //fifo size in samples
            streamId.throughputVsLatency = 0.5f;        //balance
            streamId.isTx    = false;                   //RX channel
            streamId.dataFmt = dataFmt.LMS_FMT_F32;
            _stream          = Marshal.AllocHGlobal(Marshal.SizeOf(streamId));

            Marshal.StructureToPtr(streamId, _stream, false);
            if (NativeMethods.LMS_SetupStream(_device, _stream) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            if (NativeMethods.LMS_StartStream(_stream) != 0)
            {
                throw new ApplicationException(NativeMethods.limesdr_strerror());
            }

            _isStreaming   = true;
            this.Frequency = (long)_centerFrequency;

            _sampleThread          = new Thread(ReceiveSamples_sync);
            _sampleThread.Name     = "limesdr_samples_rx";
            _sampleThread.Priority = ThreadPriority.Highest;
            _sampleThread.Start();
        }