Skip to content

Commit

Permalink
fix: added directory under docs to maintain pseudocode used in docume…
Browse files Browse the repository at this point in the history
…ntation.
  • Loading branch information
u625355 committed Sep 19, 2024
1 parent a57e794 commit 1d803e7
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 221 deletions.
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")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch1' is not used.
ch3: AnalogWaveform = connection.get_data("ch3")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch3' is not used.
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")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch1' is not used.
ch3: AnalogWaveform = connection.get_data("ch3")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch3' is not used.
ch1_iq: IQWaveform = connection.get_data("ch1_iq")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch1_iq' is not used.
ch4_dall: DigitalWaveform = connection.get_data("ch4_DAll")

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'ch4_dall' is not used.
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
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
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

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'vd' is not used.
y_axis = wfm.y_axis_units

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'y_axis' is not used.
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

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'vd' is not used.
y_axis = wfm.y_axis_units

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'y_axis' is not used.
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)

Check notice

Code scanning / CodeQL

Unused global variable Note documentation

The global variable 'vd' is not used.
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):
...

Check notice

Code scanning / CodeQL

Statement has no effect Note documentation

This statement has no effect.
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):
...

Check notice

Code scanning / CodeQL

Statement has no effect Note documentation

This statement has no effect.
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):
...

Check notice

Code scanning / CodeQL

Statement has no effect Note documentation

This statement has no effect.
Loading

0 comments on commit 1d803e7

Please sign in to comment.