Tuesday, February 4, 2025

Digital Oscilloscope Screen Captures

Any troubleshooting or design work involving audio equipment or digital logic is often sped up by using an oscilloscope to look at analog wave forms or analyze digital signals and alignment across a circuit. When documenting such troubleshooting and design work, being able to capture a signal trace on an oscilloscope is helpful in communicating a diagnosis or design. Most modern digital scopes provide a USB host port that allows a USB thumb drive to be plugged in and used as the destination in writing screen dumps to paste into other documents.

Since at least 2015, many digital scope makers have expanded beyond this simple approach to capturing screen images by implementing networking and VISA (Virtual Instrument Software Architecture) protocols developed by National Instruments that add significant automation and scripting capabilties to a variety of laboratory gear. APIs implementing these VISA standards have been implemented in a variety of languages including Python, C#, Java and .Net.

(You can see where this is going...)

This capability exists on virtually all scopes. The process of using it will be demonstrated using a Rigol DHO924S scope that operates atop the Android operating system and Python as a scripting language. However, these newer scopes also make screen captures possible without any scripting using functions built within browser interfaces. Both approaches will be shown. The browser appraoch is easier for rare, occassional use but the ability to script a capture allows it to be used within a larger process that might also be scripted.


Connecting to the Scope - USB or IP

Rigol scopes accept connections via a USB Device port tied to a laptop / desktop computer or via IP. Use of the USB interface might be preferable for selected tasks and seems logically preferable given that Rigol scopes do not (yet) have WiFi IP connectivity and a wired Ethernet connection may not always be close to where the scope is being used. However, communicating to a Rigol scope over USB requires installation of an application developed by Rigol called UltraSIgma whose user interface components were last altered around 2016 but visually appear to be coded using mid-1990s frameworks. Given the age of the software, it requires installation by a user with Admin privileges on Windows.


Finding the Scope's VISA Address

VISA libraries use identifiers in a specific format to identify a specific lab device. When accessing a Rigol scope via IP or USB, that identifer will take one of these forms:

TCPIP::192.168.99.29::INSTR
USB0::0x1AB1::0x044C::DHO9S254201528::INSTR

If IP connectivity is used, the VISA address will be visible in the Rigol scope's Utility sub-function as soon as the scope boots and pulls an IP address from the DHCP server. The screen will look like this:

Note that it IS possible to statically assign the IP so the scope obtains the same IP address consistently, avoiding the need to possible change this IP reference in the VISA address in the script. However, in most small networks, DHCP servers in gateway routers will typically re-assign the same IP to the same MAC unless they exhaust their available pool so changing IP addresses isn't often an issue.

If USB connectivity is used, the view in the scope will NOT be updated since a USB connection is not considered a "network" connection. Instead, the USB format VISA address can be identified in two ways. One way is to temporarly connect the scope to an IP network and surf to the scope's IP and gleen the USB address from the top level Rigol Web Control view (see a sample screen dump further below). The other way is to install the UltraSigma software package from Rigol to then allow its parent utility program to be run to display the VISA string.

The view displaying the USB VISA address looks like this in that parent application:

Since the USB designation may change based on which physical USB port on the computer is used and which USB controller is driving that physical port, this information must be discovered from the PC end. There's no way to predict it by looking at information in the scope's displays.

Using Python and pyvisa for Captures

With the scope connected via IP or USB and its VISA address identified, the logic required to make VISA calls to address the scope and trigger a screen capture are very simple in Python. First, two libraries are required which can be installed via these commands.


pip install -U pyvisa
pip install -U pyvisa-py

As of February 4, 2025, these will install version 1.14.1 of pyvisa and version 0.7.2 of pyvisa-py.

With those libraries installed, a simple script like the following will allow an output filename to be specified along with an option to include a datetime stamp like 20250204193059 in the filename.

