12-21-2014 03:15 PM
Hi all,
in my application i need to acquire data through a pcie 6323 with C# .Net.
For my purpose when i start the software the NI card is configured to acquire data in continuoussample mode.
After user acts on main form and press start button, i call again
analogInputTask.Timing.ConfigureSampleClock( ClockSource , SampleRate , ActiveEdge , SampleMode // starts in continuous samples to switch to finite samples when acting on main form , samplesPerChannel);
with samplemode = finitesamples
The callback i use to call through following lines of code:
this.analogInputAsyncResult = this.analogReader.BeginReadWaveform( SamplesPerChannel , analogInputReaderCallback , analogInputTask );
is this:
private void AnalogInCallback(IAsyncResult ar) { try { if (runningAnalogInputTask != null && runningAnalogInputTask == ar.AsyncState) { /// Handles the end of an asynchronous read initiated with /// BeginReadWaveform and retrieves the read samples. /// REMARKS /// If you call EndReadWaveform before the asynchronous read /// represented by the provided IAsyncResult is complete, /// EndReadWaveform waits for the read to complete before returning. analogInputReaderData = analogReader.EndReadWaveform(ar); try { double[] buffer = new double[SamplesPerChannel]; DateTime[] dtBuffer = new DateTime[SamplesPerChannel]; using (TimedLock.Lock(AnalogInputs)) { if (analogInputReaderData != null && analogInputReaderData.Length > 0) { try { foreach (SampleBuffer<double> input in AnalogInputs) { var inputData = analogInputReaderData .Where<AnalogWaveform<double>>(r => r.ChannelName.Equals(input.Name)) .Single(); /// Read samples inputData.GetBuffer(true).CopyTo(buffer, 0); input.AddSamples(buffer); /// Read timestamps inputData.GetTimeStampBuffer().CopyTo(dtBuffer, 0); input.AddTimeStamps(dtBuffer.Select(dt => dt.Ticks)); } OnSampleBufferChanged(new SampleBufferChangedEventArgs(AnalogInputs)); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } } catch (LockTimeoutException) { } /// Restart reading analogReader.BeginMemoryOptimizedReadWaveform( SamplesPerChannel , analogInputReaderCallback , analogInputTask , analogInputReaderData ); } } catch (DaqException ex) { #if DEBUG Debug.WriteLine(ex.Message); #endif runningAnalogInputTask = null; analogInputTask.Dispose(); } }
i'd like to ask you if with the check i do with
if (analogInputReaderData != null && analogInputReaderData.Length > 0)
is correct to see if there is incoming acquired samples. What i mean is that when i switch to finitesamples the callback is the same so before the trigger starts i want to not perform any processing on the acquired data premise that there is a way to check that buffer is empty 'cause the trigger is not yet started.
Thanks in advance
12-22-2014 02:09 PM
Consider looking at the C# examples that should have been installed during your installation of NI-DAQmx.
12-28-2014 10:59 AM
Sure, but it would be better if some NI expert share with me some link with deep explanation of this.
Also when i've tried to modify the code to understand it better i've noticed that callback is called also when board is in finite sample mode and trigger is not yet detected.
Now instead the callback in the same situation is called only if trigger is detected