I'm using NI 9207 with cDAQ-9174, from Visual Studio 2013 (.net3.5)
What I want to do is,
- measure analog input voltage from NI 9207
- sampling speed 30msec interval ( = 30000Hz ), sampling count 1000
- call function then starts sampling, and waits till sampling is in end, then get analog input data ( 1000 sample datas)
And I wrote a code like below.
public void Setup(string[] aiChannelNames, double max, double min, int samplingCount, double samplingSpeed_Hz) { try { if(aiTask != null) { aiTask.Stop(); aiTask.Dispose(); } aiTask = new Task(NI_MULTI_ADC_TASK_NAME); foreach (var aiChannelName in aiChannelNames) { AIChannel aiChannel = aiTask.AIChannels.CreateVoltageChannel( aiChannelName, aiChannelName.Replace("/", ""), AITerminalConfiguration.Differential, min, max, AIVoltageUnits.Volts ); aiChannelList.Add(aiChannel); } this.samplingCount = samplingCount; aiTask.Timing.ConfigureSampleClock( string.Empty, // for internal clock samplingSpeed_Hz, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, samplingCount ); multiChannelReader = new AnalogMultiChannelReader(aiTask.Stream); } catch (Exception) { throw; } } public double[,] MultiRead() { double[,] multiSampleDatas = null; try { if (multiChannelReader == null) { throw new Exception("NI_Multi_ADC not setup"); } aiTask.Stop(); //aiTask.Start(); multiSampleDatas = multiChannelReader.ReadMultiSample(samplingCount); } catch (Exception) { throw; } return multiSampleDatas; }
First call Setup(...) method, and after, call MultiRead() method for several times.
In unit test, I tested MultiRead() function.
( called method Setup("...", 10, 0, 1000, 30000) )
For result, this function does not takes time for 30msec * 1000 ( = 30sec ), method ended in about 300msec, but 1000 sampling data is returned.
For question,
1. Why ReadMultiSample() ends and returns data so quickly? When is sampling started?
2. Do you need asynchronous callback to wait till sampling data is sampled? Is there a class or method for this?
3. Witch sample code or document is good to read for this quesiton?