### Install RF Explorer for Python Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Install the library using pip. Ensure Python 3.5+ and pySerial are installed. Use `sudo` on Linux/Mac and an Administrator Command Prompt on Windows. ```bash # Linux / Mac / Raspberry Pi sudo pip3 install RFExplorer ``` ```bash # Windows (Administrator Command Prompt) pip install RFExplorer ``` ```bash # Upgrade pip install RFExplorer --upgrade ``` -------------------------------- ### Install RFExplorer Library on Windows Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Installing-RFExplorer-Python-library Execute this command in a Command Prompt opened as Administrator to install the RFExplorer library on Windows. pySerial and Python 3.5+ are required. ```bash pip install RFExplorer ``` -------------------------------- ### Install RFExplorer Library on Linux/Mac/Unix Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Installing-RFExplorer-Python-library Use this command to install the RFExplorer library on Linux, Mac, or Unix systems. Ensure you have Python 3.5 or later and pySerial installed. ```bash sudo pip3 install RFExplorer ``` -------------------------------- ### Initialize and Scan RF Explorer IoT Module Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-Example-IoT-1 This snippet initializes the RF Explorer IoT module, connects to the serial port (auto-detected), requests configuration data, and performs a 10-second scan. Ensure you have the RF Explorer Python libraries installed and run with superuser privileges. ```python import RPi.GPIO as GPIO import time import sys import os # Add the RFE_IoT directory to the Python path sys.path.append(os.path.abspath('../../../')) from RFE_IoT import RFE_IoT # --- Configuration --- # Set SERIALPORT to None to use automatic detection SERIALPORT = None BAUDRATE = 500000 # --- Main --- # Initialize RF Explorer IoT object objRFE = RFE_IoT() # Reset the IoT module by hardware # True = Reset, False = Do not reset objRFE.ResetIOT_HW(True) # Connect to the RF Explorer IoT module # If SERIALPORT is None, the library will try to detect the port automatically # If connection fails, an exception will be raised if objRFE.ConnectPort(SERIALPORT, BAUDRATE) == False: print("Error connecting to RF Explorer IoT module") sys.exit(1) print("RF Explorer IoT module connected!") # Request configuration data from the module # This command also starts the sweep scan process objRFE.SendCommand_RequestConfigData() # Wait a moment for the command to be processed time.sleep(0.5) # Get configuration data config = objRFE.GetConfigData() # Print configuration details print("Firmware version: %s" % config['firmware']) print("Active connection: %s baud" % config['baudrate']) print("Device serial number: %s" % config['serial']) print("\nStarting RF scan for 10 seconds...") # Start time for the scan startTime = time.time() # Loop for 10 seconds to scan for signals while (time.time() - startTime) < 10: # Get the latest scan data scanData = objRFE.GetScanData() # Check if scanData is valid if scanData is not None: # Print peak amplitude and frequency print("\tPeak Amplitude: %.2f dBm, Frequency: %.2f MHz" % (scanData['amplitude'], scanData['frequency'])) # Small delay to avoid flooding the console time.sleep(0.05) print("\nScan finished.") # Disconnect from the RF Explorer IoT module objRFE.DisconnectPort() print("RF Explorer IoT module disconnected.") sys.exit(0) ``` -------------------------------- ### Initialize RFECommunicator Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Instantiate the main communicator object. The background receive thread starts automatically. Remember to close the communicator when done to stop the thread and release the port. ```python import RFExplorer from RFExplorer import RFE_Common # Create communicator (starts background thread automatically) objRFE = RFExplorer.RFECommunicator() # Optional: disable auto-configuration on connect objRFE.AutoConfigure = False # Always close when done to cleanly stop thread and port objRFE.Close() objRFE = None ``` -------------------------------- ### Update RFExplorer Library on Windows Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Installing-RFExplorer-Python-library To upgrade the RFExplorer library on Windows, use the '--upgrade' flag with the installation command. This ensures you have the latest version. ```bash pip install RFExplorer --upgrade ``` -------------------------------- ### Update RFExplorer Library on Linux/Mac/Unix Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Installing-RFExplorer-Python-library Upgrade the RFExplorer library on Linux, Mac, or Unix systems by adding the '--upgrade' flag to the installation command. This fetches the latest version. ```bash sudo pip3 install RFExplorer --upgrade ``` -------------------------------- ### Configure and Scan Multiple Frequency Ranges with RF Explorer IoT Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-Example-IoT-2 This Python script configures the RF Explorer IoT device to scan multiple, sequential frequency ranges. It iteratively updates the device's scan start and stop frequencies, captures a sweep for each range, and displays the peak signal amplitude. Ensure you run this script with superuser privileges on a Raspberry Pi. ```python import sys import time import serial from RFExplorer_IO import RFExplorerIO # --- Configuration --- # Use the correct serial port for your Raspberry Pi # For Raspberry Pi 3, 4, Zero W, use /dev/ttyAMA0 # For Raspberry Pi 1, 2, use /dev/ttyAMA0 or /dev/ttyS0 # For other systems, check your serial port name SERIAL_PORT = "/dev/ttyAMA0" BAUD_RATE = 500000 # 500k # Define the frequency ranges to scan (in MHz) # Max frequency is 900 MHz for this model SCAN_RANGES = [ (500, 600), # 500 MHz to 600 MHz (600, 700), # 600 MHz to 700 MHz (700, 800), # 700 MHz to 800 MHz (800, 900) # 800 MHz to 900 MHz ] # --- Main Script --- def main(): try: # Initialize RF Explorer connection objRFE = RFExplorerIO(SERIAL_PORT, BAUD_RATE) print("RF Explorer connected.") # Get and display device info firmware = objRFE.GetFirmwareVersion() print(f"Firmware: {firmware}") serial_num = objRFE.GetSerialNumber() print(f"Serial Number: {serial_num}") # Iterate through defined scan ranges for start_freq, stop_freq in SCAN_RANGES: print(f"\nConfiguring scan for {start_freq} MHz to {stop_freq} MHz...") # Update device configuration with new frequency range # This command reconfigures the device scan range objRFE.UpdateDeviceConfig(start_freq, stop_freq) # Wait a moment for the device to apply the new configuration time.sleep(0.5) # Perform a single sweep and get the peak amplitude # The sweep data is returned as a list of tuples (frequency, amplitude) sweep_data = objRFE.GetSweepData() if sweep_data: # Find the maximum amplitude in the sweep data peak_amplitude = max(sweep_data, key=lambda item: item[1]) print(f" Peak amplitude: {peak_amplitude[1]:.2f} dBm at {peak_amplitude[0]:.2f} MHz") else: print(" No sweep data received.") # Small delay before reconfiguring for the next range time.sleep(0.5) print("\nFinished scanning all ranges.") except serial.SerialException as e: print(f"Error opening or reading from serial port {SERIAL_PORT}: {e}") print("Ensure the serial port is correct and you have permissions (use sudo).") sys.exit(1) except Exception as e: print(f"An unexpected error occurred: {e}") sys.exit(1) finally: # Ensure the connection is closed properly if 'objRFE' in locals() and objRFE.IsConnected(): objRFE.CloseConnection() print("RF Explorer connection closed.") if __name__ == "__main__": main() ``` -------------------------------- ### Get Channel Power and Save Sweep Data Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Reads the channel power and saves a single sweep to a CSV file. Ensure the device is connected and configured before use. ```python channel_power = sweep.GetChannelPowerDBM() print("Channel power: {:.1f} dBm/span".format(channel_power)) ``` ```python sweep.SaveFileCSV("/tmp/single_sweep.csv", ",", None) ``` -------------------------------- ### Connect and Generate CW Signal with RF Explorer (Signal Generator) Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-Example-USB-1 Initializes the RF Explorer and sets a specific frequency and power to generate a Continuous Wave (CW) signal for 5 seconds. Assumes a 50 ohms load is connected. Designed for Signal Generator mode. ```python import time from RFExplorer import RFExplorer # --- Configuration --- SERIALPORT = None # Use None for auto-detection BAUDRATE = 500000 # --- Main --- # Create RF Explorer object objRFE = RFExplorer() # Connect to the RF Explorer device if objRFE.ConnectPort(SERIALPORT, BAUDRATE): print("Connected to RF Explorer!") # Reset device to start fresh configuration objRFE.SendCommand("r") time.sleep(1) # Set frequency and power, then generate CW signal # Example: 100 MHz, -10 dBm objRFE.SendCommand_SetFrequency(100000000) objRFE.SendCommand_SetPower(-10) objRFE.SendCommand("G") # Generate CW signal time.sleep(1) # Keep generating signal for 5 seconds start_time = time.time() while (time.time() - start_time) < 5: # Read data from RF Explorer (optional, to check status) data = objRFE.Read() if data: # Process data if needed pass time.sleep(0.1) # Stop signal generation objRFE.SendCommand("S") # Stop signal generation time.sleep(1) # Disconnect from the device objRFE.DisconnectPort() print("Disconnected from RF Explorer.") else: print("Failed to connect to RF Explorer.") ``` -------------------------------- ### Connect and Scan with RF Explorer (Spectrum Analyzer) Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-Example-USB-1 Initializes the RF Explorer, requests configuration, and scans for peak signals for 10 seconds. Automatically detects the serial port if not specified. Designed for Spectrum Analyzer mode. ```python import time from RFExplorer import RFExplorer # --- Configuration --- SERIALPORT = None # Use None for auto-detection BAUDRATE = 500000 # --- Main --- # Create RF Explorer object objRFE = RFExplorer() # Connect to the RF Explorer device if objRFE.ConnectPort(SERIALPORT, BAUDRATE): print("Connected to RF Explorer!") # Reset device to start fresh configuration objRFE.SendCommand("r") time.sleep(1) # Request configuration data and start sweep scan objRFE.SendCommand_RequestConfigData() time.sleep(1) # Keep scanning for 10 seconds start_time = time.time() while (time.time() - start_time) < 10: # Read data from RF Explorer data = objRFE.Read() if data: # Process data (e.g., print peak signal) print(f"Amplitude: {data['peak_amplitude']} dBm, Frequency: {data['peak_frequency']} Hz") time.sleep(0.1) # Disconnect from the device objRFE.DisconnectPort() print("Disconnected from RF Explorer.") else: print("Failed to connect to RF Explorer.") ``` -------------------------------- ### Wait for Device Model Initialization Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-library-reference This code snippet demonstrates how to wait for the RF Explorer device to report its model information. It repeatedly calls the ProcessReceivedString function until the device model is no longer 'MODEL_NONE', ensuring that configuration data is available before proceeding. ```python while(objRFE.ActiveModel == RFExplorer.RFE_Common.eModel.MODEL_NONE): objRFE.ProcessReceivedString(True) #Process the received configuration ``` -------------------------------- ### Import RF Explorer Library Source: https://github.com/rfexplorer/rfexplorer-for-python/wiki/Python-library-reference Import the RF Explorer library into your Python script to access its functionalities. This is the first step before creating any RF Explorer objects. ```python import RFExplorer ``` -------------------------------- ### ConnectPort - Open Serial Connection Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Establishes a serial connection to a specified port with a given baud rate. Supports auto-detection if no specific port is provided. ```APIDOC ## ConnectPort ### Description Connects to a specific serial port at the given baud rate. Pass `None` as the port name to auto-select when only one device is connected. Returns `True` if the port was successfully opened. ### Method `ConnectPort(port_name, baud_rate)` ### Parameters - **port_name** (string or None) - The name of the serial port to connect to. Use `None` to auto-detect. - **baud_rate** (integer) - The baud rate for the serial connection (e.g., 500000). ### Returns - `True` if the connection was successful, `False` otherwise. ### Usage ```python import RFExplorer import time SERIALPORT = None # None = autodetect BAUDRATE = 500000 # Standard RF Explorer baud rate (also 2400 for IoT) objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() if objRFE.ConnectPort(SERIALPORT, BAUDRATE): print("Connected to: " + objRFE.PortName) # Example Output: # Connected: /dev/ttyUSB0, 500000 bauds else: print("Connection failed") ``` ``` -------------------------------- ### Signal Generator Commands Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt This section details how to configure and control the signal generator for CW tones, frequency sweeps, and amplitude sweeps using the `RFExplorer` library. ```APIDOC ## Signal Generator Commands — CW and Frequency/Amplitude Sweep Configure generator properties then call the corresponding `SendCommand_Generator*` methods to start/stop CW tones, frequency sweeps, or amplitude sweeps. ### CW signal at 500 MHz Generates a Continuous Wave (CW) signal at a specified frequency and power level. #### Configuration - `objRFE.RFGenCWFrequencyMHZ` (float): Set the center frequency in MHz. - `objRFE.RFGenHighPowerSwitch` (bool): Enable or disable high power mode. - `objRFE.RFGenPowerLevel` (int): Set the power level (0-3). #### Method ```python objRFE.SendCommand_GeneratorCW() ``` #### Example ```python objRFE.RFGenCWFrequencyMHZ = 500.0 objRFE.RFGenHighPowerSwitch = False objRFE.RFGenPowerLevel = 3 # 0-3 power levels estimated_dbm = objRFE.GetSignalGeneratorEstimatedAmplitude(500.0) print("CW: 500 MHz at ~{:.1f} dBm".format(estimated_dbm)) objRFE.SendCommand_GeneratorCW() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() ``` ### Frequency sweep 400–450 MHz, 25 steps, 200 ms dwell Performs a frequency sweep across a defined range with a specified number of steps and dwell time. #### Configuration - `objRFE.RFGenStartFrequencyMHZ` (float): Start frequency in MHz. - `objRFE.RFGenStopFrequencyMHZ` (float): Stop frequency in MHz. - `objRFE.RFGenSweepSteps` (int): Number of steps in the sweep. - `objRFE.RFGenStepWaitMS` (int): Dwell time in milliseconds per step. - `objRFE.RFGenHighPowerSwitch` (bool): Enable or disable high power mode. - `objRFE.RFGenPowerLevel` (int): Set the power level (0-3). #### Method ```python objRFE.SendCommand_GeneratorSweepFreq() ``` #### Example ```python objRFE.RFGenStartFrequencyMHZ = 400.0 objRFE.RFGenStopFrequencyMHZ = 450.0 objRFE.RFGenSweepSteps = 25 objRFE.RFGenStepWaitMS = 200 objRFE.RFGenHighPowerSwitch = False objRFE.RFGenPowerLevel = 0 print("Frequency sweep: 400–450 MHz, 25 steps") objRFE.SendCommand_GeneratorSweepFreq() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() ``` ### Amplitude sweep at fixed 500 MHz Performs an amplitude sweep at a fixed frequency, varying the power level across a defined range. #### Configuration - `objRFE.RFGenCWFrequencyMHZ` (float): The fixed frequency in MHz for the amplitude sweep. - `objRFE.RFGenStartHighPowerSwitch` (bool): Enable or disable high power mode for the start of the sweep. - `objRFE.RFGenStartPowerLevel` (int): The starting power level (0-3). - `objRFE.RFGenStopHighPowerSwitch` (bool): Enable or disable high power mode for the end of the sweep. - `objRFE.RFGenStopPowerLevel` (int): The ending power level (0-3). - `objRFE.RFGenSweepSteps` (int): Number of steps in the amplitude sweep. - `objRFE.RFGenStepWaitMS` (int): Dwell time in milliseconds per step. #### Method ```python objRFE.SendCommand_GeneratorSweepAmplitude() ``` #### Example ```python objRFE.RFGenCWFrequencyMHZ = 500.0 objRFE.RFGenStartHighPowerSwitch = False objRFE.RFGenStartPowerLevel = 0 objRFE.RFGenStopHighPowerSwitch = True objRFE.RFGenStopPowerLevel = 3 objRFE.RFGenSweepSteps = 5 objRFE.RFGenStepWaitMS = 500 print("Amplitude sweep: power levels 0–3 in 5 steps") objRFE.SendCommand_GeneratorSweepAmplitude() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() ``` ``` -------------------------------- ### SendCommand / SendCommand_RequestConfigData - Send Device Commands Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Allows sending raw UART commands to the RF Explorer device. Includes convenience wrappers for common commands and a crucial method to request device configuration data. ```APIDOC ## SendCommand / SendCommand_RequestConfigData ### Description `SendCommand(sCommand)` formats and transmits a raw UART command by prepending the `#` header and byte-length prefix. Convenience wrappers cover the most common commands. Always call `SendCommand_RequestConfigData()` after connecting to trigger the device to return its configuration. ### Methods - `SendCommand(sCommand)`: Sends a raw command string. - `SendCommand_RequestConfigData()`: Requests the device to send its configuration data. - `SendCommand_Hold()`: Pauses data transmission from the device. - `SendCommand_SetMaxHold()`: Sets the device to Max Hold mode. - `SendCommand_Realtime()`: Sets the device to Normal (real-time) mode. - `SendCommand_ScreenOFF()`: Turns off the device's LCD screen. - `SendCommand_ScreenON()`: Turns on the device's LCD screen. - `SendCommand_WifiAnalyzerMode2_4GHZ()`: Switches the device to WiFi 2.4GHz analyzer mode. - `ResetInternalBuffers()`: Clears the internal Max Hold cache. ### Usage ```python import RFExplorer import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) # Reset device, then wait for it to signal reset completion objRFE.SendCommand("r") while objRFE.IsResetEvent: pass time.sleep(8) # Wait for device to fully stabilize after reset # Request configuration — device will start sending sweeps objRFE.SendCommand_RequestConfigData() # Other common commands: objRFE.SendCommand_Hold() # Pause data dump objRFE.SendCommand_SetMaxHold() # Calculator: Max Hold mode objRFE.SendCommand_Realtime() # Calculator: Normal (real-time) mode objRFE.SendCommand_ScreenOFF() # Turn off LCD to save power objRFE.SendCommand_ScreenON() # Re-enable LCD objRFE.SendCommand_WifiAnalyzerMode2_4GHZ() # Switch to WiFi 2.4GHz mode objRFE.ResetInternalBuffers() # Clear internal Max Hold cache ``` ``` -------------------------------- ### Configure and Control RFGen Signal Generator Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Sets up and controls the RFE6GEN signal generator for CW, frequency sweep, and amplitude sweep modes. Requires an RFE6GEN device and proper initialization. ```python import RFExplorer from RFExplorer import RFE_Common import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") while objRFE.IsResetEvent: pass time.sleep(3) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) if objRFE.IsGenerator(): # Retrieve internal calibration data objRFE.SendCommand("Cq") cal = objRFE.GetRFE6GENCal() while cal.GetCalSize() < 0: objRFE.ProcessReceivedString(True) # --- CW signal at 500 MHz --- objRFE.RFGenCWFrequencyMHZ = 500.0 objRFE.RFGenHighPowerSwitch = False objRFE.RFGenPowerLevel = 3 # 0-3 power levels estimated_dbm = objRFE.GetSignalGeneratorEstimatedAmplitude(500.0) print("CW: 500 MHz at ~{:.1f} dBm".format(estimated_dbm)) objRFE.SendCommand_GeneratorCW() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() # --- Frequency sweep 400–450 MHz, 25 steps, 200 ms dwell --- objRFE.RFGenStartFrequencyMHZ = 400.0 objRFE.RFGenStopFrequencyMHZ = 450.0 objRFE.RFGenSweepSteps = 25 objRFE.RFGenStepWaitMS = 200 objRFE.RFGenHighPowerSwitch = False objRFE.RFGenPowerLevel = 0 print("Frequency sweep: 400–450 MHz, 25 steps") objRFE.SendCommand_GeneratorSweepFreq() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() # --- Amplitude sweep at fixed 500 MHz --- objRFE.RFGenCWFrequencyMHZ = 500.0 objRFE.RFGenStartHighPowerSwitch = False objRFE.RFGenStartPowerLevel = 0 objRFE.RFGenStopHighPowerSwitch = True objRFE.RFGenStopPowerLevel = 3 objRFE.RFGenSweepSteps = 5 objRFE.RFGenStepWaitMS = 500 print("Amplitude sweep: power levels 0–3 in 5 steps") objRFE.SendCommand_GeneratorSweepAmplitude() time.sleep(5) objRFE.SendCommand_GeneratorRFPowerOFF() objRFE.Close() ``` -------------------------------- ### Connect to Serial Port Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Establish a serial connection to a specific port and baud rate. Auto-select the port if `None` is provided and only one device is connected. Returns `True` on successful connection. ```python import RFExplorer import time SERIALPORT = None # None = autodetect BAUDRATE = 500000 # Standard RF Explorer baud rate (also 2400 for IoT) objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() if objRFE.ConnectPort(SERIALPORT, BAUDRATE): print("Connected to: " + objRFE.PortName) # Output: "Connected: /dev/ttyUSB0, 500000 bauds" else: print("Connection failed") ``` -------------------------------- ### Unit Conversion Utilities Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Provides helper functions for converting between common RF power units (mW, dBm, Watt, dBuV) and for retrieving model names from enums and vice-versa. ```python import RFExplorer # mW ↔ dBm dbm = RFExplorer.Convert_mW_2_dBm(1.0) # 0.0 dBm mw = RFExplorer.Convert_dBm_2_mW(0.0) # 1.0 mW print("1 mW =", dbm, "dBm") # 1 mW = 0.0 dBm print("0 dBm =", mw, "mW") # 0 dBm = 1.0 mW # Watt ↔ dBm dbm = RFExplorer.Convert_Watt_2_dBm(1.0) # 30.0 dBm watt = RFExplorer.Convert_dBm_2_Watt(30.0) # 1.0 W print("1 W =", dbm, "dBm") # 1 W = 30.0 dBm # dBm ↔ dBµV dbuv = RFExplorer.Convert_dBm_2_dBuV(-107.0) # 0.0 dBµV dbm = RFExplorer.Convert_dBuV_2_dBm(0.0) # -107.0 dBm # Model name helpers text = RFExplorer.GetModelTextFromEnum(RFExplorer.RFE_Common.eModel.MODEL_WSUB3G.value) print("Model:", text) # Model: WSUB3G model = RFExplorer.GetModelEnumFromText("6G") print("Enum:", model) # Enum: eModel.MODEL_6G ``` -------------------------------- ### Send Device Commands Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Send raw UART commands or use convenience wrappers. Always call `SendCommand_RequestConfigData()` after connecting to initiate data transmission. Includes commands for reset, pausing, mode changes, and screen control. ```python import RFExplorer import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) # Reset device, then wait for it to signal reset completion objRFE.SendCommand("r") while objRFE.IsResetEvent: pass time.sleep(8) # Wait for device to fully stabilize after reset # Request configuration — device will start sending sweeps objRFE.SendCommand_RequestConfigData() # Other common commands: objRFE.SendCommand_Hold() # Pause data dump objRFE.SendCommand_SetMaxHold() # Calculator: Max Hold mode objRFE.SendCommand_Realtime() # Calculator: Normal (real-time) mode objRFE.SendCommand_ScreenOFF() # Turn off LCD to save power objRFE.SendCommand_ScreenON() # Re-enable LCD objRFE.SendCommand_WifiAnalyzerMode2_4GHZ() # Switch to WiFi 2.4GHz mode objRFE.ResetInternalBuffers() # Clear internal Max Hold cache ``` -------------------------------- ### Configure Sweep Resolution with RF Explorer Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Sets the number of data points per sweep for RF Explorer devices. Use `SendCommand_SweepDataPoints` for standard resolution and `SendCommand_SweepDataPointsEx` for high-resolution models. Ensure the device is connected and configured before sending commands. ```python import RFExplorer from RFExplorer import RFE_Common import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") time.sleep(8) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) # Standard resolution: 112 to 4096, must be multiple of 16 objRFE.SendCommand_SweepDataPoints(512) time.sleep(0.5) # High resolution (PLUS/MWSUB3G models only): up to 65536 if objRFE.IsHighResAvailable: objRFE.SendCommand_SweepDataPointsEx(8192) time.sleep(0.5) print("High-res sweep: 8192 data points configured") # Wait for new sweep with updated resolution while objRFE.SweepData.Count < 1: objRFE.ProcessReceivedString(True) sweep = objRFE.SweepData.GetData(0) print("Data points in sweep:", sweep.TotalDataPoints) objRFE.Close() ``` -------------------------------- ### Unit Conversion Utilities Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Provides module-level helper functions for converting between common RF power units and for retrieving model information. ```APIDOC ## Unit Conversion Utilities Module-level helper functions for converting between common RF power units and for retrieving model information. ### mW ↔ dBm Conversion Converts between milliwatts (mW) and dBm. #### Functions - `RFExplorer.Convert_mW_2_dBm(mW)`: Converts milliwatts to dBm. - `RFExplorer.Convert_dBm_2_mW(dBm)`: Converts dBm to milliwatts. #### Example ```python dbm = RFExplorer.Convert_mW_2_dBm(1.0) # 0.0 dBm mw = RFExplorer.Convert_dBm_2_mW(0.0) # 1.0 mW print("1 mW =", dbm, "dBm") # 1 mW = 0.0 dBm print("0 dBm =", mw, "mW") # 0 dBm = 1.0 mW ``` ### Watt ↔ dBm Conversion Converts between Watts and dBm. #### Functions - `RFExplorer.Convert_Watt_2_dBm(watt)`: Converts Watts to dBm. - `RFExplorer.Convert_dBm_2_Watt(dBm)`: Converts dBm to Watts. #### Example ```python dbm = RFExplorer.Convert_Watt_2_dBm(1.0) # 30.0 dBm watt = RFExplorer.Convert_dBm_2_Watt(30.0) # 1.0 W print("1 W =", dbm, "dBm") # 1 W = 30.0 dBm ``` ### dBm ↔ dBµV Conversion Converts between dBm and dBµV. #### Functions - `RFExplorer.Convert_dBm_2_dBuV(dBm)`: Converts dBm to dBµV. - `RFExplorer.Convert_dBuV_2_dBm(dbuv)`: Converts dBµV to dBm. #### Example ```python dbuv = RFExplorer.Convert_dBm_2_dBuV(-107.0) # 0.0 dBµV dbm = RFExplorer.Convert_dBuV_2_dBm(0.0) # -107.0 dBm ``` ### Model Name Helpers Retrieves the string representation of a model enum or the enum value from a model name string. #### Functions - `RFExplorer.GetModelTextFromEnum(enum_value)`: Returns the string name for a given model enum value. - `RFExplorer.GetModelEnumFromText(model_name)`: Returns the model enum for a given model name string. #### Example ```python text = RFExplorer.GetModelTextFromEnum(RFExplorer.RFE_Common.eModel.MODEL_WSUB3G.value) print("Model:", text) # Model: WSUB3G model = RFExplorer.GetModelEnumFromText("6G") print("Enum:", model) # Enum: eModel.MODEL_6G ``` ``` -------------------------------- ### RFESweepData - Read Amplitude and Frequency per Data Point Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Each RFESweepData object stores one sweep. Use GetAmplitude_DBM, GetFrequencyMHZ, GetPeakDataPoint, GetMinDataPoint, and GetChannelPowerDBM to analyze individual sweeps. ```python import RFExplorer from RFExplorer import RFE_Common import time, math objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") time.sleep(8) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) while objRFE.SweepData.Count < 1: objRFE.ProcessReceivedString(True) sweep = objRFE.SweepData.GetData(objRFE.SweepData.Count - 1) # Find and print the peak signal peak_idx = sweep.GetPeakDataPoint() peak_freq = sweep.GetFrequencyMHZ(peak_idx) peak_amp = sweep.GetAmplitude_DBM(peak_idx) print("Peak: {:.3f} MHz at {:.1f} dBm".format(peak_freq, peak_amp)) # Output: "Peak: 433.920 MHz at -42.5 dBm" # Print entire sweep as CSV for i in range(sweep.TotalDataPoints): freq = sweep.GetFrequencyMHZ(i) amp = sweep.GetAmplitude_DBM(i) print("{:.3f},{:.1f}".format(freq, amp)) ``` -------------------------------- ### Channel Power Measurement Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt This snippet demonstrates how to retrieve the channel power in dBm over the full span using the `GetChannelPowerDBM` method and save a sweep to a CSV file. ```APIDOC ## Channel power over the full span This operation retrieves the channel power in dBm across the entire frequency span. ### Method ```python channel_power = sweep.GetChannelPowerDBM() ``` ### Description Retrieves the measured channel power in dBm. ### Example ```python print("Channel power: {:.1f} dBm/span".format(channel_power)) ``` ## Save single sweep to CSV file This operation saves the current sweep data to a CSV file. ### Method ```python sweep.SaveFileCSV(file_path, delimiter, None) ``` ### Parameters - **file_path** (string): The path to the CSV file to save. - **delimiter** (string): The delimiter to use in the CSV file (e.g., "," or ";"). - **None**: Placeholder for potential future arguments. ### Example ```python sweep.SaveFileCSV("/tmp/single_sweep.csv", ",", None) ``` ``` -------------------------------- ### GetConnectedPorts - Discover Available Serial Ports Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Scans the system for available serial ports compatible with RF Explorer devices. Returns True if any valid ports are found, aiding in the connection process. ```APIDOC ## GetConnectedPorts ### Description Scans the system for available serial ports and populates the internal valid-ports list. On macOS, only SLAB USB driver ports are included. Returns `True` if at least one valid port is found. ### Method `GetConnectedPorts()` ### Returns - `True` if at least one valid port is found, `False` otherwise. ### Usage ```python import RFExplorer objRFE = RFExplorer.RFECommunicator() if objRFE.GetConnectedPorts(): print("Valid ports detected, ready to connect") else: print("No valid RF Explorer ports found") # Example Output: # Detected COM ports: # * /dev/ttyUSB0 # /dev/ttyUSB0 is a valid available port. # RF Explorer Valid Ports found: 1 - /dev/ttyUSB0 ``` ``` -------------------------------- ### SweepData / RFESweepDataCollection - Access Collected Sweeps Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt The RFESweepDataCollection accumulates sweeps. Use Count, GetData, MaxHoldData, GetAverage, and SaveFileCSV to access or persist spectrum data. ```python import RFExplorer from RFExplorer import RFE_Common import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") time.sleep(8) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) # Collect at least 5 sweeps while objRFE.SweepData.Count < 5: objRFE.ProcessReceivedString(True) # Access latest sweep latest = objRFE.SweepData.GetData(objRFE.SweepData.Count - 1) print("Sweeps in buffer:", objRFE.SweepData.Count) print("Capture time:", latest.CaptureTime) print("Start freq: {:.3f} MHz".format(latest.StartFrequencyMHZ)) print("Data points:", latest.TotalDataPoints) # Access Max Hold data across all collected sweeps maxHold = objRFE.SweepData.MaxHoldData if maxHold: print("Max Hold start freq: {:.3f} MHz".format(maxHold.StartFrequencyMHZ)) # Save all sweep data to CSV objRFE.SweepData.SaveFileCSV("/tmp/sweep_data.csv", ",", None) # Clear buffer objRFE.SweepData.CleanAll() objRFE.Close() ``` -------------------------------- ### UpdateDeviceConfig Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Reconfigures the spectrum analyzer's frequency range by sending a `C2-F:` command. This action clears the device's internal buffer and initiates sweeps across the new frequency range. Optional parameters allow setting amplitude display limits and the Resolution Bandwidth (RBW). ```APIDOC ## UpdateDeviceConfig — Reconfigure Spectrum Analyzer Frequency Range Sends a `C2-F:` command to change the active sweep span. The device clears its internal buffer and begins sending sweeps over the new range. Optionally specify amplitude display limits and RBW. ```python import RFExplorer import time import math objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") time.sleep(8) objRFE.SendCommand_RequestConfigData() from RFExplorer import RFE_Common while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) # Tune to 2.4 GHz WiFi band, -30 dBm top, -120 dBm bottom START_MHZ = 2400.0 STOP_MHZ = 2500.0 objRFE.UpdateDeviceConfig(START_MHZ, STOP_MHZ, fTopDBM=-30, fBottomDBM=-120) # Wait for the new config to take effect while True: objRFE.ProcessReceivedString(True) if math.fabs(objRFE.StartFrequencyMHZ - START_MHZ) <= 0.001: break print("Now scanning: {:.3f} - {:.3f} MHz".format( objRFE.StartFrequencyMHZ, objRFE.StopFrequencyMHZ)) objRFE.Close() ``` ``` -------------------------------- ### Format Serial Number Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Demonstrates how to format a raw serial number string into the standard xxxx-xxxx-xxxx-xxxx format using the DecorateSerialNumberRAWString method. ```APIDOC ## Format Serial Number ### Description Formats a raw serial number string into a human-readable format. ### Method ```python RFExplorer.DecorateSerialNumberRAWString(raw_serial_string) ``` ### Parameters - **raw_serial_string** (str) - Required - The raw serial number string from the device. ### Request Example ```python formatted = RFExplorer.DecorateSerialNumberRAWString("ABCD1234EFGH5678") print("Serial:", formatted) ``` ### Response Example ``` Serial: ABCD-1234-EFGH-5678 ``` ``` -------------------------------- ### Reset IoT Hardware Module via GPIO Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Resets the RF Explorer IoT module using Raspberry Pi's GPIO pins. Must be called before `ConnectPort()` when using IoT hardware. Sets baud rate to 500000 bps when `bMode` is True. ```python import RFExplorer from RFExplorer import RFE_Common import time from datetime import datetime # IoT-specific: reset the RF Explorer module via GPIO pins # bMode=True → 500000 bps, bMode=False → 2400 bps RFExplorer.RFECommunicator.ResetIOT_HW(True) objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() # On Raspberry Pi the IoT port is /dev/ttyAMA0 if objRFE.ConnectPort(None, 500000): while objRFE.IsResetEvent: pass time.sleep(3) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) startTime = datetime.now() last_count = 0 while (datetime.now() - startTime).seconds < 10: objRFE.ProcessReceivedString(True) if objRFE.SweepData.Count > last_count: last_count = objRFE.SweepData.Count sweep = objRFE.SweepData.GetData(last_count - 1) peak = sweep.GetPeakDataPoint() print("Peak: {:.3f} MHz {:.1f} dBm".format( sweep.GetFrequencyMHZ(peak), sweep.GetAmplitude_DBM(peak))) objRFE.Close() ``` -------------------------------- ### Discover Available Serial Ports Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Scan the system for available serial ports. This method populates the internal valid-ports list and returns `True` if at least one valid port is found. On macOS, only SLAB USB driver ports are included. ```python import RFExplorer objRFE = RFExplorer.RFECommunicator() if objRFE.GetConnectedPorts(): print("Valid ports detected, ready to connect") else: print("No valid RF Explorer ports found") # Output: "Detected COM ports:" # " * /dev/ttyUSB0" # "/dev/ttyUSB0 is a valid available port." # "RF Explorer Valid Ports found: 1 - /dev/ttyUSB0" ``` -------------------------------- ### Configure Sweep Data Points Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt Configures the number of data points per sweep. Supports standard resolution and high-resolution modes for specific models. ```APIDOC ## SendCommand_SweepDataPoints — Configure Sweep Resolution ### Description Sets the number of data points per sweep. `SendCommand_SweepDataPoints` accepts 16–4096 (multiples of 16); `SendCommand_SweepDataPointsEx` accepts 112–65536 for high-resolution PLUS and MWSUB3G models. ### Method ```python objRFE.SendCommand_SweepDataPoints(data_points) objRFE.SendCommand_SweepDataPointsEx(data_points) ``` ### Parameters #### `SendCommand_SweepDataPoints` - **data_points** (int) - Required - Number of data points for standard resolution sweeps. Must be between 16 and 4096, and a multiple of 16. #### `SendCommand_SweepDataPointsEx` - **data_points** (int) - Required - Number of data points for high-resolution sweeps. Must be between 112 and 65536. Available on PLUS and MWSUB3G models. ### Request Example ```python import RFExplorer from RFExplorer import RFE_Common import time objRFE = RFExplorer.RFECommunicator() objRFE.GetConnectedPorts() objRFE.ConnectPort(None, 500000) objRFE.SendCommand("r") time.sleep(8) objRFE.SendCommand_RequestConfigData() while objRFE.ActiveModel == RFE_Common.eModel.MODEL_NONE: objRFE.ProcessReceivedString(True) # Standard resolution: 112 to 4096, must be multiple of 16 objRFE.SendCommand_SweepDataPoints(512) time.sleep(0.5) # High resolution (PLUS/MWSUB3G models only): up to 65536 if objRFE.IsHighResAvailable: objRFE.SendCommand_SweepDataPointsEx(8192) time.sleep(0.5) print("High-res sweep: 8192 data points configured") # Wait for new sweep with updated resolution while objRFE.SweepData.Count < 1: objRFE.ProcessReceivedString(True) sweep = objRFE.SweepData.GetData(0) print("Data points in sweep:", sweep.TotalDataPoints) objRFE.Close() ``` ### Response #### Success Response Configuration is applied to the device. The number of data points in subsequent sweeps will reflect the configured value. #### Response Example ``` High-res sweep: 8192 data points configured Data points in sweep: 8192 ``` ``` -------------------------------- ### ResetIOT_HW — Raspberry Pi IoT Hardware Reset Source: https://context7.com/rfexplorer/rfexplorer-for-python/llms.txt This class method resets the RF Explorer IoT module via GPIO pins on a Raspberry Pi. It must be called before `ConnectPort()` when using IoT hardware. ```APIDOC ## ResetIOT_HW — Raspberry Pi IoT Hardware Reset Class method that uses RPi.GPIO to toggle the RF Explorer IoT module's reset and baud-rate select pins on a Raspberry Pi. Must be called before `ConnectPort()` when using IoT hardware. ### Method ```python RFExplorer.RFECommunicator.ResetIOT_HW(bMode) ``` ### Parameters - **bMode** (bool): If `True`, sets the baud rate to 500000 bps. If `False`, sets it to 2400 bps. ### Example ```python # IoT-specific: reset the RF Explorer module via GPIO pins # bMode=True → 500000 bps, bMode=False → 2400 bps RFExplorer.RFECommunicator.ResetIOT_HW(True) ``` ```