11-28-2012 10:41 AM
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
Solved! Go to Solution.
11-29-2012 01:11 PM
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,
11-30-2012 11:04 AM
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
11-30-2012 02:08 PM
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