How to use the get_direct_sampling function from bindings

Find comprehensive JavaScript bindings.get_direct_sampling code examples handpicked from public code repositorys.

bindings.get_direct_sampling is a function in the rtl-sdr library that enables direct sampling mode on a RTL-SDR device.

671
672
673
674
675
676
677
678
679
680
	rtlsdr.mock_set_rtlsdr_dev_contents(dev, 'direct_sampling', 0);
	rtlsdr.get_direct_sampling(dev).should.equal(0);
});

it('throws if dev_hnd is not an open device handle', () => {
	(() => rtlsdr.get_direct_sampling({})).should.throw();
});

it('throws if rtlsdr_get_direct_sampling errors', () => {
	rtlsdr.mock_set_rtlsdr_dev_contents(dev, 'mock_return_error', -1);
fork icon0
star icon1
watch icon0

+ 95 other calls in file

How does bindings.get_direct_sampling work?

bindings.get_direct_sampling is a function in the rtl-sdr library that enables direct sampling mode on an RTL-SDR device. Direct sampling mode is a feature of RTL-SDR devices that allows them to be used as general-purpose software-defined radios. In this mode, the device's built-in tuner is bypassed, and the incoming signal is sampled directly by the device's analog-to-digital converter (ADC). To enable direct sampling mode using bindings.get_direct_sampling, you need to provide the function with two arguments: the device index of the RTL-SDR device you want to use, and a value that indicates the sampling mode you want to use. The sampling mode value can be either 0, which disables direct sampling mode and uses the device's built-in tuner, or 1, which enables direct sampling mode and uses the device's ADC to sample the incoming signal directly. Note that enabling direct sampling mode requires some additional hardware setup, such as attaching an appropriate antenna or RF filter to the device. You should refer to the documentation for your specific RTL-SDR device for more information on how to use direct sampling mode. Also note that bindings.get_direct_sampling is a low-level function in the rtl-sdr library that is used to configure the RTL-SDR device for direct sampling mode. You will typically need to use other functions in the library, such as rtl_sdr_read_sync, to actually read data from the device once it is configured.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const rtlSdr = require("rtl-sdr");
const deviceIndex = 0; // The device index of the RTL-SDR device you want to use
const samplingMode = 1; // Enable direct sampling mode

// Open the RTL-SDR device and enable direct sampling mode
const device = rtlSdr.open(deviceIndex);
rtlSdr.setDirectSampling(device, samplingMode);

// Set the center frequency and sample rate for the RTL-SDR device
rtlSdr.setCenterFreq(device, 1000000000); // 1 GHz
rtlSdr.setSampleRate(device, 2000000); // 2 MS/s

// Read data from the RTL-SDR device
const buffer = Buffer.alloc(16384); // A buffer to hold the data
const numSamplesRead = rtlSdr.readSync(device, buffer, buffer.length);

// Close the RTL-SDR device
rtlSdr.close(device);

In this example, we start by importing the rtl-sdr library and setting the device index and sampling mode values. We then use the rtlSdr.open() function to open the RTL-SDR device with the specified device index. Next, we use rtlSdr.setDirectSampling() to enable direct sampling mode on the device. We then use rtlSdr.setCenterFreq() and rtlSdr.setSampleRate() to set the center frequency and sample rate for the device. Finally, we use rtlSdr.readSync() to read data from the device into a buffer, and rtlSdr.close() to close the device. Note that this is just an example, and the actual center frequency, sample rate, and buffer size values will depend on the specific use case. However, the basic pattern of using rtlSdr.setDirectSampling() to enable direct sampling mode on an RTL-SDR device is the same.

Other functions in bindings

Sorted by popularity

function icon

bindings.createKey is the most popular function in bindings (8616 examples)