From 999f15d7a02a2c4a70e8a3f980c4983f2e3ef144 Mon Sep 17 00:00:00 2001 From: MAnoushe-NI <139955784+MAnoushe-NI@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:43:24 +0100 Subject: [PATCH 1/2] Add Time Based example for scheduled acquisition --- .../nidaqmx - time tased synchronization.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/nidaqmx - time tased synchronization.py diff --git a/examples/nidaqmx - time tased synchronization.py b/examples/nidaqmx - time tased synchronization.py new file mode 100644 index 000000000..a102961bf --- /dev/null +++ b/examples/nidaqmx - time tased synchronization.py @@ -0,0 +1,42 @@ +import nidaqmx +import time +from nidaqmx.constants import AcquisitionType +from datetime import timedelta, datetime, timezone +import matplotlib.pyplot as plt + +# Function to perform the measurement +def perform_measurement(): + with nidaqmx.Task() as task: + task.ai_channels.add_ai_voltage_chan("cDAQ9189-1DF40B6Mod8/ai0") + + # Configure finite sampling + num_samples = 10000 + task.timing.cfg_samp_clk_timing(10000, sample_mode=AcquisitionType.FINITE, samps_per_chan=num_samples) + + # Calculate the start time (1 minute from now) + start_time = datetime.now(timezone.utc) + timedelta(minutes=1) + print(f"Scheduled start time: {start_time}") + + # Configure the time start trigger + task.triggers.start_trigger.cfg_time_start_trig(start_time) + + print("Starting the task...") + task.start() + + print(nidaqmx.__version__) + # Wait until the scheduled start time + while datetime.now(timezone.utc) < start_time: + time.sleep(1) + + # Read data after the task starts + data = task.read(number_of_samples_per_channel=num_samples) + + # Plot the data + plt.plot(data) + plt.title('Measurement Data') + plt.xlabel('Sample Number') + plt.ylabel('Voltage') + plt.show() + +# Perform the measurement +perform_measurement() \ No newline at end of file From b4316bb8364f1833a7837844714704c471cfc170 Mon Sep 17 00:00:00 2001 From: MAnoushe-NI <139955784+MAnoushe-NI@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:53:36 +0100 Subject: [PATCH 2/2] Add Time Based example for scheduled acquisition --- examples/nidaqmx - time tased synchronization.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/nidaqmx - time tased synchronization.py b/examples/nidaqmx - time tased synchronization.py index a102961bf..554dc729d 100644 --- a/examples/nidaqmx - time tased synchronization.py +++ b/examples/nidaqmx - time tased synchronization.py @@ -2,16 +2,15 @@ import time from nidaqmx.constants import AcquisitionType from datetime import timedelta, datetime, timezone -import matplotlib.pyplot as plt # Function to perform the measurement def perform_measurement(): with nidaqmx.Task() as task: - task.ai_channels.add_ai_voltage_chan("cDAQ9189-1DF40B6Mod8/ai0") + task.ai_channels.add_ai_voltage_chan("Dev1/ai0") # Configure finite sampling - num_samples = 10000 - task.timing.cfg_samp_clk_timing(10000, sample_mode=AcquisitionType.FINITE, samps_per_chan=num_samples) + num_samples = 1000 + task.timing.cfg_samp_clk_timing(1000, sample_mode=AcquisitionType.FINITE, samps_per_chan=num_samples) # Calculate the start time (1 minute from now) start_time = datetime.now(timezone.utc) + timedelta(minutes=1) @@ -23,7 +22,7 @@ def perform_measurement(): print("Starting the task...") task.start() - print(nidaqmx.__version__) + print("Waiting for the scheduled start time...") # Wait until the scheduled start time while datetime.now(timezone.utc) < start_time: time.sleep(1) @@ -31,12 +30,5 @@ def perform_measurement(): # Read data after the task starts data = task.read(number_of_samples_per_channel=num_samples) - # Plot the data - plt.plot(data) - plt.title('Measurement Data') - plt.xlabel('Sample Number') - plt.ylabel('Voltage') - plt.show() - # Perform the measurement perform_measurement() \ No newline at end of file