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

Updated Documentation to include usage of PyVISA and tm_devices along with TekHSI. #24

Merged
merged 12 commits into from
Sep 20, 2024
Merged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Valid subsections within a version are:

Things to be included in the next release go here.

### Added

- Updated documentation to include examples illustrating usage of `PyVISA` and `tm_devices`.
- Updated documentation requirements.

---

## v0.1.1 (2024-09-11)
Expand Down
10 changes: 10 additions & 0 deletions docs/additional_examples_and_pseudo_codes/access_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tm_data_types import AnalogWaveform

from tekhsi import TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
# Request access to data
with connection.access_data():
# Access granted
ch1: AnalogWaveform = connection.get_data("ch1")
Fixed Show fixed Hide fixed
ch3: AnalogWaveform = connection.get_data("ch3")
Fixed Show fixed Hide fixed
17 changes: 17 additions & 0 deletions docs/additional_examples_and_pseudo_codes/acq_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def any_horizontal_change(previous_header, current_header):
"""Prebuilt acq acceptance filter that accepts only acqs with
changes to horizontal settings.
"""
for key, cur in current_header.items():
if key not in previous_header:
return True
prev = previous_header[key]
if prev is None and cur != None:
return True
if prev is not None and (
prev.noofsamples != cur.noofsamples
or prev.horizontalspacing != cur.horizontalspacing
or prev.horizontalzeroindex != cur.horizontalzeroindex
):
return True
return False
4 changes: 4 additions & 0 deletions docs/additional_examples_and_pseudo_codes/active_symbols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tekhsi import TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
print(connection.activesymbols)
25 changes: 25 additions & 0 deletions docs/additional_examples_and_pseudo_codes/analog_waveform_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import matplotlib.pyplot as plt

from tm_data_types import AnalogWaveform

from tekhsi import TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
# Get one data set to setup plot
with connection.access_data():
waveform: AnalogWaveform = connection.get_data("ch1")

# Data converted into vertical units
# This is the usual way to access the data
vd = waveform.normalized_vertical_values

# Horizontal Times - returns an array of times
# that corresponds to the time at each index in
# vertical array
hd = waveform.normalized_horizontal_values

# Simple Plot Example
_, ax = plt.subplots()
ax.plot(hd, vd)
ax.set(xlabel=waveform.x_axis_units, ylabel=waveform.y_axis_units, title="Simple Plot")
plt.show()
10 changes: 10 additions & 0 deletions docs/additional_examples_and_pseudo_codes/blocking_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tm_data_types import AnalogWaveform, DigitalWaveform, IQWaveform

from tekhsi import AcqWaitOn, TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
with connection.access_data(AcqWaitOn.NewData):
ch1: AnalogWaveform = connection.get_data("ch1")
Fixed Show fixed Hide fixed
ch3: AnalogWaveform = connection.get_data("ch3")
Fixed Show fixed Hide fixed
ch1_iq: IQWaveform = connection.get_data("ch1_iq")
Fixed Show fixed Hide fixed
ch4_dall: DigitalWaveform = connection.get_data("ch4_DAll")
Fixed Show fixed Hide fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import matplotlib.pyplot as plt
import numpy as np

from tm_data_types import DigitalWaveform

from tekhsi import TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
# Get one data set to setup plot
with connection.access_data():
waveform: DigitalWaveform = connection.get_data("ch4_DAll")

# Digital retrieval of bit 3 in the digital array
vd = waveform.get_nth_bitstream(3).astype(np.float32)

# Horizontal Times - returns an array of times
# that corresponds to the time at each index in
# vertical array
hd = waveform.normalized_horizontal_values

# Simple Plot Example
_, ax = plt.subplots()
ax.plot(hd, vd)
ax.set(xlabel=waveform.x_axis_units, ylabel=waveform.y_axis_units, title="Simple Plot")
plt.show()
24 changes: 24 additions & 0 deletions docs/additional_examples_and_pseudo_codes/iq_waveform_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import matplotlib.pyplot as plt

from tm_data_types import IQWaveform

from tekhsi import TekHSIConnect

with TekHSIConnect("169.254.3.12:5000") as connection:
# Get one data set to setup plot
with connection.access_data():
waveform: IQWaveform = connection.get_data("ch1_iq")

# IQ Data Access (Complex Array)
iq_data = waveform.normalized_vertical_values

