0% found this document useful (0 votes)
89 views9 pages

Getting - Started - With - Oscilloscope - Automation - and - Python - App Note - 48W-73878-0

The document discusses getting started with oscilloscope automation and Python. It covers the basics of programmatic interfaces and provides an example of downloading and running a Python script to automate an oscilloscope. The example demonstrates correcting the VISA address and running the code to plot data from the oscilloscope.

Uploaded by

Keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views9 pages

Getting - Started - With - Oscilloscope - Automation - and - Python - App Note - 48W-73878-0

The document discusses getting started with oscilloscope automation and Python. It covers the basics of programmatic interfaces and provides an example of downloading and running a Python script to automate an oscilloscope. The example demonstrates correcting the VISA address and running the code to plot data from the oscilloscope.

Uploaded by

Keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Getting Started with Oscilloscope

Automation and Python


––
TECHNICAL BRIEF
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

Engineers across many industries use automation to extend the capabilities of their oscilloscopes, and many engineers are
using Python. The free programming language Python has significant advantages for automation:

• Versatility

• Easy to teach and learn

• Code readability

• Widely available knowledge bases and modules

There are two main use cases for automation:

• Routines that mimic human behavior to automate the front panel and save time, e.g., automated compliance testing. Rather
than sitting down at the scope, adding the appropriate measurements, and writing down the results every time you need to
test a new part, the engineer develops a script that does all of that and displays the result.

• Uses that extend the functionality of the instrument, for example measurement logging, validation, or quality assurance.
Automation allows the engineer to execute complex tests without many of the downsides inherent to those tests. There’s
no need for an operator to set up the scope or manually record the results, and the test can be performed the same way
every time.

This technical brief will cover what you need to get started programming scopes in Python, including the basics of
programmatic interfaces and how to download and run an example.

What Is a Programmatic Interface?


A programmatic interface (PI) is a boundary or set of The PI Stack (Figure 1) shows the flow of information from
boundaries between two computing systems that can be the host controller down to the instrument. The application
programmed to execute specific behaviors. For our purposes, code written by the end user defines the behavior of the target
it’s the bridge between the computer that runs in every piece of instrument. This is usually written in one of the development
Tektronix test equipment and the application written by the end platforms popular in the industry, such as Python, MATLAB,
user. To narrow this even further, it is a set of commands that LabVIEW, C++, or C#.
can be sent remotely to an oscilloscope and the system on
This application will send SCPI commands, which are
that oscilloscope that processes and executes them.
the standard format for almost all test and measurement
equipment, to the VISA layer. In some cases, the application
will call a driver, which will then send one or more SCPI
commands to the VISA layer.

2 | TEK.COM
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

Host Machine

Application (Your Code)

IVI Driver LabView .NET Driver

SCPI SCPI SCPI SCPI

VISA

USB LAN/VXI-11

Instrument

Figure 1. The programmatic interface (PI) stack shows the flow of information between a host controller and instrument

The VISA layer negotiates the connection with the instrument The instrument will then read and write information directly
over either the USB or LAN interface. VISA opens and closes on the USB or LAN interface. Depending on what commands
the remote session with the instrument, writes and reads are issued, it may change settings in the scope application or
data on the bus, and maintains the health of the connection provide the response to a query.
with synchronization, flushing and other miscellaneous
All of the systems above the physical communication
functions. This layer abstracts a lot of the technical minutia
interface are also mirrored in the scope, but we can consider
required for communication, like resource addresses and
it a “black box” since we can’t modify those systems. Each
buffer management.
major instrument vendor provides an implementation of the
VISA standard to use with their products. All of the basic
functionality is included in the standard requirements, so
any vendor's VISA should work well enough to control
an instrument.

TEK.COM | 3
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

How to Get Started with Automation Downloading and Running an Example


To get started quickly, you should install a few development To demonstrate running a Python program, we are using a file
tools on your PC: on the Tektronix GitHub page at https://github.com/tektronix/
Programmatic-Control-Examples under Oscilloscopes –
1. Install NI VISA:
Touchscreen Oscilloscopes & High Speed Digitizers. The
• Download the installer from National Instruments. The program is called SimplePlotExample.
URL is subject to change, but the installer can be found
1. Pull the file from GitHub. One way is to open the source
by searching “NI VISA.”
code then right-click Raw and choose, “Save link as”.
• Use the default settings.
2. Open IDLE (the default Python editor) and open the file
2. Install Python:
that was just saved. IDLE will open up the text editor,
• Download the installer from https://www.python.org/. which shows the code.

• Install Python using “Install Now” and enable “Add 3. Run the code to see what happens. There are two ways to
Python 3.x to PATH” – this will make it easier to do so in IDLE: click Run->Run Module or simply press F5
install modules. on the keyboard. The screen in Figure 3 shows that there
3. Install pyvisa: is a problem with the code.

• Open Windows cmd (command line)

• Press Win+R to open Run

• Type “py –m pip install pyvisa”

Figure 2. Saving source code from GitHub, using the Chrome


web browser.

4 | TEK.COM
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

Figure 3. Incorrect VISA Address

