Skip to content

Commit a522bec

Browse files
committed
Add examples to demonstrate TDMS logging and data plotting
1 parent cc140f7 commit a522bec

File tree

5 files changed

+659
-127
lines changed

5 files changed

+659
-127
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Example of generating visualizations for acquired data.
2+
3+
This example demonstrates how to plot the acquired data.
4+
"""
5+
6+
import matplotlib.pyplot as plt
7+
8+
import nidaqmx
9+
from nidaqmx.constants import READ_ALL_AVAILABLE, AcquisitionType
10+
11+
with nidaqmx.Task() as task:
12+
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
13+
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)
14+
15+
data = task.read(READ_ALL_AVAILABLE)
16+
17+
plt.plot(data)
18+
plt.ylabel("Amplitude")
19+
plt.title("Waveform")
20+
plt.show()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Example of logging acquired data to TDMS file and read back.
2+
3+
This example demonstrates how to log the acquired data to a TDMS file
4+
and then read the data from the file.
5+
"""
6+
7+
import os
8+
9+
from nptdms import TdmsFile
10+
11+
import nidaqmx
12+
from nidaqmx.constants import (
13+
READ_ALL_AVAILABLE,
14+
AcquisitionType,
15+
LoggingMode,
16+
LoggingOperation,
17+
)
18+
19+
with nidaqmx.Task() as task:
20+
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
21+
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=10)
22+
task._in_stream.configure_logging(
23+
"TestData.tdms", LoggingMode.LOG_AND_READ, operation=LoggingOperation.CREATE_OR_REPLACE
24+
)
25+
26+
task.read(READ_ALL_AVAILABLE)
27+
28+
with TdmsFile.open("TestData.tdms") as tdms_file:
29+
for group in tdms_file.groups():
30+
for channel in group.channels():
31+
data = channel[:]
32+
print("Read data from TDMS file: [" + ", ".join(f"{value:f}" for value in data) + "]")
33+
34+
if os.path.exists("TestData.tdms"):
35+
os.remove("TestData.tdms")
36+
37+
if os.path.exists("TestData.tdms_index"):
38+
os.remove("TestData.tdms_index")

0 commit comments

Comments
 (0)