Tektronix Oscilloscope Data Logging in Python

Tektronix Oscilloscope Data Logging in Python

View the app user interface

Whether testing your power supply or monitoring a heartbeat, if you have an oscilloscope, Dash DAQ will help you control and read your instrument with user-friendly GUIs.

You can try out the app online.

This app was created alongside the function generator app, which we created in this post.

The setup

This Dash DAQ application facilitates control of the Tektronix TDS350 oscilloscope. We wrote a driver with PyVISA because of its versatility with various instruments, but modules such as PySerial can be used with the proper hardware.

Our setup required connecting the oscilloscope (bottom) to the computer using a GPIB-USB-HS adapter. We used a function generator for creating the input signal to be measured by the oscilloscope, and connected it to the computer with a  simple USB-B-to-USB connection.

The Dash DAQ app

The first step is to import the  necessary libraries from Plotly’s dash libraries, general Python packages, and helper libraries, like the fgen_afg3021 and osc_tds350 modules. You also need the dash_daq library.

The app layout formats the oscilloscope display alongside the function generator display we created in another post. In this code, a graph is initialized with the oscilloscope data upon load:

To populate the graph, we use the get_data method from the osc_tds350 module to return a data dictionary with corresponding x and y arrays to be displayed. This get_data method is repeatedly called by using a Dash callback with Interval, a function within the dash_core_components module.

An Interval can be defined with the interval and n_intervals properties, which represent the time between each update and the starting interval number, respectively.

Reminiscent of the Graph object above, the update-oscope callback returns a figure object, populated via get_data, which updates at every 2,000 millisecond interval (whenever the user changes Run #, introduced later).

This graph view also features a tab system to allow users to view multiple runs, or figures, generated by the Tektronix function generator.

With the new_tabs callback, users can add new runs to visualize different waveforms. Though the app is initialized with only one tab, users can add tabs in the GUI using the “+” icon above the graph. Clicking on a tab in the GUI will switch between run visualizations.

In this Dash app, we created an oscilloscope logging system which polls from a Tektronix TDS350 device. By utilizing Dash DAQ components like those in the in the function generating aspect of this Python program, users can easily interface their hardware devices.

You can play with the demo version of this app.

Purchase a Dash DAQ license to access the full source code for this app and others, and start taking advantage of reliable, logical components that resemble your in-lab hardware.