PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read DAQmx task data into a timed loop on a PXI?

I am running into problems using DAQmx on a PXI-1031 system. Specifically, I am unable to read data collected by a DAQmx task into a timed loop. In my setup I have 8 analog input channels that are read and stored using two separate loops:

1. Store ch0-ch7 data at 2kHz
2. Read ch6 data in a 16ms timed loop

I am able to implement the storage fine, by initializing an 8 channel 2kHz continuous-sample DAQ task (outside any loops), then reading 200 samples/channel using DAQmx Read (Analog 2D DBL NChan NSamp) in a while loop (this gives a 100ms period for the 'storage' loop).

The problem arises when I try to read ch6 data into the 16ms deterministic loop. The ch6 data represents control feedback for an actuator running at 16ms, therefore it only needs to read the most recent data value (i.e. it does not need to store any extra data between 16ms periods). It would seem easiest if there were a way to simply query the current data coming from the 2kHz DAQ task, but I have tried this with another DAQmx Read block off the existing 2kHz task, with no success. Moreover, my understanding is that even if it could read from the same task, it would remove data from the buffer - stealing this data away from the storage loop.

The only way I have been able to successfully implement this:
- increase the speed of the storage loop to <16ms period (by reducing the number of samples to read per iteration)
- write one ch6 data element (DBL) to a local variable
- read this local variable in the 16ms control loop

This seems like a very ad hoc solution, with the drawback that it forces the storage loop to work much harder than necessary. I am certain there is a better way than this, though I cannot find any information in the help files. Can anyone suggest a better implementation for reading analog data into a timed loop?
0 Kudos
Message 1 of 2
(3,232 Views)

tph,

 

How much data do you need to read from ch6 every 16ms (all deterministic mind you)?

 

You mention that you are worried about pulling data out of the buffer excluding your other loop.  Why can't you pull the data out and then send it to both loops (one writing to disk/one "reading?")? 

 

I am not sure if this is your implementation, but if it is not you might look into a Producer/Consumer loop. 

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 2 of 2
(3,220 Views)