Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Placing multiple channels' data into arrays

Solved!
Go to solution

 Right now I have a sample program with 8 channels worth of data from my USB 6009 spewing into a waveform graph, which looks and functions very nicely. Ideally I would like to take that data and manipulate it to produce two calculations before it gets out onto the graph. After I'd manipulate them I'd want to display them onto a (scatter?) graph as two continously updating lines. I'm thinking if I can get my 8 channels into 8 separate arrays the rest would fall into place.

 

Thanks

0 Kudos
Message 1 of 4
(5,115 Views)
Solution
Accepted by topic author lwild

Hi Iwild,

 

How are you importing your data?  Are you not placing data into an array to begin with?

 

Are you using NI-DAQmx?  If so, please see this document which goes over how to use NI-DAQmx with text-based environments.

 

Warm Regards,

Daniel Dorroh
National Instruments
0 Kudos
Message 2 of 4
(5,105 Views)

Hi,

 

Try this. It's in VB but It shouldn't be too hard to convert this to C#

 

ArrayOperation is a member of NationalInstruments.Analysis.Math class

 

            Dim sampleRate As Double = 1000
            Dim rangeMin As Double = 0
            Dim rangeMax As Double = 10 '5
            Dim samplesPerChan As Int32 = 100
            
            ' Create a channel
            myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:3", "", CType(-1, AITerminalConfiguration), rangeMin, rangeMax, AIVoltageUnits.Volts)

            ' Configure timing specs 
            myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChan)

            ' Verify the task
            myTask.Control(TaskAction.Verify)
            reader = New AnalogMultiChannelReader(myTask.Stream)

            ' Read the data
            Dim data As Double(,) = reader.ReadMultiSample(samplesPerChan)

            Dim data0(samplesPerChan) As Double
            Dim data1(samplesPerChan) As Double
            Dim data2(samplesPerChan) As Double
            Dim data3(samplesPerChan) As Double
            
            data0 = ArrayOperation.CopyRow(data, 0)
            data1 = ArrayOperation.CopyRow(data, 1)
            data2 = ArrayOperation.CopyRow(data, 2)
            data3 = ArrayOperation.CopyRow(data, 3)

            Average1 = Statistics.Mean(data1)
            Average2 = Statistics.Mean(data2)
            Average3 = Statistics.Mean(data3)

 

Hope this helps

 

Curt

0 Kudos
Message 3 of 4
(5,096 Views)

Thanks guys. I checked out the link and ended up using a 2-dimensional array to play the reader's results into.

 

Code looks like the following..

 

On form load:

_task = New Task()

_task.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3,Dev1/ai4,Dev1/ai5,Dev1/ai6,Dev1/ai7", CStr(0 + 1), AITerminalConfiguration.Rse, 0, 10, AIVoltageUnits.Volts) 

_task.Timing.ConfigureSampleClock("", 2000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 8)

_task.Control(TaskAction.Verify)

 

Timed event:

Dim analogInReader As AnalogMultiChannelReader = New AnalogMultiChannelReader(_task.Stream)
dataArray = analogInReader.ReadMultiSample(8)

 

Made it real easy to pull the data from dataArray and dump into some formulas.

 

Thanks again to both of you, and let me know if my code looks like it needs any tweaking or changes.

 

Take care

0 Kudos
Message 4 of 4
(5,089 Views)