Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

get all available samples on USB-6229

Hi,

 

I am using C# and MeasurementStudio to acquire continiously an analog signal with a USB-6229.

Sometimes I need to get N samples and sometimes I need to read all available samples on the DAQ buffer.

 

The code I use is:

 

public class AITask : Task

{

private AnalogMultiChannelReader reader;

 

 public AITask(String name): base(name)

{

// Link a writer_csv to the task

reader = new AnalogMultiChannelReader(this.Stream);

}

 

 public void AddChannel(List<TestbenchChannel_DAQ_AIN> ain, double rate)

{

int N = ain.Count;
 for (int i = 0; i < N; i++)

{

....

 

//Create virtual trigger_channel in task

 this.AIChannels.CreateVoltageChannel(channel.device + @"/" + channel.terminal, channel.channel_name,

aiTerminalConfiguration, min, max, scaleName);

}
// end for all AIN oracle_channels

 

//Configure the timing parameters

 this.Timing.ConfigureSampleClock("", rate, SampleClockActiveEdge.Rising,  SampleQuantityMode.ContinuousSamples);

}

 

public AnalogWaveform<double>[] GetValues(int N)

{

N = (int)this.Stream.CurrentWritePosition - (int)this.Stream.CurrentReadPosition;

AnalogWaveform<double>[] wf = (AnalogWaveform<double>[]) reader.ReadWaveform(N); return wf;

}

 

where TestbenchChannel_DAQ_AIN contains all the needed parameters to define the AI channels.

 

To read the sample, I am calling the function GetValues(int N). N > 0 for a finite number of samples or N=-1 when I want to get all available samples on the buffer.

 

Now the problem is that sometimes after a pause of 2s where I am not calling the function GetValues, a call to this function with N=-1 will return an array of waveform with no samples. Most of the time I am getting the available samples but sometimes not.

 

Why? Where is the problem? When I am using this function on a PCI-6014, it works! 

 

Thanks for any help!

Risotto

0 Kudos
Message 1 of 3
(2,831 Views)

Hi Risotto,

when you are saying that after a pause you do not get any samples back, do you get any error messages indicating e.g. a buffer overflow?

 

I am not quite sure why you are reading the current write position - this indicates the sample position for the output buffer.

 

Which DAQmx version are you using? 

 

Regards,

Peter

--
Peter A.
Field Sales Engineer, NI Germany
0 Kudos
Message 2 of 3
(2,781 Views)

Hi Peter,

 

 

No I get neither error message nor exception. An I set the buffer to contains 30 minutes of measurements (I need it sometimes). And because I am usually reading the data each 2 seconds, the read position should be updated each 2 seconds.

 

On PCI-6014, this is working well. May be it is due to the communication with USB?

 

Anyway I have made an error copying the function GetValues and put some code I was using trying to solve my problem.

The right code is:

public AnalogWaveform<double>[] GetValues(int N)

{

  AnalogWaveform<double>[] wf = (AnalogWaveform<double>[]) reader.ReadWaveform(N);

  wf = (AnalogWaveform<double>[])reader.ReadWaveform(N);

return wf;

 

With this code, I am getting the problem I explained in my first post.

 

 

Now after several tries, I found a - not nice - solution to get anyway the data:

 public AnalogWaveform<double>[] GetValues(int N)

{

  AnalogWaveform<double>[] wf = (AnalogWaveform<double>[]) reader.ReadWaveform(N);

  int i = 0;

  while ((wf[0].SampleCount == 0) && (i < 101))

  {

    wf = (
AnalogWaveform<double>[])reader.ReadWaveform(N);     Thread.Sleep(1);

    i++;

  }

 

  return wf;

}

 

I am not really happy whith this because I don't understand what appends, but until now it seems to work.

Anyway I would be happy if you could give me some hints which could help me to understand the problem.

 

Regards,

Risotto

0 Kudos
Message 3 of 3
(2,775 Views)