-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added and updated AI examples * reworked as per given comments * fixed style error * added pprint in event example * reworked and file renamed as per suggestions * remind user before start task in event example * reduced samples per chan * reduced samples per chan for event example * print total read in cont examples * removed samps_per_chan for cont examples * added :f for single read examples
- Loading branch information
1 parent
5e0380b
commit db57411
Showing
6 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Example of analog input voltage acquisition. | ||
This example demonstrates how to acquire a continuous amount of data | ||
using the DAQ device's internal clock. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import AcquisitionType | ||
|
||
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.CONTINUOUS) | ||
task.start() | ||
print("Running task. Press Ctrl+C to stop.") | ||
|
||
try: | ||
total_read = 0 | ||
while True: | ||
data = task.read(number_of_samples_per_channel=1000) | ||
read = len(data) | ||
total_read += read | ||
print(f"Acquired data: {read} samples. Total {total_read}.", end="\r") | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
task.stop() | ||
print(f"\nAcquired {total_read} total samples.") |
39 changes: 39 additions & 0 deletions
39
examples/analog_in/cont_voltage_acq_int_clk_every_n_samples_event.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Example of analog input voltage acquisition with events. | ||
This example demonstrates how to use Every N Samples events to | ||
acquire a continuous amount of data using the DAQ device's | ||
internal clock. The Every N Samples events indicate when data is | ||
available from DAQmx. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import AcquisitionType | ||
|
||
|
||
def main(): | ||
"""Continuously acquires data using an Every N Samples event.""" | ||
total_read = 0 | ||
with nidaqmx.Task() as task: | ||
|
||
def callback(task_handle, every_n_samples_event_type, number_of_samples, callback_data): | ||
"""Callback function for reading singals.""" | ||
nonlocal total_read | ||
read = len(task.read(number_of_samples_per_channel=number_of_samples)) | ||
total_read += read | ||
print(f"Acquired data: {read} samples. Total {total_read}.", end="\r") | ||
|
||
return 0 | ||
|
||
task.ai_channels.add_ai_voltage_chan("Dev1/ai0") | ||
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.CONTINUOUS) | ||
task.register_every_n_samples_acquired_into_buffer_event(1000, callback) | ||
task.start() | ||
|
||
input("Running task. Press Enter to stop.\n") | ||
|
||
task.stop() | ||
print(f"\nAcquired {total_read} total samples.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Example of analog input temperature acquisition. | ||
This example demonstrates how to acquire thermocouple measurement using | ||
software timing. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import ThermocoupleType, TemperatureUnits | ||
|
||
with nidaqmx.Task() as task: | ||
task.ai_channels.add_ai_thrmcpl_chan( | ||
"Dev1/ai0", units=TemperatureUnits.DEG_C, thermocouple_type=ThermocoupleType.K | ||
) | ||
|
||
data = task.read() | ||
print(f"Acquired data: {data:f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Example of analog input voltage acquisition. | ||
This example demonstrates how to acquire a finite amount | ||
of data using the DAQ device's internal clock. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE | ||
|
||
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) | ||
|
||
data = task.read(READ_ALL_AVAILABLE) | ||
print("Acquired data: [" + ", ".join(f"{value:f}" for value in data) + "]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Example of analog input voltage acquisition. | ||
This example demonstrates how to acquire a voltage measurement using software timing. | ||
""" | ||
|
||
import nidaqmx | ||
|
||
with nidaqmx.Task() as task: | ||
task.ai_channels.add_ai_voltage_chan("Dev1/ai0") | ||
|
||
data = task.read() | ||
print(f"Acquired data: {data:f}") |