Quantcast
Channel: Digital I/O topics
Viewing all articles
Browse latest Browse all 2182

Start a read task triggered by a digital write task

$
0
0

Hello,

 

I am using the PCIe6363 DAQ board and need precisely timed data acquisition using Python.

 

My goal is to start reading analog inputs (AI) as soon as I write a digital output (DO) task.

In practice the DO task shuts off a relay, and as soon as it shuts off, I want to acquire data.

 I can not see through the NIDAQmx documentation as my python knowledge is very limited.

 

Here is a minimal example of what is not working:

 

 with ni.Task() as task_DO_AC, ni.Task() as task_AI:

     # Add analog input channels
     task_AI.ai_channels.add_ai_voltage_chan("PCIe6363/ai1")

     # Add digital output channels
     task_DO_AC.do_channels.add_do_chan("PCIE6363/PFI1")
     DO_AC_write = [True]

# Set sample rate and numbers of samples to write at this sample rate
task_AI.timing.cfg_samp_clk_timing(rate=sr,source='OnboardClock',sample_mode=AcquisitionType.FINITE,samps_per_chan=int(sr*AI_t))
task_DO_AC.timing.cfg_samp_clk_timing(rate=sr, source='OnboardClock',sample_mode=AcquisitionType.FINITE,samps_per_chan=int(sr*AI_t))

# trigger write_task as soon as read_task starts
task_DO_AC.triggers.start_trigger.cfg_dig_edge_start_trig(task_AI.triggers.start_trigger.term)

# Write DO_AC
task_DO_AC.write(DO_AC_write, auto_start=False)
task_DO_AC.start()

# Pause code (better than waiting for task to finish)
time.sleep(AO_AC_t)

# Close the channels
task_DO_AC.write(list(np.invert(DO_AC_write)))

# Read out the signal
signal = task_AI.read(int(sr*AI_t))

 

-----

It seems strange, that DO channels can not be buffered.

I have the same task for starting and stopping the DO, otherwise it will just stay open.

How to do I trigger the read task together with the second DO task?

 

Thanks for any help.


Viewing all articles
Browse latest Browse all 2182

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>