Measurement Studio for .NET Languages

Showing results for 
Search instead for 
Did you mean: 

multiple channel read

Go to solution

Hello, I have added two channels to a task and I can read one but when I try to read the second, I get an out of range error. 


flowMeterTask.AIChannels.CreateCurrentChannel(flowsensor1name, "FlowRate1Voltage", sensorMeasurementType, minCurrentIn, maxCurrentIn, AICurrentUnits.Amps);
flowMeterTask.AIChannels.CreateCurrentChannel(flowsensor2name, "FlowRate2Voltage", sensorMeasurementType, minCurrentIn, maxCurrentIn, AICurrentUnits.Amps);

flowMeterTask.Timing.ConfigureSampleClock("", samplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberOfSamples);



reader = new AnalogMultiChannelReader(flowMeterTask.Stream);


dataSensor2.Add(reader.ReadSingleSample()[1]); //says out of range here

0 Kudos
Message 1 of 6

try dataSensor2.Add(reader.ReadSingleSample()[0]);

0 Kudos
Message 2 of 6

Thanks for the reply! wouldn't that just be reading my sensor 1 though since it is channel 0?


also update: I am able to read data for a while and then after about 95 samples per channel it hits that out of range exception. 

0 Kudos
Message 3 of 6

I guess I am not getting an out of range error anymore. it just hangs at some point when trying to read the sensors. Sometimes its the first sensor read and sometimes its the second. I am able to read from a single sensor all the way through every time but when I add the second one it hangs up at some point. Thanks for any ideas or input

0 Kudos
Message 4 of 6

Maybe an example project with multiple channels would help to reference but I was not able to find any. Does anyone know of one?

0 Kudos
Message 5 of 6
Accepted by topic author chandrian

I realized I was actually reading twice instead of grabbing the whole array of values at once like this:


dynamic temp = reader.ReadSingleSample();


0 Kudos
Message 6 of 6