LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to record data using a while loop?

Solved!
Go to solution

Hello,

 

I've created a .vi that I am trying to use to record multiple channels of data. I've have set it up that the user should be able to record data until the 'STOP' button is pushed, then the data will be saved into a spreadsheet file. 

 

Question 1: How do I allow the user to store an undefined amount of data? 

            If you run the .vi as is, you will see that you are only able to collect 100 points, and the recording only takes place over a millisecond or so. I would like it to collect +/- 5 minutes worth of data and have a sampling rate of 1kHz.                 Any suggestions?

 

Question 2: How do I change the file extension of the spreadsheet? Let's say I would like the file to save as a .csv?

 

 

Thanks in advance for any pointers or suggestions!

0 Kudos
Message 1 of 10
(8,843 Views)
Solution
Accepted by topic author kashi13

I haven't looked at your code, but based purely on your description I would set up a Producer/Consumer to save your data.  You should aquire your data in one loop (the producer) and send it to your logging loop (the consumer) using a queue.  Yes, you should save the data while it is being acquired.  This way you don't have to worry about storing who knows how much data in RAM.  It just goes to the disk whenever it can.

 

You can save the file with whatever extension you want.  If you want it to be a CSV, then make the extension a .csv.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(8,838 Views)

I cannot open your VI because I am running LabVIEW 2011. But it seems that you are trying to do something similar to what was discussed in this thread.

 

Jeff

Jeffrey Zola
0 Kudos
Message 3 of 10
(8,810 Views)
Hi I took a look at your VI and the reason you are only able to collect 100 points is because that is all your loop is collecting. Every time your loop runs you are throwing away the last loops data. To fix this, change your code to include a shift register. This shift register will store your last loops value and then you can append the new data to it and repeat. This will allow you to keep sampling. Be aware that this could use up a lot of memory if you let this run over and over too many times. You could even crash your application if you collect too much data. To fix this, you could do what others have suggested and have two loops. One loop would capture the data and send it to the other loop. This other loop would write this data to a file and keep appending the file every time.
0 Kudos
Message 4 of 10
(8,804 Views)

I did some research on the producer/consumer loop method and had some sucees! I'll attatch my vi for others to use a point of reference! Thanks again for all the suggestions. 

0 Kudos
Message 5 of 10
(8,754 Views)

Hi Kashi,

 

I'm new to LV and also trying to record data using a while loop and your vi sounds like it would be very helpful. I'm running LV 2011 and when I tried to look at your vi I got an error that I can't open version 12 files. Any chance you could take a screenshot of your block diagram so I could take a look?

 

Thanks!

0 Kudos
Message 6 of 10
(8,645 Views)

You may find this example useful: https://decibel.ni.com/content/docs/DOC-2431

 

Mike

 

0 Kudos
Message 7 of 10
(8,617 Views)

Hi Kashi,

 

I went through your code and as others have told if you can put a producer consumer (2 while loops in parallel with some synchronization) should be ok with your requirement.

But what i see is as per the coding standard, flexibility and integrability, i find this kind of 2 while loops in parallel after the start acquisition.vi is a concern.

 

What idealy would be good is a statemachine (Queue based or Enum / string based) which should keep handling other events and it should loop you to Read acquisition case frequently (based on other events). This Read data should be written to a function global or LV2global (Uninitialized shift register with while loop running only once).

The consumer while loop will keep looking for the function global data. If empty it does nothing. If data is there in function global, the consumer while loop will write the data to a csv file (I would use write to text file vi with file position set ability) and then empty the function global.

Using global variable here will cause race condition easliy.

 

Hope you are able to get what i say.

Regards,
Muthuraman
0 Kudos
Message 8 of 10
(8,592 Views)

i can't undestand with your suggestion, maybe you have samo exampel for record data such as i want

0 Kudos
Message 9 of 10
(8,108 Views)

So you are replying to an old thread that already has a marked solution.

 

And you have a problem understanding the solution?

You do not give any details about what you have tried and what you have problem with. What is it, that you don't understand?

 

You have of course gone through all the training material and free online tutorials that NI offer.

 

The best thing you can do, is to make a new thread with your own question explaining in details your problem, with a minimum of 10 lines. Also include your code that you are working with.

0 Kudos
Message 10 of 10
(8,080 Views)