Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6009 Visual Basic 6 do Event

Hi,

 

I am using Visual Basic 6 to control a pump (thourgh a CAN bus connected to Copley Controls stepnet controller) and collect voltages from USB at the same time.

 

If I use:

 

DAQmxReadAnalogF64 (with finite samples, say 1000 sample at 1000 Hz)

pumpMove (to move the pump)

 

then,

DAQmx will acquire the samples.  Wait until sampling is done, then, execute thepumpMove command.

 

Is there a way to start acquiring the sample, while start moving the pump at the same time?

 

If I do:

 

pumpMove

DAQmxReadAnalogF64 

 

Then, I will lose some sample points because DAQms starts "after" the pump moves.

 

Any suggestion?

 

Pei-Ying

0 Kudos
Message 1 of 5
(3,851 Views)

Hi Pei-Ying,

 

When are you calling the DAQmxStartTask command?  The basic program flow should be similar to this:

 

DAQmxCreateAI... (Configure channels and measure settings)

DAQmxCfgSampClkTiming (Configure sample rate and type, in your case finite)

DAQmxStartTask (The DAQ card starts collecting samples)

pumpMove 

DAQmxReadAnalogF64 (Collect the samples from the buffer)

 

This should start acquiring samples, move the pump while it is still sampling (assuming your sampling time is long enough), then collect the samples from the buffer in the end.

 

Regards,

Barron
Applications Engineering
National Instruments
0 Kudos
Message 2 of 5
(3,833 Views)

Hi, Barron,

 

Thanks for the answer.  

 

I used the following code:

 

    'Create the DAQmx task.
    DAQmxErrChk DAQmxCreateTask("", taskHandle)
    taskIsRunning = True
 
    'Add an analog input channel to the task.
    DAQmxErrChk DAQmxCreateAIVoltageChan(taskHandle, physicalChannelTextBox.Text, "", _
                    DAQmx_Val_InputTermCfg_RSE, minValueTextBox.Text, maxValueTextBox.Text, _
                    DAQmx_Val_VoltageUnits1_Volts, "")
                   
    'Configure task for finite sample acquisition and read in data
    DAQmxErrChk DAQmxCfgSampClkTiming(taskHandle, "OnboardClock", frequencyTextBox.Text, DAQmx_Val_Rising, _
                    DAQmx_Val_AcquisitionType_FiniteSamps, CLng(samplesPerChannelTextBox.Text))
    DAQmxErrChk DAQmxGetTaskNumChans(taskHandle, numChannels)
    arraySizeInSamps = numSampsPerChannel * numChannels
    ReDim data(arraySizeInSamps)
   
    WaitMs (200)
     
    '*************************************
    ' for Copley Controls - move pump
    myMove = MOVE_DISTANCE
        ampObj.MoveRel (myMove)
    '*************************************
       
    'acquiringLabel.Visible = True
    'acquiringLabel.Caption = "Acquiring..."
    DAQmxErrChk DAQmxReadAnalogF64(taskHandle, numSampsPerChannel, 10#, _
                    fillMode, data(0), arraySizeInSamps, sampsPerChanRead, ByVal 0&)
   
I was able to acquire the trace, but, lost several data points in the begining.  It looks like the WaitMS (200) (ie, wait 200 ms) did not work.

For example, I set Rate to 1000 Hz and collect 1000 points.  I still got 1000 points, but, when pump moves, pressure goes up.  The traces I got has pressure already going up.  

 

I would like to :

 

1. start sampling at 1000 Hz for 1 second

2. wait 200 milli-seconds (while USB-6009 still collecting samples)

3. start pump move (while USB-6009 still collecting samples)

 

Is there a way to achive above?  Is there any good command (piece of code) for waiting while sampling, but do not allow pump to move until reaches specified time interval?

 

Pei-Ying

 

 

 

0 Kudos
Message 3 of 5
(3,817 Views)

Hi, Barron,

 

In the VB6 example installed with DAQmx, it did not use DAQmxStartTask.  Now, my code worked as I wanted after I added it.  Thanks!

 

Pei-Ying

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

Hi Pei-Ying,

 

I'm glad to hear you got it working!  The DAQmxStartTask function will tell the DAQ hardware to begin sampling, but does not hold software execution while the samples are taken so you can continue doing other things in your program.

 

Regards,

Barron
Applications Engineering
National Instruments
0 Kudos
Message 5 of 5
(3,805 Views)