From 39d31a8f56fe368af543231d4b1b6cee4292ed91 Mon Sep 17 00:00:00 2001 From: Gayland Pounder <62302148+Gaylandp@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:32:19 -0800 Subject: [PATCH] Added a simple MSO68B example using tm_devices. (#64) * tm_devices example for MSO6B * Update of the Main directory for tm_devices example. * Update to tm_devices example folder names. * simple typo fix * Updated some bad links in teh basic scopes area --- .../src/Ivi2MatlabDriverExample/README.md | 2 +- .../README.md | 1 + .../src/Measurements_tm_devices/README.md | 8 +++ .../tm_devices_MSO6B_example.py | 61 +++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/README.md create mode 100644 Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/tm_devices_MSO6B_example.py diff --git a/Examples/Oscilloscopes/BenchScopes/src/Ivi2MatlabDriverExample/README.md b/Examples/Oscilloscopes/BenchScopes/src/Ivi2MatlabDriverExample/README.md index 28384d0..70dfe79 100644 --- a/Examples/Oscilloscopes/BenchScopes/src/Ivi2MatlabDriverExample/README.md +++ b/Examples/Oscilloscopes/BenchScopes/src/Ivi2MatlabDriverExample/README.md @@ -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. diff --git a/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/README.md b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/README.md index be00081..2739eca 100644 --- a/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/README.md +++ b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/README.md @@ -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/) | \ No newline at end of file diff --git a/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/README.md b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/README.md new file mode 100644 index 0000000..d0b2e20 --- /dev/null +++ b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/README.md @@ -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. diff --git a/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/tm_devices_MSO6B_example.py b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/tm_devices_MSO6B_example.py new file mode 100644 index 0000000..53523b7 --- /dev/null +++ b/Examples/Oscilloscopes/TekSeriesScopes_HighSpeedDigitizers/src/Measurements_tm_devices/tm_devices_MSO6B_example.py @@ -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) +