Skip to content

Python Example USB 1

Julian edited this page Jun 25, 2021 · 16 revisions

This example shows how easily you can drive a RF Explorer Spectrum Analyzer using the Python library. This is a very simple, “Hello World” equivalent example to understand how RF Explorer Python library works.

What it does

Initializes the RF module, then request configuration details and check for peak signal value in Amplitude and Frequency within the default RF scanning range.

It keeps scanning for 10 seconds then program automatically close.

How to run it

  • Install Python 3.5 or later, for more details visit www.python.org - there is no need to uninstall other versions of python, as several python versions can live together as long as you call the right one for the examples.
  • Install pySerial
  • Install RFExplorer for Python library
  • Depending on your OS version, you may need to install Silabs CP210x drivers. Most modern Linux distro and Windows version come with it installed, but Mac need specific install. Check Windows and MacOS driver troubleshooting articles.
  • Download the example from GITHUB repository link

Open a terminal or command line in your OS and run

python3.5 RFE_Example_USB_1.py

Expected results

As depicted below (using Windows as example), you will get automatic connection to the USB device using a specific COM port name. Other OS will return different port names.

  • Firmware version of the connected RF Explorer device

  • Active connection at 500,000 baud

  • Some information may depend on the specific device connected and firmware version installed

  • This example is available to test behavior of Spectrum Analyzer or Signal Generator so depending on the device connected the results will be differents.

    • Spectrum Analyzer: receiving data scan, with 10 seconds activity displaying default range. For the sake of simplicity, this example does not change default settings defined as 1.180 – 1.220GHz.

    • Signal Generator: generating CW signal during some seconds with specific power and frequency. Note: you should always run this examples with a 50 ohms load into the active RF connector.

Detailed source code description

The serial port is automatically detected by using SERIALPORT = None as the first argument of objRFE.ConnectPort(SERIALPORT, BAUDRATE) call. By specifying a explicit port name, the library will not use autodetection but will try to connect to the specified port instead.

Then RF Explorer device is reset with objRFE.SendCommand("r") to start fresh configuration, this is actually optional step.

The call to objRFE.SendCommand_RequestConfigData() makes the RF Explorer device to send configuration back, and start the sweep scan process.

The final step is completed with a while loop, running for 10 seconds (although you can easily change that to run forever, or for a different timeframe)

Clone this wiki locally