LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Start and Read

Hello

 

I am having a frustrating problem with my code that involves the use of DAQmx_Start and DAQmx_Read vi's. My problem seems to involve the way I input the "timout" and "number of samples" for DAQmx_Read.

 

In my code I have a while loop and a True/False Case structure that actives when I press "Scan". The while loops is always activated until I stop it. There is a Stacked Squence within this Case Structure. One of the first sequences has the DAQmx_Start vi which should begin the data acquisition of my scans (I am recording 4 analogue voltage values from 4 physical channels). The rest of the sequences carry out the scanning procedure that involves motorized stages and other changes but nothing with DAQmx vi's. Outside of this Stacked Sequence but still within the True/Falce Case structure is the DAQmx_Read vi.

 

Here is my problem because even though the motorized stages are moving and the other commands are being executed once the True/False Case Structure is activated, the DAQmx vi's don't seem to record the voltage values.

 

DAQmx_Read is set up as Analog 1D Wfm NChan NSamp. Sometimes by playing with the timeout and number of samples per ch for this vi, I actually do get some data recorded. However, I have not found a consistent techquine for always recording data because the number of samples per ch that I need are constantly changing per scan. 

 

Please see attached a picture of DAQmx_Read vi and also my code itself.

 

From what I understand I either am almost always calculating the timout/number of samples per ch improperly or the DAQmx_Read vi should be placed elsewhere... perhaps outside the True/False Case Structure? I have not tried this. Someone please advise. Also, how should the "number of samples per ch" for DAQmx_Timing vi that I use at the very beginning of the DAQmx set up differ from DAQmx Read vi?

 

I understand that my code is very involved and might benefit from Event Structures but, believe me, I have tried and failed. 

 

Thank you!

Alfredo

Message Edited by AlfredoT on 02-20-2010 06:33 PM
Alfredo
Download All
0 Kudos
Message 1 of 5
(2,876 Views)

Hi,

 

A few things that I have noticed.

 

1. The task that you are referring to is a analog in "continuous" task.  You only need to start the task once and the buffer will continue to collect data.  From your code, you have the start task in a loop, and that may give you problem.  The task only need to be started once.

 

2. When you setup the task, becareful about your frequency of acquisition and number of samples in buffer (for continuous mode).  For example, let say that the frequency is 1000 Hz and you select 1000 samples per channel.  That means your buffer will only be able to contain data for 1s before it overflow.  Try increasing the samples per channel to about twice your frequency.  You want to give yourself some extra room.

 

3. It seems like you only need to read a chunk of data when a condition is met.  If that's the case, use the read finite samples option instead.  You can leave the start task in the loop if you use this option instead. 

 

 

If you have a continuous test, and you are not reading your buffer regularly, your buffer will overflow, unless you enable a daq property that will allow you to overwrite previous value in the buffer. 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 2 of 5
(2,841 Views)

HI Alfredo,

I agree with jyang on mast parts. I would change the sampling mode from continuous to finite if you only want to read when you get to that portion of your code otherwise the hardware will begin sampling when you call the start task and the buffer will overflow. I would also remove the start task from your code, the DAQmx read will implicitly start your task and return the number of samples you requested and then stop the task. The next time the read is called it will restart, read and close again. This way you avoid timing issues since you’re only interested in a certain number of samples per call.

Matt
Applications Engineer
National Instruments
0 Kudos
Message 3 of 5
(2,825 Views)

Thank you very much for your reply.

 

I have gotten rid of DAQmx Start and kept everything else and that seems to have done wonders. I am now able to record my data as expected! Thank you!

 

Question: What if I would like to pause my data acquistion instead of having it continuously acquiring? Should I not be able to use the Stop/Start DAQmx vi's? So far I have been unsuccessful at making them work. It seems that having the DAQmx Read vi in the same Case Structure with DAQmx Start is not a good idea. Is this true?

Alfredo
0 Kudos
Message 4 of 5
(2,792 Views)

Hi Alfredo,

You shouldn’t be continuously acquiring. It should start and then take the number of samples required and then stop. It is possible to pause your data acquisition using a digital line (internal or external), but I don’t believe that was what you meant. If you explicitly start the task you can then stop the task latter before starting it again if needed. This allows you greater control of your task but requires you to be more diligent in your placement and timing. Starting and stopping the task is not the same thing as pausing however.

Matt
Applications Engineer
National Instruments
0 Kudos
Message 5 of 5
(2,764 Views)