09-03-2021 10:01 AM
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
Solved! Go to Solution.
09-03-2021 11:57 AM
try dataSensor2.Add(reader.ReadSingleSample()[0]);
09-03-2021 12:06 PM
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.
09-03-2021 12:47 PM
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
09-07-2021 12:42 PM
Maybe an example project with multiple channels would help to reference but I was not able to find any. Does anyone know of one?
09-09-2021 12:35 PM
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]);