And then when we use the device manager and driver together:
pip install tm_devices
pip install tm_data_types
pip install tekHSI
scope :MSO5B= device_manager.add_scope ("192.168.1.1")
from tm_devices import DeviceManager
from tm_devices.drivers import MSO5B
with DeviceManager (verbose=True) as device_manager:
We can instantiate an instrument with a specific command set that matches its model. Just input your instrument’s IP address (other VISA addresses work as well).
With these four lines complete, we are able to start writing meaningful and specific automation for the MSO5B!
Code Snippets
Let’s take a look at a few simple actions -
Setting the Trigger type to Edge
# Setting Trigger A to Edge
scope.commands.trigger.a.type.write ("EDGE")
Here’s how you would add and query a peak-to-peak measurement on CH1:
# Specifying source as Channel 1
scope.commands.display.select.source.write("CH1")
# Identifying pk2pk as the measurement we would like to make
scope.commands.measurement.addmeas.write('PK2Pk' )
# Make sure the operation is complete using the opc command
scope.commands.opc.query()
# Store the value locally before we print
chipk2pk = float(scope.commands.measurement.meas[1].results.allacqs.mean.query())
# Printing the value onto the console
print(f 'Channel 1 pk2pk: {ch1pk2pk}')
If you wanted to take an amplitude measurement on CH2:
# Specifying source as channel 2
scope.commands.display.select.source.write("CH2")
# Identifying amplitude as the measurement we would like to make
scope.commands.measurement.addmeas.write('AMPLITUDE')
# Make sure the operation is complete using the opc command
scope.commands.opc.query()
# Store the value locally before we print
champ = float(scope.commands.measurement.meas[2].results.allacqs.mean.query())
# Print the value onto the console
print(f' amplitude: {ch2amp}')
Using IntelliSense/Code Completion
IntelliSense – Microsoft’s name for Code Completion is a very powerful feature of IDE’s we have tried to exploit as much as possible.
One of the core barriers to automation with test and measurement devices is the SCPI command set. It is a dated structure with syntax not widely supported in the development community.
What we have done with tm_devices is create a set of Python commands for each SCPI command. This allowed us to generate Python code from existing command syntax to avoid manual development of the drivers, as well as create a structure that is familiar to existing SCPI users. It also maps to the lower-level code that might require intentional debugging during your program creation. The structure of the Python commands mimics the SCPI (or in some Keithley cases TSP) commands structure so if you are familiar with SCPI you will be familiar with these.
This is an example of how IntelliSense shows all the commands available with the previously typed command:
In the scrollable list that appears after the dot on scope we can see an alphabetical list of scope command categories:
Choosing afg we are able to then see a list of AFG categories:
Final command written with the help of IntelliSense:
scope.commands.afg.amplitude.write(10e6)
Docstring Help
As you code, or as you are reading someone else’s code, you can hover over different parts of the syntax to get that level’s specific help documentation. The closer you are to the full command syntax the more specific it will get.
Depending on your IDE conditions you can display both IntelliSense and docstring help at the same time.
With this guide you have seen some of the benefits of Tek’s python driver package tm_devices and can start your automation journey. With the easy setup, code completion, and built-in help you will be able to learn without leaving your IDE, speed up your development time, and code with higher confidence.
There are contribution guidelines in the Github repo if you wish to improve the package. There are plenty of more advanced examples highlighted in the documentation and within the package contents in the Examples folder.
Extra Resources
tm_devices · PyPI – Package driver download and information
tm_devices Github - Source code, issue tracking, contribution
tm_devices Github - Online Documentation
Troubleshooting
Upgrading pip is usually a good first step to troubleshooting:
In your terminal type:
Python.exe -m pip install -upgrade pip
Error: whl looks like a filename, but file does not exist OR .whl is not a supported wheel on this platform.
Solution: Pip installing wheel so that it recognizes the file format.
In your terminal type: pip install wheel
If you are needing to install wheel offline you can follow similar instructions as Appendix A, but it requires the tar.gz download instead of the .whl file.
Appendix A – Offline Installation of tm_devices
1. On a computer with internet, download the package along with all dependencies to the specified path location using:
2. Copy the files to your computer that does not have internet access
3. Then, follow the instructions from the main guide for whichever IDE you are using but swap the install command for the following: