LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get DAQmx Read (Analog 2D DBL NChan NSamp).vi to acquire continuous data?

Solved!
Go to solution

I am trying to get the DAQmx Read (Analog 2D DBL NChan NSamp).vi to acquire continuous data.  The "Help" indicates I should wire the number of samples per channel to -1, but this does not seem to work for my application.  If I wire it to any number greater than 0, data collection works, but is not continuous.  I have attached the code (Sept15_MainPanel_WorkingBaselines_ApplyBaselines and Calibration.vi) and a subVI (Collect_Baselines.vi) if anyone would like to take a look.

 

Here is what I'm trying to do:

 

I am using a NI USB-6009 device to collect analog voltages from 2 load cells (Channel 0 and Channel 1) and 2 displacement transducers (Channel 2 and Channel 3).  The main panel of the VI contains a listbox with 4 options - "Check EMG Channels," "Collect Baselines," "Collect Data," and "End Program."  "Collect Baselines" and "End Program" work and I'm working on writing code for "Collect Data." 

 

For the "Collect Baseline" option, 2500 samples are read from the 4 channels described above and the 2500 samples are averaged.  This is working.

 

For the "Collect Data" option - I would like the data from the 4 channels to be continuously acquired.  Eventually, for the collect data option, data acquisition will stop when Channel 0 detects of force of 200 N - so I will not ever have a finite number of samples read.  The time it takes to reach this force value will be different for each test.

 

So - how do I get continuous samples for my 4 channels?  Is DAQmx Read (Analog 2D DBL NChan NSamp).vi the wrong function to be using and if so, what should I be using?

 

Thanks in advance for any ideas or advice.

 

Esther

0 Kudos
Message 1 of 6
(6,832 Views)

You have set the number of samples per channel to 4800 in the Sample Clock function.  The read function will read that many and then stop.  To read continuous, you need to put the read function inside a loop.  Do not put the start function inside that loop.  You will need to compare the output array to find your stopping condition.  If met, then stop the loop.  After the loop call the DAQmx Stop funciton.  To see an example of how this is done, open up the Example Finder (under Help), search for DAQmx, and open the example called Cont Acq Acel Samples-Int Clk-Analog Start.vi.  This example shows how to start on an analog  trigger input.  Just disregard the trigger section.

 

- tbob

Inventor of the WORM Global
Message 2 of 6
(6,824 Views)

Hi Esther,

 

There is also a great example in the LabVIEW Example Finder (Help»Find Examples).  It is called Cont Acq&Graph Voltage-Int Clk.vi (Browse: Hardware Input and Output»DAQmx»Analog Measurements»Voltage).  This shows how to do a continuous read on a single channel, but you can easily modify it for multiple channels.

 

Best Regards,

Bryan H.
Message 3 of 6
(6,800 Views)

This suggestion worked.  Thanks!

0 Kudos
Message 4 of 6
(6,771 Views)

Hi tbob,

 

Hoping you can give me another push in the right direction with this code now that I have the continuous read working.  Now, I need to get all this continuous read data into an array so I can do a number of things (subtract off a baseline value, apply a calibration equation to show values in Newtons versus volts, graphically display the data, etc).  I am trying to do this using the Build Array function along with shift registers (see attached Sept23_MainPanel_WorkingBaselines_Apply Baselines and Calibration.vi).  I think this is sort of working but I have some issues.  Data is going into any array, evidenced by the array indicator (Before Build Array) but nothing feeds into a second indicator (After Build Array) - I don't know why.  However, my problem here is that I assume memory can fill up depending on how long this is run - so I think I need a buffer to store information.  Do you have any suggestions of examples for me to check out?  Is this the best way to be working with and manipulating my continuously acquired data?

 

These are clearly "newbie" questions - but any advice would help, especially specific examples to follow.

 

Thanks in advance,

Esther

 

0 Kudos
Message 5 of 6
(6,741 Views)
Solution
Accepted by topic author EstherH

First of all, in case 1, you don't need the flat sequence structure.  The error wires and data wires will correctly dictate execution flow.  Next, in state 2, you need to initialize the shift register, unless you want to keep accumulating data each time you run the vi.  The reason you are not seeing any data here is because you have -1 wired to the number of samples per channel input.  You need to wire some number here, even though you are taking continuous samples.  The function needs to know how many sample to gather at one time.  If you put -1 here, the number of samples per channel needs to be set up in the DAQmx Timing (Sample Clock) function.  If you specify a number here, then you put -1 in the read function.  The DAQ will continuously read, but you have to retrieve the data now and then, so you need to specify number of samples.  By having the read inside a loop, it will continue to read until the stop function is encountered.  I guess the Clear function acts as a stop.  But you still need to tell the read vi how many samples to read and return on each loop iteration.

 

The documentation is a bit misleading.  It says a -1 will cause a continuous read.  But the buffers are just so large, it can't read continuously forever without losing data.  So you specify a finite number, put the read in a loop, and it will read that number and return the data (emptying out the internal buffer) on each loop iteration.  Continous means that you only have to call the Start function once.  It will read on each loop iteration until the stop function (or clear) is called. 

 

Here is the difference between setting the DAQmx Timing function for continous or finite read:  Finite Samples requires one start, it reads the finite number of samples, and it is done.  It requires another start to read more data.  Continous read requires just one start.  It still reads a finite number of samples, but when that is done, you have to retrieve the data by calling the read function before it can continue.  After calling the read, you do not have to call start again.  Look at it this way.  Start is what starts the data acquisition, not the read function.  The read function just empties the buffers into your data wire.  The data acquisition continues in continuous mode, but you have to call read again to get the data out of the buffers.  So you are basically specifying the buffer size when setting number of samples per channel.

 

- tbob

Inventor of the WORM Global
Message 6 of 6
(6,732 Views)