The first thing to do when using any example script is to look at the VISA address, which is the network name that tells VISA where
to find the instrument. This example code specifies a USB address, which means the user would need to have the exact same
oscilloscope connected to his or her PC as the author of this script did when it was written and published it to GitHub.

TEK.COM | 5
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

To correct the VISA address, open NI MAX, which was installed as part of NI-VISA. NI MAX will allow the user to connect to
oscilloscopes, troubleshoot those connections, and send single individual commands as needed.

For this example, we are using a LAN connection. In Figure 4, you can see any oscilloscopes on the network in the tree structure
on the left. The instrument at address 192.168.1.17 is a 4 Series Mixed Signal Oscilloscope, which will be used as an example for
this technical brief. (You will see a different address for a different oscilloscope on your network.)

Take the VISA resource name from NI-VISA and paste it into the program, then run the code again.

Figure 4. Using NI MAX to determine the correct VISA resource name.

6 | TEK.COM
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

Figure 5. The Simple Plot example program prompts the user to connect a probe.

The example code now runs correctly. It pauses for a moment to ask the user to install a probe on Channel 1 and connect it to the
probe compensation signal on the oscilloscope.

After connecting the probe, hit Enter to continue. This results in a scope trace on the PC.

TEK.COM | 7
Getting Started with Oscilloscope Automation and Python TECHNICAL BRIEF

Figure 6. The Simple Plot example will transfer a waveform from the oscilloscope and plot it on the PC.

Key Python SCPI Commands for • IDN?: Tells you what instrument is connected and provides
a handshake and sanity check.
Scope Automation
• OPC?: A synchronization command that returns only when
Standard Commands for Programmable Instruments
operations are complete.
(SCPI) instructions are used to change settings and get
measurements from instruments. A versatile instrument, such • ESR?: Tells you there is an error. This must be sent before
as an oscilloscope, may support hundreds of commands. ALLEV?.
The general syntax of SCPI commands is very similar among
• ALLEV?: Explains the error.
various manufacturers and instruments, making it easier to
communicate with different instruments. Most SCPI commands
have a “set” form for changing settings, and a “query” form Taking the Next Steps
for getting information back from the instrument. The precise
It is common for developers to copy and paste code from
syntax for a given instrument is typically documented in a
examples; this not only saves time but also helps them learn
Programmer Manual, which is generally available on the
along the way. Browse the code examples on the Tektronix
instrument manufacturer’s website. The programmatic interface
Github for finished solutions and inspiration!
manual for the 4, 5 and 6 Series MSOs is a good example.
Python is one of the preferred software environments to use
A comprehensive description of SCPI commands is beyond
automation to extend the capabilities of an oscilloscope due to
the scope of this technical brief, but there are several
the portability, ease of use and scalability it offers. If you have
commands that you should get to know right away:
repetitive or complex tasks to perform with your oscilloscope,
using Python and starting with pre-written example programs
can provide a quick path to a solution.

8 | TEK.COM
Contact Information:
Australia 1 800 709 465
Austria* 00800 2255 4835
Balkans, Israel, South Africa and other ISE Countries +41 52 675 3777
Belgium* 00800 2255 4835
Brazil +55 (11) 3759 7627
Canada 1 800 833 9200
Central East Europe / Baltics +41 52 675 3777
Central Europe / Greece +41 52 675 3777
Denmark +45 80 88 1401
Finland +41 52 675 3777
France* 00800 2255 4835
Germany* 00800 2255 4835
Hong Kong 400 820 5835
India 000 800 650 1835
Indonesia 007 803 601 5249
Italy 00800 2255 4835
Japan 81 (3) 6714 3086
Luxembourg +41 52 675 3777
Malaysia 1 800 22 55835
Mexico, Central/South America and Caribbean 52 (55) 56 04 50 90
Middle East, Asia, and North Africa +41 52 675 3777
The Netherlands* 00800 2255 4835
New Zealand 0800 800 238
Norway 800 16098
People’s Republic of China 400 820 5835
Philippines 1 800 1601 0077
Poland +41 52 675 3777
Portugal 80 08 12370
Republic of Korea +82 2 565 1455
Russia / CIS +7 (495) 6647564
Singapore 800 6011 473
South Africa +41 52 675 3777
Spain* 00800 2255 4835
Sweden* 00800 2255 4835
Switzerland* 00800 2255 4835
Taiwan 886 (2) 2656 6688
Thailand 1 800 011 931
United Kingdom / Ireland* 00800 2255 4835
USA 1 800 833 9200
Vietnam 12060128

* European toll-free number. If not


accessible, call: +41 52 675 3777
Rev. 02.2018

Find more valuable resources at tek.com

Copyright © Tektronix. All rights reserved. Tektronix products are covered by U.S. and foreign patents, issued and pending. Information in this publication supersedes that
in all previously published material. Specification and price change privileges reserved. PCIE® and PCI-SIG® are registered trademarks and/or service marks of PCI-SIG. TEKTRO-
NIX and TEK are registered trademarks of Tektronix, Inc. All other trade names referenced are the service marks, trademarks or registered trademarks of their respective companies.
031622 SBG 48W-73878-0

You might also like