Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

when does control return from a DIU32 operation in VC++?

Is there a way for me to initiate a long DAQ operation (unkonwn # of samples) using DAQmxReadDigitalU32() function in VC++, and then regain control of the program while aquisition continues (for concurrent data display and other purposes)?  there is the 'timeout' input parameter that says to put -1 for an unknown amount of time, but I want to regain control without having a timeout error
 
thanks, Ryan
0 Kudos
Message 1 of 9
(4,206 Views)
Hi Ryan-
 
There is no method to accomplish this directly, but you can workaround this by calling the DAQmx Read function in a loop with a small timeout value and simply ignore the timeout error number -200284 that will be thrown each time until the specified number of samples is available.  This will allow you to execute other code without blocking operation on the DAQmx Read function.
 
Hopefully this helps-
Tom W
National Instruments
0 Kudos
Message 2 of 9
(4,193 Views)
so after it throws the timeout error it will return control to the program and continue taking data until the specified number of samples is reached?

It seems like I will run the risk of missing data points in between DAQ function calls, no?

thanks

Ryan
0 Kudos
Message 3 of 9
(4,190 Views)
Hi Ryan-
 
What type of operation are you performing (i.e. hardware-timed or software-timed)?  Which device are you using?  For hardware-timed operations you will not lose data points using this method.  Other than this, waiting for the function to execute with software-timed operations is the only way to ensure that you receive all data without missing any points.
 
Hopefully this helps-
Tom W
National Instruments
0 Kudos
Message 4 of 9
(4,184 Views)
Hey Tom,

I am writing an app that takes a 32-bit digital data stream using an externally supplied clock.  I am using the 6534 card in VC++ with NIDAQmx functions.  The user must be able to initiate a data capture (start trigger) and then regain control of the program in order to any number of tasks:

1.  stop acquisition and save
2.  view streaming data plotted on screen
3.  restart new acquisition and trash old data
4.  restart new acquisition and save old data

For instance, if the user is viewing streaming data on screen, I need to be capturing data continuously and displaying on screen.  In order to do this, the DAQ function must pass control back to the program for the plot update code.

Should I be using a loop?  The user must be able to break out of this loop in order to do things like stop acquisition and save or restart new acquisition and save old data..

Thanks for your help.

Ryan
0 Kudos
Message 5 of 9
(4,182 Views)
I was thinking about your suggestion to call the DAQmx read function continuously in a loop and it seems like if I did this my program control would be continuously stuck in this loop and still not returning control to the program.  How would this work?
0 Kudos
Message 6 of 9
(4,174 Views)

Hi Ryan-

By calling the DAQmx Read in a loop and either varying the timeout or the number of samples to read you can read from the DAQ buffer in small chunks and also perform UI updates, look for user input, etc.  These calls would also take place within the loop.

If this method is not satisfactory then you might be able to run the two processes in seperate threads.  One thread would call the DAQmx read in a loop and pass data to another thread for use in graphing, etc.  The NI-DAQmx API is completely multi-thread safe, so you can make NI-DAQmx calls in both threads if necessary. 

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 7 of 9
(4,173 Views)

Hey Tom,

Okay I made this into a multithreaded dialog app which runs the DAQ loop in a worker thread and leaves the User Interface thread unblocked for data display or user input.

So far in DAQmx I have only done DAQ's where I specified a finite number of data points to get ahead of time.

In the case that I don't know how many samples that the user wants to take, (just sample data until the user says stop), should I be using a circular buffer type loop for my DAQ loop?

Also, as data comes in I want to continuously and temporarily store it to a file (contiunous file concatenation?) in the case that the user wants to save the data that they captured.  Is there a good sample code that illustrates this or am I on my own?

There was a double-buffered DAQ example in the traditional NIDAQ sample code, but I don't see one for DAQmx?

Thanks, Ryan

0 Kudos
Message 8 of 9
(4,154 Views)
Hi Ryan-
 
Double-buffering is performed implicitly by the NI-DAQmx driver when you specify "DAQmx_Val_ContSamps" for sampleMode in the DAQmxCfgSampClkTiming function.  This setting will continuously buffer samples that you can then read into your program by calling the DAQmx Read functions in a loop.  There is no need to configure the task for double buffering with this approach.  An example of continuous acquisition that runs until a stop is requested installs with the NI-DAQmx driver in the directory "C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Read Values\Cont Read Dig Chan-Ext Clk"
 
The NI-DAQmx driver does not ship with examples for File I/O because any generic approach should work just fine with NI-DAQmx.  My best suggestions would be to search on the internet for examples of opening files a single time and then writing to file within your main acquisition loop.
 
Hope this helps-
Tom W
National Instruments
0 Kudos
Message 9 of 9
(4,138 Views)