# Simple Plot Example
_, ax = plt.subplots()
ax.specgram(
iq_data,
NFFT=int(waveform.meta_info.iq_fft_length),
Fc=waveform.meta_info.iq_center_frequency,
Fs=waveform.meta_info.iq_sample_rate,
)
ax.set_title("Spectrogram")
plt.show()
37 changes: 37 additions & 0 deletions docs/additional_examples_and_pseudo_codes/pyvisa_usage.py
u625355 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""An example script demonstrating the command & control using PyVISA and retrieving waveform data from a single channel using TekHSI."""

import pyvisa

from tm_data_types import AnalogWaveform

from tekhsi import TekHSIConnect

addr = "192.168.0.1" # Replace with the IP address of your instrument

rm = pyvisa.ResourceManager("@py")

# write command to instrument sample using pyvisa
visa_scope = rm.open_resource(f"TCPIP0::{addr}::INSTR")

sample_query = visa_scope.query("*IDN?")
print(sample_query)
# Make the waveform display OFF
visa_scope.write("DISplay:WAVEform OFF")
# Set the Horizontal mode to Manual
visa_scope.write("HOR:MODE MAN")
# Set the horizontal Record Length
visa_scope.write("HOR:MODE:RECO 2500")

# time.sleep(2) # Optional delay
# Connect to instrument via TekHSI, select channel 1
with TekHSIConnect(f"{addr}:5000", ["ch1"]) as connect:
# Save data from 10 acquisitions
for i in range(10):
with connect.access_data():
waveform: AnalogWaveform = connect.get_data("ch1")
print(f"{waveform.source_name}_{i}:{waveform.record_length}")

visa_scope.write("DISplay:WAVEform ON")

# close visa connection
u625355 marked this conversation as resolved.
Show resolved Hide resolved
rm.close()
24 changes: 24 additions & 0 deletions docs/additional_examples_and_pseudo_codes/supported_data_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np

from tm_data_types import AnalogWaveform, DigitalWaveform, IQWaveform, read_file

data = read_file("Test.wfm")

# currently wfm files can be of three flavors
# AnalogWaveform, IQWaveform, or DigitalWaveform
# each can be explicitly checked for as follows.
if isinstance(data, AnalogWaveform):
wfm: AnalogWaveform = data
# returns the sampled values in vertical units
vd = wfm.normalized_vertical_values
Fixed Show fixed Hide fixed
y_axis = wfm.y_axis_units
Fixed Show fixed Hide fixed
elif isinstance(data, IQWaveform):
wfm: IQWaveform = data
# Returns the real portion of the iq data for plotting.
# Note that 'normalized_vertical_values' is a complex array.
vd = wfm.normalized_vertical_values.real
Fixed Show fixed Hide fixed
y_axis = wfm.y_axis_units
Fixed Show fixed Hide fixed
elif isinstance(data, DigitalWaveform):
wfm: DigitalWaveform = data
# Returns bit 3 as a float stream for plotting.
vd = wfm.get_nth_bitstream(3).astype(np.float32)
Fixed Show fixed Hide fixed
32 changes: 32 additions & 0 deletions docs/additional_examples_and_pseudo_codes/tm_devices_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""An example script demonstrating the command & control using tm_devices and retrieving waveform data from a single channel using TekHSI."""

from tm_data_types import AnalogWaveform
from tm_devices import DeviceManager
from tm_devices.drivers import MSO6B

from tekhsi import TekHSIConnect

addr = "192.168.0.1" # Replace with the IP address of your instrument

with DeviceManager(verbose=True) as device_manager:
scope: MSO6B = device_manager.add_scope(f"{addr}")
idn_response = scope.commands.idn.query()
print(idn_response)
# Make the waveform display OFF
scope.commands.display.waveform.write("OFF")
# Set the Horizontal mode to Manual
scope.commands.horizontal.mode.write("OFF")
# Set the horizontal Record Length
scope.commands.horizontal.mode.recordlength.write("2500")

# time.sleep(2) # Optional delay
# Connect to instrument via TekHSI, select channel 1
with TekHSIConnect(f"{scope.ip_address}:5000", ["ch1"]) as connect:
# Save data from 10 acquisitions
for i in range(10):
with connect.access_data():
waveform: AnalogWaveform = connect.get_data("ch1")
print(f"{waveform.source_name}_{i}:{waveform.record_length}")

# Make the waveform display ON
scope.commands.display.waveform.write("ON")
5 changes: 5 additions & 0 deletions docs/additional_examples_and_pseudo_codes/wait_on_new_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from tekhsi import AcqWaitOn, TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
with connection.access_data(AcqWaitOn.NewData):
...
Fixed Show fixed Hide fixed
5 changes: 5 additions & 0 deletions docs/additional_examples_and_pseudo_codes/wait_on_next_acq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from tekhsi import AcqWaitOn, TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
with connection.access_data(AcqWaitOn.NextAcq):
...
Fixed Show fixed Hide fixed
5 changes: 5 additions & 0 deletions docs/additional_examples_and_pseudo_codes/wait_on_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from tekhsi import AcqWaitOn, TekHSIConnect

with TekHSIConnect("192.168.0.1:5000") as connection:
with connection.access_data(AcqWaitOn.Time, after=0.5):
...
Fixed Show fixed Hide fixed
Loading
Loading