02-08-2010 08:33 AM
02-08-2010 10:58 AM
acgrama,
DAQmx read will not return until it has copied all of the requested data into your 'A' array (unless an error occurs). So as long as you are waiting for the call to DAQmx Read to return inside your critical section, the data will be copied to A before T2 accesses it.
Hope that helps,
Dan
02-08-2010 02:14 PM
Additionally, I'm guessing that you're trying to accomplish asynchronous execution of your computational code while reading from the DAQmx device, but you might not need to make the application so optimized.
What I mean is:
The DAQmx Read already copies data to an intermediate buffer. Actually, what happens is that the onboard memory for the device is constantly being transferred (typically through DMA) to a reserved user-kernel shared buffer on the host PC. When you call DAQmx Read, it copies a chunk of data from that circular user-kernel buffer into your application memory. Therefore, essentially, what you are trying to do is already actually done internally by DAQmx. There could be some value in adding another buffer in some cases, but in most cases, this approach would be taxing memory bandwidth for little or no benefit. Additionally, consider the maintainability and ease of such a design - that is, maintaining a synchronization object and ensuring that a race condition can't occur (for instance, consumer tries to access buffer twice in a row before producer gets to execute twice - however unlikely this could be).
In summary, I would consider whether this design is really necessary at 44 kHz. It might be easier and more maintainable to simply do the processing "in the loop"; that is, either call DAQmx Read and do processing in the same loop iteration, or register for an Every N Event and do the processing in the callback.
02-09-2010 03:51 AM
02-09-2010 10:53 AM
That seems like a reasonable design considering your application.
You are correct in that a DAQmx task will reserve a DAQ card such that no other task can use it while in use.
That being said, there is a feature that you might find helpful for your application. You can filter the read call to specific channels. There's a DAQmx Read property for "Channels to Read". In the C API, the function call would be DAQmxSetReadChannelsToRead(...). If you're using the C++ API, there's a"set_ChannelsToRead" method on the stream.
02-10-2010 03:29 AM
I did not know the feature you mention, it will be very useful to me!
Thank you so much for the feedback 🙂