Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ All notable changes to this project will be documented in this file.
* [Full changelog: 1.4.1...1.5.0](https://github.com/ni/nidaqmx-python/compare/1.4.1...1.5.0)

* ### Resolved Issues
* ...
* [936: New example voltage_acq_int_clk_plot_wfm.py does not behave as expected](https://github.com/ni/nidaqmx-python/issues/936)

* ### Major Changes
* ...
Expand Down
31 changes: 25 additions & 6 deletions examples/analog_in/voltage_acq_int_clk_plot_wfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,41 @@
"""

import matplotlib.pyplot as plot
import numpy as np

import nidaqmx
from nidaqmx.constants import READ_ALL_AVAILABLE, AcquisitionType


def plot_analog_waveform(waveform, min_start_time=None):
"""Plot a single analog waveform."""
# For multiplexed devices, each channel has a different time offset, based on the AI Convert
# Clock rate. Calculate the time offset for this channel by subtracting the minimum start time.
time_offset = 0.0
if min_start_time is not None:
time_offset = (waveform.timing.start_time - min_start_time).total_seconds()
duration = waveform.sample_count * waveform.timing.sample_interval.total_seconds()
time_data = np.linspace(
time_offset, time_offset + duration, waveform.sample_count, endpoint=False
)
plot.plot(time_data, waveform.scaled_data, label=waveform.channel_name)


with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)

waveform = task.read_waveform(READ_ALL_AVAILABLE)
waveforms = task.read_waveform(READ_ALL_AVAILABLE)
if not isinstance(waveforms, list):
waveforms = [waveforms]

timestamps = list(waveform.timing.get_timestamps(0, waveform.sample_count))
time_offsets = [(ts - timestamps[0]).total_seconds() for ts in timestamps]
plot.plot(time_offsets, waveform.scaled_data)
min_start_time = min(waveform.timing.start_time for waveform in waveforms)
for waveform in waveforms:
plot_analog_waveform(waveform, min_start_time)
plot.xlabel("Seconds")
plot.ylabel(waveform.units)
plot.title(waveform.channel_name)
plot.ylabel(waveforms[0].units) # assume all channels have the same units
plot.title("Waveforms")
plot.legend()
plot.grid(True)

plot.show()
Loading