import pyvisa import argparse import datetime # use argparse to parse arguments for filename and option datestamp parser = argparse.ArgumentParser( prog="capturescope", description='Captures screen dumps via VISA protocol from Rigol oscilloscope', epilog='syntax: capturescreen.py filename --timestamp' ) parser.add_argument('filename',help='name of file without extension to write') parser.add_argument('-t','--timestamp', help='adds yyyymmddhhmmss timestamp to filename',action='store_true') args = parser.parse_args() fullfilename = args.filename if args.timestamp: # need to get the current yyyymmddhhmmss timestamp now = datetime.datetime.now() yyyymmddhhmmss = now.strftime("%Y%m%d%H%M%S") fullfilename = fullfilename + '.' + yyyymmddhhmmss fullfilename = fullfilename + '.png' print("Writing screen capture to: ",fullfilename) # Connect to the oscilloscope rm = pyvisa.ResourceManager() # here is my scope's reference when connected via TCPIP scope = rm.open_resource('TCPIP::192.168.99.29::INSTR') # here is my scope's reference when connected via USB to my laptop # find this via Sigma Ultra app from Rigol or temporarily connect via IP # then surf to http://ipaddress # scope = rm.open_resource('USB0::0x1AB1::0x044C::DHO9S254201528::INSTR') # Set the timeout scope.timeout = 5000 # Get the screenshot screenshot = scope.query_binary_values(':DISP:DATA?', datatype='B') # Save the screenshot as a PNG file with open(fullfilename, 'wb') as f: f.write(bytes(screenshot)) # Close the connection scope.close()

With that script, anything present on the screen can be captured using commands like this:

c:\Docs\gitwork\labutils>python capturescope.py scopeaddress --timestamp
Writing screen capture to:  scopeaddress.20250203215700.png

c:\Docs\gitwork\labutils>python capturescope.py negativeclock --timestamp
Writing screen capture to:  negativeclock.20250203221010.png

c:\Docs\gitwork\labutils>python capturescope.py positiveclock --timestamp
Writing screen capture to:  positiveclock.20250203221056.png

c:\Docs\gitwork\labutils>dir
 Volume in drive C is OS
 Volume Serial Number is 5841-F07E

 Directory of c:\Docs\gitwork\labutils

02/03/2025  10:15 PM    <DIR>          .
02/03/2025  10:15 PM    <DIR>          ..
02/03/2025  09:55 PM             1,327 capturescope.py
02/03/2025  10:10 PM            74,996 negativeclock.20250203221010.png
02/03/2025  10:10 PM            76,419 positiveclock.20250203221056.png
02/03/2025  09:57 PM           103,686 scopeaddress.20250203215700.png
               4 File(s)        256,428 bytes
               2 Dir(s)  500,848,386,048 bytes free

c:\Docs\gitwork\labutils>

Captures via Rigol Web Control

When connected to an IP network, most (all?) Rigol scopes expose a web server on the scope's IP address without SSL encryption or login protection that allow any function that can be performed using the touch screen on the scope to be performed via click in a browser window. For a scope assigned 192.168.99.29 as its IP, surfing to http://192.168.99.29 will display this screen.

Clicking on the Web Control button will pop open a new browser window with a full window matcing the scope's live touchscreen like this. NOTE: It is worth mentioning that this browser view is IDENTICAL in functionality to the touch screen on the scope itself. Any action that can be performed by touching the screen on the scope can be performed by clicking on the same spot on this browser view. HANDY.

It is certainly possible to capture the scope screen using the PC's "screen scraping" utilities (like Window-Shift-S in Windows) to capture the image from this browser view.

It is also possible to use the Print Screen button which displays a different browser page allowing a choice between a static snapshot and a recording.

If the Take Screenshot button is clicked, a screenshot will be captured and rendered in that browser window. At that point, you can right-click on it, choose Save Image As... then write the file wherever desired on the local PC. If the goal is to capture a live change in a signal, the Record Screen button allows control over the start and stop then prompts for the filename and destination to save the *.mp4 video file to the browser PC.