From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple channel read

Solved!
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);

flowMeterTask.Control(TaskAction.Verify);

 

reader = new AnalogMultiChannelReader(flowMeterTask.Stream);

 

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

0 Kudos
Message 1 of 6
(2,034 Views)

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

0 Kudos
Message 2 of 6
(2,020 Views)

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
(2,017 Views)

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
(2,012 Views)

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
(1,966 Views)
Solution
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();

pressureSensorList.Add(temp[0]);
dataSensor1List.Add(temp[1]);

0 Kudos
Message 6 of 6
(1,951 Views)