Ejemplo n.º 1
0
 public void Stop()
 {
     if (_worker == null)
     {
         return;
     }
     LibraryWrapper.rtlsdr_cancel_async(_dev);
     _worker.Join(100);
     _worker = null;
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     Stop();
     LibraryWrapper.rtlsdr_close(_dev);
     if (_gcHandle.IsAllocated)
     {
         _gcHandle.Free();
     }
     _dev = IntPtr.Zero;
     GC.SuppressFinalize(this);
 }
Ejemplo n.º 3
0
        public static DeviceDisplay[] GetActiveDevices()
        {
            uint count  = LibraryWrapper.rtlsdr_get_device_count();
            var  result = new DeviceDisplay[count];

            for (var i = 0u; i < count; i++)
            {
                string name = LibraryWrapper.rtlsdr_get_device_name(i);
                result[i] = new DeviceDisplay {
                    Index = i, Name = name
                };
            }

            return(result);
        }
Ejemplo n.º 4
0
        public void Start()
        {
            if (_worker != null)
            {
                throw new ApplicationException("Already running");
            }

            int r = LibraryWrapper.rtlsdr_set_center_freq(_dev, _centerFrequency);

            if (r != 0)
            {
                throw new ApplicationException("Cannot access RTL device");
            }

            r = LibraryWrapper.rtlsdr_set_tuner_gain_mode(_dev, _useTunerAgc ? 0 : 1);
            if (r != 0)
            {
                throw new ApplicationException("Cannot access RTL device");
            }

            if (!_useTunerAgc)
            {
                r = LibraryWrapper.rtlsdr_set_tuner_gain(_dev, _tunerGain);
                if (r != 0)
                {
                    throw new ApplicationException("Cannot access RTL device");
                }
            }

            r = LibraryWrapper.rtlsdr_reset_buffer(_dev);
            if (r != 0)
            {
                throw new ApplicationException("Cannot access RTL device");
            }

            _worker = new Thread(StreamProc)
            {
                Priority = ThreadPriority.Highest
            };
            _worker.Start();
        }
Ejemplo n.º 5
0
        public RtlDevice(uint index)
        {
            Index = index;
            int r = LibraryWrapper.rtlsdr_open(out _dev, Index);

            if (r != 0)
            {
                throw new ApplicationException("Cannot open RTL device. Is the device locked somewhere?");
            }
            int count = _dev == IntPtr.Zero ? 0 : LibraryWrapper.rtlsdr_get_tuner_gains(_dev, null);

            if (count < 0)
            {
                count = 0;
            }
            SupportsOffsetTuning = LibraryWrapper.rtlsdr_set_offset_tuning(_dev, 0) != -2;
            SupportedGains       = new int[count];
            if (count >= 0)
            {
                LibraryWrapper.rtlsdr_get_tuner_gains(_dev, SupportedGains);
            }
            Name      = LibraryWrapper.rtlsdr_get_device_name(Index);
            _gcHandle = GCHandle.Alloc(this);
        }