03-23-2010 10:50 AM
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
03-24-2010 10:38 AM
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,
03-25-2010 12:28 PM
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
03-26-2010 06:53 AM
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
03-26-2010 10:21 AM
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,