Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Start a read task triggered by a digital write task

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.

0 Kudos
Message 1 of 3
(776 Views)

I'm no help with any Python syntax.  Here's a fairly easy way to do what you need without getting into a lot of detailed DAQmx work.

 

Physically loopback the DO signal that controls your relay as an additional channel for your AI task.  Then in your post-processing you can identify exactly when you toggled your relay so you know which portion of your AI data is relevant.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 2 of 3
(731 Views)

Thanks!

I will try this. It will be accurate, I agree.

However this method is not yet very satisfying as it requires additional calculation time and it it does not reduce the delay between the end of the AO and the shutting down of the relay using DO. 

 

I will update when I find out more.

0 Kudos
Message 3 of 3
(705 Views)