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 Plotting example that uses TekHSI, tm_devices, and tm_data_types #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -19,4 +19,5 @@ MDO3, MSO4/5/6 Series Oscilloscopes & MSO5LP/6LP High Speed Digitizers
| **[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/) |
| **[Double Pulse Test Example](./src/DoublePulseTestExample)** | [![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/) |
| **[Double Pulse Test Example](./src/DoublePulseTestExample)** | [![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/) |
| **[TekHSI Simple Plot Example](./src/tekhsiSimplePlotExample)** | [![Python 3.12](https://img.shields.io/badge/python-3.12-&?labelColor=3E434A&colorB=006281&logo=python)](https://www.python.org/downloads/release/python-3126/) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

'''An example script for connecting to a scope, setting up the trigger and channels, acquiring a waveform,
retrieving waveform data from a channel, and plotting the waveform data.

NOTES
- Please change the ADDRESS to your scope's IP address (ADDRESS)
- This program uses an MSO5B, (from tm_device.driver import MSO5B)
- MAKE SURE HSI is enable on the scope! On the scope: Utility > I/O > HIGH SPEED INTERFACE > High Speed Interface > (Toggle) "On"
- This example uses matplotlib, tm_devices, tm_data_types, and tekhsi

- IMPORTANT NOTE: TURN ON High Speed Interface on Scope!
Scope Path: Utility > I/O > High Speed Interface > High Speed Interface

'''

# Importing modules, packages, libraries etc.
# import time # ONLY for code line 58
import matplotlib.pyplot as plt
from tm_devices import DeviceManager # https://pypi.org/project/tm-devices/
from tm_devices.drivers import MSO4B, MSO5, MSO5B, MSO6, MSO6B # Importing Drivers for Tektronix MSO58B, https://pypi.org/project/tm-devices/

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'MSO4B' is not used.
Import of 'MSO5' is not used.
Import of 'MSO6' is not used.
Import of 'MSO6B' is not used.
from tm_devices.drivers import DPO70K, DPO70KC, DPO70KD, DPO70KDX, DPO70KSX

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'DPO70K' is not used.
Import of 'DPO70KC' is not used.
Import of 'DPO70KD' is not used.
Import of 'DPO70KDX' is not used.
Import of 'DPO70KSX' is not used.
from tm_devices.drivers import MSO70K, MSO70KC, MSO70KDX

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'MSO70K' is not used.
Import of 'MSO70KC' is not used.
Import of 'MSO70KDX' is not used.
from tm_data_types import AnalogWaveform # Importing Waveform Class, https://pypi.org/project/tm-data-types/
from tekhsi import TekHSIConnect # Importing TekHSIConnect, https://pypi.org/project/TekHSI/

# Scope VISA, IP, Port Settings
ADDRESS = "xxxx.xxxx.xxxx.xxxx" # Instrument IP Address

# TURN ON High Speed Interface on Scope!
# Path: Utility > I/O > High Speed Interface > High Speed Interface

with DeviceManager(verbose=False) as dm: # Create a DeviceManager Object (dm)

MSO_scope: MSO5B = dm.add_scope(ADDRESS) # adding a scope object
MSO_scope.visa_timeout = 5000 # 5000 ms VISA timeout

scope = MSO_scope.commands # Aliasing

print(scope.idn.query()) # printout scope ID

# User input for connecting channel 2
input('''
ACTION
Connect probe to Oscilloscope Channel 2 and the Probe Compensation Signal.
Press Enter to continue....
''')

print("Scope Setup, Acquire, Waveform transfer, and plotting....")

scope.rst.write() # scope reset
scope.opc.query() # OPC command

scope.display.waveview1.ch[2].state.write("ON") # Turn on ch 2, turn off ch1
scope.display.waveview1.ch[1].state.write("OFF")

scope.trigger.a.type.write("EDGE") # set edge trigger to ch2
scope.trigger.a.edge.source.write("CH2")
scope.opc.query()

scope.autoset.write("EXECUTE") # scope autoset
scope.opc.query()
# time.sleep(1) # optional delay
scope.acquire.state.write("0") # Setup single acquisition
scope.acquire.stopafter.write("SEQUENCE")
scope.acquire.state.write("1") # single acquisition
scope.opc.query()

if int(scope.acquire.state.query()) !=1: # Checking that the scope is stopped
with TekHSIConnect(f"{ADDRESS}:5000") as connection: # Establish a tekhsi connection to the oscilloscope.
with connection.access_data(): # Begin accessing data from the oscilloscope with connection
waveform: AnalogWaveform = connection.get_data("ch2") # Retrieve the waveform data for channel 2 from the scope, waveform object

hd = waveform.normalized_horizontal_values # Extract the normalized horizontal (time) values from waveform.
vd = waveform.normalized_vertical_values # Extract the normalized vertical (voltage) values from waveform.

# Plotting the waveform data
_, ax = plt.subplots() # Create a new figure and subplot
ax.plot(hd, vd) # Plot the waveform
ax.set(xlabel=waveform.x_axis_units, # plot axes labeling
ylabel=waveform.y_axis_units, title="Simple Plot")
plt.show() # Display plot

print("End of tm_devices simple plot example")
Loading