diff --git a/examples/analog_in/ai_voltage_sw_timed.py b/examples/analog_in/ai_voltage_sw_timed.py deleted file mode 100644 index 4fd3c509c..000000000 --- a/examples/analog_in/ai_voltage_sw_timed.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Example of AI voltage sw operation.""" - -import pprint - -import nidaqmx - -pp = pprint.PrettyPrinter(indent=4) - - -with nidaqmx.Task() as task: - task.ai_channels.add_ai_voltage_chan("cDAQ1Mod1/ai0") - - print("1 Channel 1 Sample Read: ") - data = task.read() - pp.pprint(data) - - data = task.read(number_of_samples_per_channel=1) - pp.pprint(data) - - print("1 Channel N Samples Read: ") - data = task.read(number_of_samples_per_channel=8) - pp.pprint(data) - - task.ai_channels.add_ai_voltage_chan("cDAQ1Mod1/ai1:3") - - print("N Channel 1 Sample Read: ") - data = task.read() - pp.pprint(data) - - print("N Channel N Samples Read: ") - data = task.read(number_of_samples_per_channel=2) - print(data) diff --git a/examples/analog_in/cont_voltage_acq_int_clk.py b/examples/analog_in/cont_voltage_acq_int_clk.py new file mode 100644 index 000000000..8381a77ae --- /dev/null +++ b/examples/analog_in/cont_voltage_acq_int_clk.py @@ -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.") diff --git a/examples/analog_in/cont_voltage_acq_int_clk_every_n_samples_event.py b/examples/analog_in/cont_voltage_acq_int_clk_every_n_samples_event.py new file mode 100644 index 000000000..34785fcf5 --- /dev/null +++ b/examples/analog_in/cont_voltage_acq_int_clk_every_n_samples_event.py @@ -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() diff --git a/examples/analog_in/thrmcpl_sample.py b/examples/analog_in/thrmcpl_sample.py new file mode 100644 index 000000000..b61500c1b --- /dev/null +++ b/examples/analog_in/thrmcpl_sample.py @@ -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}") diff --git a/examples/analog_in/voltage_acq_int_clk.py b/examples/analog_in/voltage_acq_int_clk.py new file mode 100644 index 000000000..3debb6ef3 --- /dev/null +++ b/examples/analog_in/voltage_acq_int_clk.py @@ -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) + "]") diff --git a/examples/analog_in/voltage_sample.py b/examples/analog_in/voltage_sample.py new file mode 100644 index 000000000..15fec221a --- /dev/null +++ b/examples/analog_in/voltage_sample.py @@ -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}")