LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquire output array after data acquistion when using a case structure

I'm trying to output my data acquisition into an array so that I can perform additional data analysis. I'm using a case structure to ensure that all the samples are read from the buffer. Each time the case structure executes the array values are reinitialized and nothing is outputted. The number of samples read works fine but the data acquisition doesn't. Is the case structure the wrong thing to use or do I need to build my array differently? If I shouldn't use the case structure how do I ensure all the data is read from the buffer? This is a problem that developed after the post "for loop data acq."

 

Thanks

0 Kudos
Message 1 of 15
(2,844 Views)
First, you definitely want to use a producer/consumer design pattern. In a nutshell, you will have two while loops running in parallel, one taking data and one analyzing/saving data. Use queues to pass data from the producer loop to the consumer loop. This allows for two processes to run at different speeds, the way it is right now, the DAQ portion waits for everything else to run before running again. Also, if you set the number of samples per channel input on your DAQmx Read to -1, it will read the whole buffer, that way you wont have to continuously check the buffer. In short, your case structure tests to see if the number of samples expected has been acquired, but by setting the input on DAQmx Read to -1, you will always get the number of samples expected, saving you a big chunk of code. Lastly, if possible, avoid using the build array subVI, it slows things down.
If you need clarification please post back here.
Good luck!
0 Kudos
Message 2 of 15
(2,837 Views)

I'm using the case structure because I get a time out error with just using a while loop. Also messing with the timing of the while loop I left data points in the buffer. I'm actually collecting a data point every five seconds for 5 to 20 minutes. So I would have to have something in place to make sure the buffer was empty without getting a time out error or vice versa. This was covered under the post "for loop data acq." I don't know how to implement the two while loops with my issue being one of the stipulations.

Thanks, Eric

 

0 Kudos
Message 3 of 15
(2,813 Views)
Eric, are you trying to control timing with your while loop? That is not the way to go, instead, change the sampling rate, use continuous scan, and read the whole buffer by wiring -1 into the DAQmx read input. You can right click and then click help on these individual subVI's to figure out how to accomplish this. Info about the producer/consumer stucture can be found here
http://zone.ni.com/devzone/cda/tut/p/id/3023

Your time out error may be the result of your while loop running at a rate faster than the DAQ is taking in data. Making the above fixes should solve the problem.

Hope that helps.
0 Kudos
Message 4 of 15
(2,808 Views)
You are trying to collect 15 samples at a rate of 1 per second.  The default timeout if unwired on the DAQ read is 10 seconds.  Thus it will timeout before you get 15 samples.  You would need to increase your timeout to at least 15.
 
You are having a problem with building arrays.  Anytime the loop iterates and you have 0 samples in the buffer, your false case will run.  This will be quite frequent as you only have a 20 ms wait.  So you will only have a datapoint on 1 out of 50 times through the loop.
 
When your read the data, you have a 1-D array of waveforms (each waveform is one channel).  And each waveform will only have 1 point because that is probably all you will get in a given iteration, (since it is at least a second between datapoints).  Once you get it, you append it to your previous array now generating a 2-D array of waveforms.  You may want to append each waveform together.  Or collect the data as a 1-D array of doubles so that when they are combined, you have a 2-D array of doubles.
0 Kudos
Message 5 of 15
(2,796 Views)

The first problem is, I’m collecting a finite number of samples. In the attached vi I set the rate for one sample per second. I’m really collecting one sample every 5 seconds for 5 to 20 minutes. I could change the time out but that is where I ran into trouble with the timing of the while loop and the wait ms. Also I want the graph to update to show the user the data acquisition is working.

 

By using the case statement we were able to solve the number of samples being read and making sure none were left in the buffer, which was happening. Now I’m trying to take the samples read and perform additional analysis on them. The problem is the array I’m trying to build. I can’t figure out how to capture the signals in an array with the way the case and while loop work. As a last resort I could read the data out of my measurement file, but I was thinking there had to be something easier.
0 Kudos
Message 6 of 15
(2,786 Views)
Take a look at this.  I can't guarantee it will work as I don't have DAQ equipment to test it against.
 
1.  I made the DAQmx read return a 2D array of doubles rather than a 1D array of waveforms.
2.  I moved the concatenate array inside the case structure and wired through in the false case.
3.  Increased the wait statement in the loop to 100 msec, as 20 msec is much quicker than necessary for the sake of display updates or reacting to the press of a stop button.
0 Kudos
Message 7 of 15
(2,777 Views)

Try this

I have used the producer/consumer pattern I was talking about. I got rid of the case structure and instead used the DAQ mx functions to take care of timeout issues. I also added an input for the number of samples to collect. Finally, the bottom loop saves everything to a spreadsheet and uses shift registers to compile all the data into one big array, if you need to do some analysis on this big array, you can add to it. I'm not 100% sure if this works, give it a test and see if thats what you need.

0 Kudos
Message 8 of 15
(2,767 Views)

OK Guys,

I couldn't get the two while loops to work as TZJ suggested. I keep getting errors on the queues. I think it has to do with data being written to the queue sometimes and maybe not closing or clearing the queue others. Not really sure since I am unfamiliar with them. As far as the suggestion form Ravens Fan, I got an idea from that solution and turned it around a little. It worked but I still have one problem. The program will collect data from 1 to 4 channels. If it only collected two channels as in the attached vi no problem. I can make the program work if the channels were constant every time. I worked on it all day yesterday and today so far and can't figure out how to create the array if the number of channels changes randomly. The number of channels is chosen by the user and is inputed into this vi. This vi is a simplified version of a sub vi and doesn't have all the inputs and outputs in the real vi. Any suggestions on how to make this work?

Thanks for the help so far,

Eric

0 Kudos
Message 9 of 15
(2,739 Views)
I attached a screen shot of your code with comments.  There are a lot of things you are doing that make no sense to me.  You really didn't take what I had and modify it.  If you did, then you butchered it.
 
Why are you concatenating the 2 channels to each other?  Why are you concatenating them to an empty array on every iteration?
 
Why are you using waveforms when reading the data when acquiring them at 2-D double arrays would make more sense?


Message Edited by Ravens Fan on 08-06-2008 01:50 PM
0 Kudos
Message 10 of 15
(2,736 Views)