06-13-2013 03:03 PM
What controls when analogCallback is called after you run:
analogInReader.BeginReadWaveform(-1, analogCallback, myTask);?
I found a webpage on this site that discusses the buffer size that Nidaqmx allocates depending on you samples rate:
http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/buffersize/ .
But what about the last argument when you set up the timing of the channel? As in:
// Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", ADParams.sample_rate,SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100000);
Here I set the buffer to 100,000 samples? Will this be used or does Nidaq pick its own value?
After how many samples will the callback be called?
Thanks,
Dave
06-14-2013 06:10 PM
HI Dave,
What the page you linked is explaining, is that DAQmx will use the 100kS like you input, and the callback will run after this amount is reached, unless that sample size falls below the limits for the sample rate on the table. For example, if you specified a sample size of 100kS, but wanted to set your acquisition sample rate higher than 1MS/s (the last value in the table), the buffer size will be coerced to the next size up, 1MS. So, as long as you don't sample faster than 1MS/s, you should get the 100kS buffer size like you mentioned.
06-14-2013 06:28 PM
Doesn't it need to callback when like half the buffer is full? Otherwise you'll overwrite before the callback has a chance to do anything.
06-17-2013 04:15 PM
I took a closer look at the analogInReader.BeginReadWaveform function. I believe that the callback is executing as soon as it is reached in the execution process. The samplePerChannel parameter controls the amount of data that is read whenever this callback executes; i.e. if you specify 100000, it will try to acquire that many samples from the buffer. If you set this to -1 in continuous acquisition, however, the read function will just read all available samples in the buffer.
So while you set the actual size of the buffer using the myTask.Timing.ConfigureSampleClock function, the analogInReader.BeginReadWaveform will control how many samples are drawn from the buffer each time the callback executes. To avoid over/underwriting, I would recommend using the -1 for samples to acquire from the buffer, unless you are sure that you will be able to acquire a certain number of samples from the buffer at each callback.
06-18-2013 01:24 AM
Ah Grasshopper ... and so we return to our original question. I call this the 'circle of help'. Just kidding. Its fun trying to reverse engineer what those smart NI programmers build into these things. Documentation would be too easy. So when does the callback get called? Its is very fast, but will it sometime be delayed by windows? I need to stream to disk for about 4 hours without crashing.
06-18-2013 05:58 PM
Yeah, I definitely understand, documentation can be sparse for some of our text based API functions. I'm fairly certain the callback works like this: when it is used as an argument in the BeginReadWaveform function, it allows the read function to run in a separate thread. This is so that it will not bog down the interface thread, which should remain as uninterrupted as possible. The callback would be called immediately, but the time it takes to return won't be consistent every time, since it depends on what else is going on in Windows, like you mentioned, and also depends on how long it takes to move the samples from the hardware buffer on your DAQ card, to your system's internal memory.
Basically, it is setup to work so that you should be fine running it for extended periods, as long as your buffer is large enough to handle the sample rate you set (the time to read from the hardware buffer to your system should be negligible in comparison). Hope this helps!
06-18-2013 06:03 PM
Ok, thanks. the program is running: 4 ch at 20kHz sampling, grabbing 'waveform<double>s ' and writng them to disk. Just a matter of trying it out. Seems like it would be better to just read U16's, but I could not get the right combination of the channel setup, timing, and read functions to return anything (callback never called). I'll start a new thread on this, maybe.