Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6008:How do you measure 500 results of ai0 and ai1@500 samples per sec.

well there were mistakes the first time!
0 Kudos
Message 11 of 15
(1,968 Views)

 

I got It right!

there are 2 rows and 20 columns

thanks

0 Kudos
Message 12 of 15
(1,939 Views)

Hi...

 

I am new to VB2010. i am now require to get sample code by using NI-6009 to measure voltage(Vrms) and Current (Irms).How about if i want to create multiple input multiple type analog channels in NI-6009 DAQ Card. I mean I would like to have  1 voltage and 1 current channels and i would like to display both of those in 2 separate graphs.For channei Dev2/ai0 to measure voltage and Dev2/ai1 for current using VB10.NI-6009 DAQ have 8 analog input channel.So, how if i want to use all the channel that can display waveform in separate graph in 1 device(NI-6009 DAQ).Below is the example of ContAcqVoltageSamples_IntClk that measure only one channel..The problem is can I modified this program so that i can use 8 channel that display 8 waveform in separate graph.But how?Because before this i tried but fail.anyone can help me.

 

 

 


0 Kudos
Message 13 of 15
(1,236 Views)

 

 

Imports NationalInstruments.DAQmx

 

Public Class MainForm

    Inherits System.Windows.Forms.Form

 

    Private myTask As Task  'Main Task which is Assigned when the Start Button is Clicked

    Private runningTask As Task

#If NETFX2_0 Then

    Private data As AnalogWaveform(Of Double)()

#Else

    Private data As AnalogWaveform()

#End If

    Private analogInReader As AnalogMultiChannelReader

    Private analogCallback As AsyncCallback

    Private dataColumn As DataColumn()

    Friend WithEvents AxCWGraph1 As AxCWUIControlsLib.AxCWGraph

    Friend WithEvents AxCWGraph2 As AxCWUIControlsLib.AxCWGraph

    Friend WithEvents AxCWGraph3 As AxCWUIControlsLib.AxCWGraph

    Private dataTable As DataTable = New DataTable

 

  Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click

        If runningTask Is Nothing Then

            Try

                stopButton.Enabled = True

                startButton.Enabled = False

 

                ' Create a new task

                myTask = New Task()

 

                ' Create a virtual channel

                myTask.AIChannels.CreateVoltageChannel("Dev2/ai0:1", "", _

                    CType(-1, AITerminalConfiguration), -10, _

                  10, AIVoltageUnits.Volts)

 

                myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value), _

                    SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000)

 

                ' Verify the Task

                myTask.Control(TaskAction.Verify)

 

                runningTask = myTask

                analogInReader = New AnalogMultiChannelReader(myTask.Stream)

                analogCallback = New AsyncCallback(AddressOf AnalogInCallback)

 

                ' Prepare the table for Data

                InitializeDataTable(myTask.AIChannels, dataTable)

                acquisitionDataGrid.DataSource = dataTable

 

#If NETFX2_0 Then

                ' For .NET Framework 2.0 or later, use SynchronizeCallbacks to specify that the object

                ' marshals callbacks across threads appropriately.

                analogInReader.SynchronizeCallbacks = True

                analogInReader.BeginReadWaveform(Convert.ToInt32(samplesPerChannelNumeric.Value), analogCallback, myTask)

#Else

                ' For .NET Framework 1.1, set SynchronizingObject to the Windows Form to specify

                ' that the object marshals callbacks across threads appropriately.

                analogInReader.SynchronizingObject = Me

                analogInReader.BeginReadWaveformDouble(Convert.ToInt32(samplesPerChannelNumeric.Value), analogCallback, myTask)

#End If

            Catch exception As DaqException

                MessageBox.Show(exception.Message)

                runningTask = Nothing

                stopButton.Enabled = False

                startButton.Enabled = True

                myTask.Dispose()

            End Try

        End If

    End Sub

0 Kudos
Message 14 of 15
(1,232 Views)

Private Sub stopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopButton.Click

        If Not (runningTask Is Nothing) Then

            runningTask = Nothing

            myTask.Dispose()

            stopButton.Enabled = False

            startButton.Enabled = True

        End If

    End Sub

 

    Private Sub AnalogInCallback(ByVal ar As IAsyncResult)

        Try

            If runningTask Is ar.AsyncState Then

#If NETFX2_0 Then

                data = analogInReader.EndReadWaveform(ar)

 

                'Plot your data here

                dataToDataTable(data, dataTable)

 

                analogInReader.BeginMemoryOptimizedReadWaveform(Convert.ToInt32(samplesPerChannelNumeric.Value), analogCallback, myTask, data)

 

#Else

                data = analogInReader.EndReadWaveformDouble(ar)

 

                'Plot your data here

                dataToDataTable(data, dataTable)

 

                analogInReader.BeginReadWaveformDouble(Convert.ToInt32(samplesPerChannelNumeric.Value), analogCallback, myTask)

#End If

            End If

        Catch ex As DaqException

            MessageBox.Show(ex.Message)

            runningTask = Nothing

            myTask.Dispose()

            stopButton.Enabled = False

            startButton.Enabled = True

        End Try

 

    End Sub

 

#If NETFX2_0 Then

    Private Sub dataToDataTable(ByVal sourceArray As AnalogWaveform(Of Double)(), ByRef dataTable As DataTable)

        ' Iterate over channels

        Dim currentLineIndex As Integer = 0

        For Each waveform As AnalogWaveform(Of Double) In sourceArray

            Dim dataCount As Integer = 0

            If waveform.Samples.Count < 10 Then

                dataCount = waveform.Samples.Count

            Else

                dataCount = 10

            End If

            For sample As Integer = 0 To (dataCount - 1)

                dataTable.Rows(sample)(currentLineIndex) = waveform.Samples(sample).Value

            Next

            currentLineIndex += 1

        Next

    End Sub

#Else

    Private Sub dataToDataTable(ByVal sourceArray As AnalogWaveform(), ByRef dataTable As dataTable)

        ' Iterate over channels

        Dim currentLineIndex As Integer = 0

        For Each waveform As AnalogWaveform In sourceArray

            Dim dataCount As Integer = 0

            If waveform.Samples.Count < 10 Then

                dataCount = waveform.Samples.Count

            Else

                dataCount = 10

            End If

            For sample As Integer = 0 To (dataCount - 1)

                dataTable.Rows(sample)(currentLineIndex) = waveform.Samples(sample).Value

            Next

            currentLineIndex += 1

        Next

    End Sub

#End If

 

    Public Sub InitializeDataTable(ByVal channelCollection As AIChannelCollection, ByRef data As dataTable)

        Dim numOfChannels As Int16 = channelCollection.Count

        data.Rows.Clear()

        data.Columns.Clear()

        dataColumn = New DataColumn(numOfChannels) {}

        Dim numOfRows As Int16 = 10

        Dim currentChannelIndex As Int16 = 0

        Dim currentDataIndex As Int16 = 0

 

        For currentChannelIndex = 0 To (numOfChannels - 1)

            dataColumn(currentChannelIndex) = New DataColumn

            dataColumn(currentChannelIndex).DataType = System.Type.GetType("System.Double")

            dataColumn(currentChannelIndex).ColumnName = channelCollection(currentChannelIndex).PhysicalName

        Next

 

        data.Columns.AddRange(dataColumn)

 

        For currentDataIndex = 0 To (numOfRows - 1)

            Dim rowArr As Object() = New Object(numOfChannels - 1) {}

            data.Rows.Add(rowArr)

        Next

    End Sub

End Class

 

0 Kudos
Message 15 of 15
(1,231 Views)