About a year ago, my new project requires a lot of data captured from the Tek oscilloscope. I started with doing the data capture with a USB drive. But it didn’t take long for me figured that I need some better way to do it. After years of working in engineering world, I have learned a good rule of thumb: if you need to do some task repeatedly, it is better to automate it with some programming. The initial investment in time is in general well worth it. You can avoid human errors more easily under pressure or boredom. So I decided to work on it.

The Tektronix provided interfaces for instruments control via GPIB, USB, etc. They use a standard interface protocol (VISA, or virtual instrument software architecture) for this purpose. If you have Matlab Instrument Control Toolbox license, you can use Matlab. Otherwise, there is a Python package “PyVisa” you can use to do your job.

Here are how you do it.

Download and Install TekVisa Driver

You can download the drive from Textronix website (TekVisa.exe).

Interface Using Matlab

Because the VISA interface is independent of the choice of the language, it is very handy to have this programming manual with you.

Open Device

Before open the device, you need to find the VISA brand and address information from Matlab Instrument Control Tool. Some more information can be found here.

Here is the source code for “tek_openDevice.m”.

Acquire Data

To simplify the code, I manually setup the Trigger source and level in the Oscilloscope. You can also use the code to program it if you intend to do more sophisticated control. So the source code for “tek_acquire.m” only allow to run and stop the trigger.

Capture Data

Once the trigger is tripped, you can capture the data from it. Here is the code for “tek_captureData.m”. The input channels is an array for selected channel to capture (eg. [1, 3, 4]). One thing to note is that the oscilloscope will clip the data if the display is out-of-sight, so make sure to scale the channel and move it up/down to make sure it doesn’t get clipped. You can put them all in the middle if you don’t care of the looking in the real oscilloscope. The data captured are integers, so we need to do some conversion (details in the programming manual).

Draw the Waveform

Here is the code that I used to draw the waveform.


Save the Data

In this function “tek_saveData.m”, I did something extra to automatically increment the file name and allow to add note in the mat file.

Close the Device

Top Level Example

Interface Using PyVisa (Python)

If you prefer to use the free tools. You can use PyVisa. It should work along with any Python distributions (Python, WinPython, Anaconda, Enthought Canopy, etc). You can find some example code here: http://www1.tek.com/forum/viewtopic.php?t=4389. Again the programming manual is the best reference.

Something to watch out if the PyVisa version you downloaded. There are some difference in API functions.
For example, in Version 1.4, this code works:

while in Version 1.7 and later, you would need to use this:

Read through the documents for PyVisa.

Hope this post helps.

How to Control Tektronix Oscilloscope (DPO 3054) with Matlab and Python
Tagged on:         

Please tell us what's in your mind ...

%d bloggers like this: