Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Put acquired data into an array

Hello. I am using a NI DAC card to read data from two sources. I want to export my data to an excel file. First I want to put the acquired data into the form of an array before writing to an Excel file. Does anyone know how I can do this?

0 Kudos
Message 1 of 4
(4,336 Views)

Hello,

 

If possible could you post a image of your code, this will allow me to advise you best.

 

From the sounds of it you will need the "Build Array" function that can be found on the functions palette under Programming>>Array>>Build Array.

 

Below is an image of me simulating two signals and then building them into an array.

 

Does this look like it will do the job?

 

Kind Regards


Dan

Dan Vickers - Applications Engineer UK and Ireland
0 Kudos
Message 2 of 4
(4,322 Views)

Hi Red,

 

Try something like this. If you're using C# is should be easy to convert this.

This read 4 channels from a DAQ card a copies the data to an Excel sheet.

 

Imports System.Threading.Thread
Imports NationalInstruments.DAQmx
Imports Microsoft.Office.Interop
Imports NationalInstruments.Analysis.Math

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim myTask As Task
        Dim reader As AnalogMultiChannelReader
        Dim j As Integer = 0
        Dim ExcelApp As Excel.Application
        Dim XLSheet As Excel.Worksheet

        Dim XLBook As Excel.Workbook
        ' Initialize local variables
        Dim sampleRate As Double = 1000
        Dim rangeMin As Double = 0
        Dim rangeMax As Double = 10 '5
        Dim samplesPerChan As Int32 = 100


        Try

            myTask = New Task()
            ExcelApp = New Excel.Application

            ' Create a channel
            myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:3", "", CType(-1, AITerminalConfiguration), rangeMin, rangeMax, AIVoltageUnits.Volts)
            'or
            'myTask.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai2,Dev1/ai4,Dev1/ai6", "", 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)

            'if you need to you can isolate the data from each channel
            'for example, get the data from ai0
            Dim dataCh0(samplesPerChan) As Double
            dataCh0 = ArrayOperation.CopyRow(data, 0)

            ExcelApp.UserControl = True
            ExcelApp.Visible = True

            'open existing workbook
            'ExcelApp.Workbooks.Open("C:\dir\excelbook.xls", False, True)

            'or open new workbook
            ExcelApp.Workbooks.Add()

            XLBook = ExcelApp.ActiveWorkbook

            XLSheet = XLBook.Worksheets(1)
            XLSheet.Activate()

            XLSheet.Range("A1").Resize(4, samplesPerChan).Value = data

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        Finally

            XLBook = Nothing
            XLSheet = Nothing

            ExcelApp = Nothing
            myTask = Nothing

        End Try
    End Sub
End Class

 

 

Hope this helps

 

Curt

0 Kudos
Message 3 of 4
(4,314 Views)

Hello Red

 

Ohh, it looks like I have missed the point here, sorry.

 

Please ignore my previous post showing how to do this in LabVIEW, I can see now that this question has been posted on the Measurement Studio section.

 

It looks like Curt has given a very comprehensive reply. Please let us know how you get on.

 

Kind Regards

Dan Vickers - Applications Engineer UK and Ireland
0 Kudos
Message 4 of 4
(4,311 Views)