Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a simple MSO68B example using tm_devices. #64

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Convert IVI to MATLAB Driver and Read Waveform (TBS1kB-EDU)
Original Attribution: Will D

The purpose of this example is to demonstrate how to get a MATLAB driver for an instrument not listed in the MathWorks repository [here](https://www.mathworks.com/programs/products/instrument/instrument-drivers-search.html) but with a driver available via the IVI Foundation repository [here](http://www.ivifoundation.org/registered_drivers/driver_registry.aspx), such as [this driver](http://www.ivifoundation.org/registered_drivers/driver_registry.aspx) which I am using with a TBS1202B-EDU.
The purpose of this example is to demonstrate how to get a MATLAB driver for an instrument not listed in the MathWorks repository [here](https://www.mathworks.com/hardware-support/instrument-control-toolbox/drivers-search.html?s_tid=srchtitle_site_search_3_instrument%20drivers&q=&page=1) but with a driver available via the IVI Foundation repository [here](https://www.ivifoundation.org/DriverRegistry/default.html), such as [this driver](http://sine.ni.com/apps/utf8/niid_web_display.download_page?p_id_guid=E3B19B3E94FE659CE034080020E74861) which I am using with a TBS1202B-EDU.

This example will lead you through installing the NI driver, recognizing where that installation is and confirming its existence, then using the ".c" driver to make a MATLAB ".mdd" driver.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ MDO3, MSO4/5/6 Series Oscilloscopes & MSO5LP/6LP High Speed Digitizers
| **[Curvestream Maximum Speed (Tekworld Demo)](./src/CurvestreamMaximumSpeed)** | [![Python 3.8](https://img.shields.io/badge/python-3.8-&?labelColor=3E434A&colorB=006281&logo=python)](https://www.python.org/downloads/release/python-360/) |
| **[Hello Scope! Basic Control Example](./src/CSharpHelloScope)** | [![C Sharp](https://img.shields.io/badge/-C%20Sharp-&?labelColor=3E434A&colorB=73BF44&logo=Microsoft)](https://github.com/dotnet/roslyn) |
| **[Curve Query (Fetch Waveform) Windows Forms Example](./src/CSharpCurveQueryWinforms)** | [![C Sharp](https://img.shields.io/badge/-C%20Sharp-&?labelColor=3E434A&colorB=73BF44&logo=Microsoft)](https://github.com/dotnet/roslyn) |
| **[Simple Measurement Automation with tm_devices](./src/Measurements_tm_devices)** | [![Python 3.8](https://img.shields.io/badge/python-3.8-&?labelColor=3E434A&colorB=006281&logo=python)](https://www.python.org/downloads/release/python-360/) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Get simple measurement using tm_devices
Original Attribution: Gayland P - Tektronix Applications

This is a simple example using Tektronix tm_devices tools to connect to an oscilloscope by USB connection. This program finds the maximum peak to peak voltage value on a signal connected to Channel 1 of a 6 Series B oscilloscope. It runs the oscilloscope 10 times for 3 seconds at a time and publishes the results to a file in a C:\\Test directory. Very minor changes would be needed to use this script with a 5 Series, 4 series, or other 6 series oscilloscopes.

For a description of tm_devices please go to https://pypi.org/project/tm-devices.

This script uses numpy arrays, and assumes that the user has a version of VISA loaded on their PC that supports USB control of instrumentation, such as TekVISA, or NI-VISA.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is an introductory python script originally written with pycharm IDE. This shows how to use tm_devices
# for a relatively realistic short automation routine. Its goal is to find the maximum peak to peak
# value of a signal on CH1 for a period of three seconds for 10 separate periods.

# to use this script please create a folder under "C" drive called "Test"

# This program uses tm_devices. see https://pypi.org/project/tm-devices/ for more details.
# Device Manager interacts with pyvisa (and if a third party VISA is installed pyvisa interacts
# with that). It has the routines that control instruments.
from tm_devices import DeviceManager

# Now we import the specific drivers that control the individual instrument, in this case a B version 6-series
from tm_devices.drivers import MSO6B
# Import time so we can use time.sleep()
import time
# Import Numpy (https://pypi.org/project/numpy/) to use numpy's array tools
import numpy as np

# set up initial values, including the numpy array.
i = 0
NumberOfRuns = 10
MaxPKtoPK = np.zeros(NumberOfRuns)

# Set up and connect to scope and check its idn string to ensure we connected. verbose in the DeviceManager
# means you can see all commands going to instrument and all responses to queries which is useful for debug, or
# not. Here we chose "false" so that we do not print those out.
with DeviceManager(verbose=False) as device_manager:
scope: MSO6B = device_manager.add_scope("MSO68B-B025464", connection_type="USB" )
print(scope.idn_string)

# default the oscilloscope so that it is in a standard condition
scope.reset()

# Run Autoset to get the signal set up on screen. Followed by OPC query to ensure it completes.
scope.commands.autoset.write("EXEC")
scope.commands.opc.query()
# Set up horizontal record length to 1 million points.
scope.commands.horizontal.mode.write("MANual")
scope.commands.horizontal.recordlength.write(1e6)
# Ad Meas1 as a PK2PK measurement and display all stats in the badge
# Then add a second Risetime measurement using a different method within tm_devices.
scope.add_new_measurement("MEAS1", "PK2PK", "CH1")
scope.commands.measurement.meas[1].displaystat.enable.write("ON")
scope.commands.measurement.addmeas.write("RISETIME")
scope.commands.measurement.meas[2].source.write("CH1")

# stop the scope
scope.commands.acquire.state.write("OFF")
# This loop first clear the previous measurement values, starts the scope and runs it for 3 seconds, stops the
# scope. and then add the Maximum peak to peak measurement value to the numpy array.
while i < NumberOfRuns:
scope.commands.clear.write()
scope.commands.acquire.state.write("ON")
time.sleep(3)
scope.commands.acquire.state.write("OFF")
MaxPKtoPK[i] = scope.commands.measurement.meas[1].results.allacqs.maximum.query()
i = i+1
# Create the output file in the folder "Test" and use a numpy command to save the data into it.
filename = "C:\\Test\\MaxAmp.txt"
np.savetxt(filename, MaxPKtoPK)