Expand description
rfe is a Rust library for communicating with
RF Explorer spectrum analyzers and signal
generators over a USB virtual serial port.
It provides high-level device types for RF Explorer hardware and lower-level building blocks for similar serial devices that use the same message container pattern.
§Connecting to an RF Explorer
rfe can search for an attached RF Explorer without knowing its port name or
baud rate. It tries USB serial ports with the VID and PID used by the RF
Explorer’s Silicon Labs CP210x USB-to-UART bridge.
use rfe::{SignalGenerator, SpectrumAnalyzer};
let spectrum_analyzer =
SpectrumAnalyzer::connect().expect("RF Explorer spectrum analyzer should be connected");
let signal_generator =
SignalGenerator::connect().expect("RF Explorer signal generator should be connected");You can also connect to a known serial port and baud rate.
use rfe::{SignalGenerator, SpectrumAnalyzer};
let spectrum_analyzer =
SpectrumAnalyzer::connect_with_name_and_baud_rate("COM2", 500_000)?;
let signal_generator =
SignalGenerator::connect_with_name_and_baud_rate("COM1", 500_000)?;§Collecting spectrum analyzer sweeps
rfe provides three APIs for reading spectrum analyzer sweeps.
§Waiting for the next sweep
SpectrumAnalyzer::wait_for_next_sweep() blocks until the device reports a
new sweep or the timeout elapses.
use rfe::SpectrumAnalyzer;
let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
let sweep = rfe.wait_for_next_sweep()?;
println!("{:?}", sweep);§Reading the latest cached sweep
SpectrumAnalyzer::sweep() returns the most recently measured sweep, or
None if no sweep has been received yet.
use rfe::SpectrumAnalyzer;
let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
let sweep = rfe.sweep();§Receiving sweeps with a callback
SpectrumAnalyzer::set_sweep_callback() registers a callback that runs on a
separate thread whenever a sweep is received.
use rfe::SpectrumAnalyzer;
let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
rfe.set_sweep_callback(|sweep, start_freq, stop_freq| {
println!(
"Received sweep from {}-{} MHz",
start_freq.as_mhz(),
stop_freq.as_mhz()
);
println!("{sweep:?}");
});§Generating a signal with an RF Explorer Signal Generator
use rfe::{
signal_generator::{Attenuation, PowerLevel, SignalGenerator},
Frequency,
};
let rfe = SignalGenerator::connect().expect("RF Explorer should be connected");
rfe.start_cw(Frequency::from_mhz(2412), Attenuation::Off, PowerLevel::Low)?;Re-exports§
pub use signal_generator::SignalGenerator;pub use spectrum_analyzer::SpectrumAnalyzer;
Modules§
- signal_
generator - RF Explorer signal generator types and commands.
- spectrum_
analyzer - RF Explorer spectrum analyzer types and commands.
Structs§
- Device
- Low-level serial device wrapper for RF Explorer-like devices.
- Frequency
- Frequency value stored internally in hertz.
- Screen
Data - Monochrome LCD screen capture from an RF Explorer device.
Enums§
- Connection
Error - Error returned while opening or initializing a device connection.
- Error
- Error returned by high-level RF Explorer operations.
- Message
Parse Error - Error returned when parsing a device message fails.
Traits§
- Message
Container - Storage and synchronization contract for messages read by
Device.
Functions§
- is_
driver_ installed - Checks if a driver for the RF Explorer is installed.
- port_
names - Returns the names of serial ports with the VID and PID of an RF Explorer.
Type Aliases§
- Connection
Result - Result type returned while opening or initializing a device connection.
- Result
- Result type returned by high-level RF Explorer operations.