Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx fit AI Tasks together, but how?

Hi!

I do have several AI Channels, and I want to fit ai0 to ai3 together, i thought, I can do it with this statements:

this

.KraftT = new Task("");

this.KraftT.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai2,Dev1/ai3","",AITerminalConfiguration.Differential,0,10.0, AIVoltageUnits.Volts);

this.KraftT.Stream.ReadOverwriteMode = ReadOverwriteMode.OverwriteUnreadSamples;

this.KraftT.Timing.ConfigureSampleClock("",this.konfig.abtastfrequenz_kraft,SampleClockActiveEdge.Rising,

SampleQuantityMode.ContinuousSamples);

this.KraftC = new AnalogSingleChannelReader(this.KraftT.Stream);

 

Is this correct? So the only question now is: how can I access just ai0 ?
Before, I tried with one channel, and I made my access in this kind:

return NationalInstruments.Analysis.Math.Statistics.Mean(this.Vorspann_VoltageC.ReadMultiSample(System.Convert.ToInt32(this.Vorspann_VoltageT.Stream.AvailableSamplesPerChannel)));

But now, I want to access just a specific channel, like ai0, with which statement is this possible? How can I access to channels?
Do I have always to start and stop the task ?

Please help me, because in the Measurement help of dotNET, I am not able to find anything out!
Are there any manuals for programming in Visual Studio .NET together with the national instruments libraries available?

Yours, Klaus

0 Kudos
Message 1 of 10
(4,799 Views)
Greetings Klaus

When reading multiple channels in a task, use the AnalogMultiChannelReader instead of the AnalogSingleChannelReader.

Here is a snippet from the help for the multichannel reader read method:

A 2D array of floating-point samples from the task. Each element in the first dimension of the array corresponds to a channel in the task. Each element in the second dimension of the array corresponds to a sample from each of the channels.

The Help for the DAQmx functions is integrated into Visual Studio. For example, try selecting the AnalogSingleChannelReader and hit the F1 key. There is a complete reference as well as some application notes included in the help. You can also get to the Help by going to the Help Menu and selecting Contents.  WIth the Filter selected to "Measurement Studio .NET class libraries",  browse the Content tree by going to NI Measurement Studio Help >> NI Measurement Studio .NET class library >> Reference (go to the use topics instead if you want to get a high level overview of the functions) >> NationalInstruments.DAQmx.

I hope this helps.



Bilal Durrani
NI
0 Kudos
Message 2 of 10
(4,789 Views)

Great!

Thanks a lot!
The only problem I now have is, that If I start and stop the task, and than try again to start the task and read data, that I don't get any data in the 2dimension array!
I try to get the 2dimension array in this kind:

this.KraftT = new Task("");

this.KraftT.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai2,Dev1/ai3","",AITerminalConfiguration.Differential,0,10.0, AIVoltageUnits.Volts);
this.KraftT.Stream.ReadOverwriteMode = ReadOverwriteMode.OverwriteUnreadSamples;
this.KraftT.Timing.ConfigureSampleClock("",200,SampleClockActiveEdge.Rising,SampleQuantityMode.ContinuousSamples);

this

.KraftC = new AnalogMultiChannelReader(this.KraftT.Stream);

//to Read data:

this.KraftT.Start();
double [,] measures = this.KraftC.ReadMultiSample(System.Convert.ToInt32(this.myTask.Stream.AvailableSamplesPerChannel);
this.KraftT.Stop();

Always, when I try a second time to Start and Stop the task, there is no data from Reading the Multi Sample!

Please reply soon!
Thanks, Klaus1

0 Kudos
Message 3 of 10
(4,783 Views)

i found my mistake:

it was the AvailableSamplesPerChannel, which caused problems! Now I take 10 Samples and everything is OK! 🙂
Yours, Klaus

0 Kudos
Message 4 of 10
(4,784 Views)
oh no... i just have seen, that now the measurement has old values, and it takes 65ms just to read a single AI ? why that?
 
I mean, the voltage at the time I read in is one of the DAQMx Card Buffer, and not the realtime value!
What can I do?
Yours, Klaus
0 Kudos
Message 5 of 10
(4,777 Views)

How many samples are you reading? And whats the sample rate? Do you have a small example I would have a look at?

Bilal Durrani
NI
0 Kudos
Message 6 of 10
(4,765 Views)

About the reading old data, what might be happening is that your buffer is so large that its not actaully getting over-written by the new data. Use the DAQBuffer class to override the default buffer that DAQmx allocates for you based on the sample rate. See the help for DaqBuffer.InputBufferSize  for more information.

To use this, try the following

myTask.Stream.Buffer.InputBufferSize = 20 //need to experiment with what works for you.

I hope this helps

Bilal Durrani
NI
0 Kudos
Message 7 of 10
(4,758 Views)

I think i can use the property "RelativeTo" and than i have to set the integer to "DAQmx_Val_MostRecentSamp ? But how?

yours, Klaus
0 Kudos
Message 8 of 10
(4,746 Views)
OK, this helped in my constructor to have "new" values:

this

.AiT.Stream.ReadOffset=-1;

this.AiT.Stream.ReadRelativeTo = ReadRelativeTo.MostRecentSample;

The main problem is now that the function

double [,] measures = this.AiC.ReadMultiSample(10);

 

needs at least 100ms !!
Why that?

I configured:

this.AiT.Timing.ConfigureSampleClock("",100,SampleClockActiveEdge.Rising,

SampleQuantityMode.ContinuousSamples,10);

 

Yours, Klaus

 

0 Kudos
Message 9 of 10
(4,740 Views)

Your clock is configured for 100 samples per second. You are reading 10 samples,so if you have not already started the acquisition, it will take 100 ms for 10 samples to be read.

Bilal Durrani
NI
0 Kudos
Message 10 of 10
(4,727 Views)