Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6009: How to read AI's on the clock?

Hi,

I’ve got a beginner type question concerning data acquisition.

I’m attempting to write a windows application with Measurement Studio, Visual Studio 2005 VB.net) and the NI USB-2009 DAQ.

Eventually, I would like to be reading ai’s and di’s on the clock (say 10 times a second).  The ao’s and do’s will be written as required.

Right now, I would simply like to read a single ai “DEV1/ai0” and display the updating value in a textbox.  Once I get a single value updating properly, the others should fall into place.

In the code I’ve included, I create a task to input the ai0 input value.  When it runs, it calls the “Callback” routine and does update the “txtRegAirPressure.text” textbox.  However, as expected, it only runs once.  I would like the input task to run continuously to bring the ai in at the desired rate, but I also need the user to be able to interact with the application to perform other functions.  I thought that the task is supposed to run as a separate thread acquiring data while allowing other tasks (such as di’s on the clock and the user interface) to continue.

So, my question is… What am I missing?  I’m sure this must be fairly easy, but I’ve tried a number of permutations in the setup and cannot get where I want to be.

Hopefully, someone has the answer and will guide me in the right direction to which I will be very grateful!

Thanks in advance for taking a look!

 

  Private myTask As Task
  Private analogInReader As AnalogMultiChannelReader
  Private analogCallback As AsyncCallback

  Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ' Create a new task
    myTask = New Task

    ' Create a virtual channel
    myTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "", AITerminalConfiguration.Rse, 0.0, 5.0, AIVoltageUnits.Volts)

    myTask.Timing.ConfigureSampleClock("", 10000.0, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000)

    ' Verify the task
    myTask.Control(TaskAction.Verify)

    analogInReader = New AnalogMultiChannelReader(myTask.Stream)

    '' For .NET Framework 2.0, use SynchronizeCallbacks to specify that the object marshalls callbacks across the
    '' threads appropriately.
    analogInReader.SynchronizeCallbacks = True

    analogCallback = New AsyncCallback(AddressOf AnalogInCallback)

    analogInReader.BeginReadMultiSample(1000.0, analogCallback, Nothing)

  End Sub

  Private Sub AnalogInCallback(ByVal ar As IAsyncResult)

    Dim data() As Double = analogInReader.ReadSingleSample

    txtRegAirPressure.Text = data(0)

  End Sub

 

 

0 Kudos
Message 1 of 3
(3,136 Views)
Hey psgeorge,

Check out this example for how to continuously acquire voltage samples based upon a hardware clock:

C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\
Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk

In visual studio I'm afraid you'll need to use semaphores or some other process to have a multi-threaded application.  In text based programming this is not automatically taken care of for you.  Your best bet might be to consult visual studio forums for input pertaining to this matter.

Message Edited by Elijah K on 03-02-2007 10:57 AM

Elijah Kerry
NI Director, Software Community
0 Kudos
Message 2 of 3
(3,121 Views)

Thanks for your response....

 

I figured out how to get the AI's to update continually.  I had to place another "BeginReadMultiSample(......)" call at the end of the Callback routine.  I was thinking of having the process inputs run in their own thread, but I don't think that is necessary for my application.

 

Thanks again!

0 Kudos
Message 3 of 3
(3,115 Views)