Class RTLSDRDevice

Opened RTLSDR device.

NOTE: Do not create an instance of this class directly (unless for some weird reason you want to provide a pure C dev* buffer)

//Proper form
let device = rtljs.open(index);

//Improper form
// C device Ptr (typed as void) from librtlsdr rtlsdr_open
let device = new RTLSDRDevice(devPtr);

Constructors

Properties

device: bigint

Raw C librtlsdr device (typed as void)

open: boolean
supportedGains: number[]

Methods

  • Get actual frequency the device is tuned to.

    Returns number

    Frequency in Hz

    let freq = device.getCenterFreq();

    console.log(freq); // 1090000000
  • Get state of the direct sampling mode

    Returns number

    -1 on error, 0 means disabled, 1 I-ADC input enabled 2 Q-ADC input enabled

  • Get actual frequency correction value of the device.

    Returns number

    Correction value in parts per million (ppm)

    let ppm = device.getFreqCorrection();
    console.log(ppm); // 1
  • Get state of the offset tuning mode

    Returns number

    -1 on error, 0 means disabled, 1 enabled

  • Get actual sample rate the device is configured to.

    Returns number

    Sample rate in Hz

  • Get actual gain the device is configured to.

    Returns number

    Gain in tenths of a dB, 115 means 11.5 dB.

  • Get a list of gains supported by the tuner.

    NOTE: The gains argument must be preallocated by the caller. If NULL is being given instead, the number of available gain values will be returned.

    Returns number[]

    Number of available (returned) gain values otherwise

  • Get the tuner type.

    Returns string

    RTLSDR_TUNER_UNKNOWN on error, tuner type otherwise

    let type = device.getTunerType();

    console.log(type); // RTLSDR_TUNER_R820T
  • Get USB device strings. Max size 256 bytes. Alike to rtljs.getDeviceUSBStrings(index).

    Returns DeviceUSBStrings

    manufacturer, product, and serial strings. They may all be null.

    let strings = device.getUSBStrings();

    console.log(`${strings.manufacturer}, ${strings.product}, ${strings.serial}`);
  • Get crystal oscillator frequencies used for the RTL2832 and the tuner IC.

    Usually both ICs use the same clock.

    Returns XtalFreq

    Frequency value used to clock the RTL2832 and IC, in Hz

    let xtal = device.getXtalFreq();

    console.log(`${xtal.rtlFreq}, ${xtal.tunerFreq}`); // <RTL Freq in Hz>, <Tuner Freq in Hz>
  • Read samples from the device asynchronously. This function will block until it is being canceled using cancelAsync()

    Parameters

    • callback: ((buf: number[], len: number, ctx: void) => void)

      Callback function to return received samples (buf:number[], len:number, ctx:void)

        • (buf, len, ctx): void
        • Parameters

          • buf: number[]
          • len: number
          • ctx: void

          Returns void

    • buf_num: number

      optional buffer count, buf_num * buf_len = overall buffer size set to 0 for default buffer count (15)

    • buf_len: number

      optional buffer length, must be multiple of 512, should be a multiple of 16384 (URB size), set to 0 for default buffer length (16 * 32 * 512)

    Returns void

  • Read the device EEPROM

    Parameters

    • offset: number

      Address where the data should be read from

    • len: number

      Length of the data

    Returns number[]

  • read signal data from the device array returned may be smaller than what was requested

    Parameters

    • len: number

      Amount of data to return

    Returns number[]

    Buffer with signal data

  • Enable or disable the internal digital AGC of the RTL2832.

    Parameters

    • on: number

      digital AGC mode, 1 means enabled, 0 disabled

    Returns void

  • Set tune frequency of the device

    Parameters

    • freq: number

      Frequency to tune to in Hz

    Returns void

    device.setCenterFreq(1090000000); // 1090MHz (1090*10^6Hz)
    
  • Enable or disable the direct sampling mode. When enabled, the IF mode of the RTL2832 is activated, and rtlsdr_set_center_freq() will control the IF-frequency of the DDC, which can be used to tune from 0 to 28.8 MHz (xtal frequency of the RTL2832).

    Parameters

    • on: number

      0 means disabled, 1 I-ADC input enabled, 2 Q-ADC input enabled

    Returns void

  • Set the frequency correction value for the device.

    Parameters

    • ppm: number

      Correction value in parts per million (ppm)

    Returns void

    device.setFreqCorrection(1); // 1ppm correction
    
  • Enable or disable offset tuning for zero-IF tuners, which allows to avoid problems caused by the DC offset of the ADCs and 1/f noise.

    Parameters

    • on: number

      0 means disabled, 1 enabled

    Returns void

  • Set the sample rate for the device, also selects the baseband filters according to the requested sample rate for tuners where this is possible.

    Parameters

    • rate: number

      samp_rate the sample rate to be set, possible values are: 225001 - 300000 Hz 900001 - 3200000 Hz sample loss is to be expected for rates > 2400000

    Returns void

  • Enable test mode that returns an 8 bit counter instead of the samples. The counter is generated inside the RTL2832.

    Parameters

    • on: number

      Test mode, 1 means enabled, 0 disabled

    Returns void

  • Set the bandwidth for the device.

    Parameters

    • bw: number

      Bandwidth in Hz. Zero means automatic BW selection.

    Returns void

  • Set the gain for the device. Manual gain mode must be enabled for this to work.

    Each device has a specific set of gains it supports. Gains are checked against pre-aquired array of gains by rtljs for validity.

    Parameters

    • gain: number

      Measured in tenths of a dB, 115 means 11.5 dB.

    Returns void

  • Set the gain mode (automatic/manual) for the device. Manual gain mode must be enabled for the gain setter function to work.

    Parameters

    • manual: number

      Gain mode, 1 means manual gain mode shall be enabled.

    Returns void

  • Set the intermediate frequency gain for the device.

    Parameters

    • stage: number

      Intermediate frequency gain stage number (1 to 6 for E4000)

    • gain: number

      Measured in tenths of a dB, -30 means -3.0 dB.

    Returns void

  • Set crystal oscillator frequencies used for the RTL2832 and the tuner IC.

    Usually both ICs use the same clock. Changing the clock may make sense if you are applying an external clock to the tuner or to compensate the frequency (and samplerate) error caused by the original (cheap) crystal.

    NOTE: Call this function only if you fully understand the implications.

    Parameters

    • rtlFreq: number

      Frequency value used to clock the RTL2832 in Hz

    • tunerFreq: number

      Frequency value used to clock the tuner IC in Hz

    Returns void

    let xtal = device.getXtalFreq();

    // e.g.
    device.setXtalFreq(xtal.rtlFreq, xtal.tunerFreq);
  • Write the device EEPROM

    Parameters

    • data: number[]

      Buffer of data to be written

    • offset: number

      Address where the data should be written

    • len: number

      Length of the data

    Returns void