Tektronix data in Python

Screenshot of python code for viewing and saving data from Tektronix scopes.

Screenshot of python code for viewing and saving data from Tektronix scopes.

In the Photonics and Quantum Optics lab, I’ve made open-source a high priority. With that in mind, we’ve written software to interface with many of our instruments. We also rely on github for version control and dissemination of our code. I’m particularly happy with a small application that pulls data from a Tektronix oscilloscope (tested on TDS1000 & 2000 models). This is my first python GUI app, despite having worked in python quite heavily for the past 12+ years. If you are interested, the work-in-progress code is available and should work for a Tek scope plugged in to USB on a linux host. I can’t promise it works on other platforms.

Here is a partial list of the requirements:

  • Python
  • numpy
  • matplotlib
  • wxPython
  • python-usbtmc

All but the last are fairly standard for scientific use of python. The last can be installed by your package manager. In Fedora, run

yum install python-matplotlib-wx

and that should ensure that you have all but the last of these components installed. I used the python package manager “pip” to install the usbtmc package:

pip install python-usbtmc

Credit for this project also goes to Eli Bendersky for an awesome example that got me 90% through this process.

4 thoughts on “Tektronix data in Python

  1. I get an error when I run the code:
    ./TekScope.py –help
    TEKTRONIX,MSO2024,C000276,CF:91.1CT FV:v1.25 DPO2EMBD:V1.00 DPO2COMP:V1.00

    Traceback (most recent call last):
    File “./TekScope.py”, line 30, in
    ch1data = test.get_data(“CH1”)
    File “instrument.py”, line 68, in get_data
    data = self.read_data()
    File “instrument.py”, line 58, in read_data
    return numpy.frombuffer(rawdata[6:-1], ‘i2’)
    ValueError: buffer size must be a multiple of element size

    • The MSO2024 must have a different length of raw buffer (probably has a longer data length. I would suggest adding “print rawdata” right before line 58 (in the “read_data” function. Then post what that returns. The scope I have puts out 5 bytes that indicate the length of the raw data stream, then the raw data, then a stop character. Line 58 drops all of these bytes except the actual data. Yours is probably returning a different length and/or a different encoding. If I cab track down a MSO programmers guide, I’ll let you know how to modify the code.

      • Another quick thought, I have the instrument.py code read 9000 bytes because that is more than any of our instruments send. You may have to increase that since it looks like the MSO record length is quite long: up to 1,250,000 data points (2500000 bytes for the max data width).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s