LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to file Options.

I am trying to write data from 6 channels of a Daq Card by Daq assistant. I want to take data at a rate of 10kHz. What is the best way of writing them to a .txt file?  I think one way can be to run a while loop and use a shift register to store it in an array and then write the whole array to a file. The problem in that is, if somehow the program crashes I will loose the data. I was wondering if there is any better way?

 

In my vi I want to have a acquisition button that will get the data continuously and show it in a waveform chart and a record button that will allow me to record part of the acquisition (between the time I click record and stop). I try this but could not do it.

An other problem with my vi is, when I convert it from array to string, the string looks fine but when write it to a file, it some how loose its column form and look wired.

 

Please help me with these. 

0 Kudos
Message 1 of 9
(2,613 Views)

You got a few things going on here.  Yes, your program will crash because you keep appending data to the array with no limit.  No limit = huge data set = memory leak = your program will crash.

 

Suggestions:  Use the Produced Consumer template.  The producer is your DAQ and the consumer is write to file and graph the data.  Can you use a chart instead of a graph?  It would be easy to limit the data by using a chart. Data would be FIFOed to the hard drive.  Other advantage is that you are not limiting the performance of the DAQ loop.

 

Let me know if this makes sense or if you need me to clarify anything.

 

Matt

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 2 of 9
(2,610 Views)

Thanks for your reply.

I see your point why the system crashes. 

Yes I can use a chart instead of a graph. 

But sorry, I don't understand your suggestion. I am not familiar with this.

Please clarify. An example vi would be very helpful (Please save as V:9 or previous.).

Thanks.

0 Kudos
Message 3 of 9
(2,605 Views)

Here's a KB on the producer/consumer design pattern: http://www.ni.com/white-paper/3023/en

It is a very important design pattern.  I use it in all of my big applications.

 

In simple terms, you have multiple loops.  Your main (producer) loop is the DAQ loop.  The consumer loop will be your write to disk.  You use a queue to send the data from the producer loop to the consumer loop.


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
0 Kudos
Message 4 of 9
(2,581 Views)

Thanks for your reply.

I tried to make it from the examples that you have suggested. It definitely does not crash any more. But as I am not familiar with the producer/ consumer template, so I am having difficulties with the following.

1. How to create a Boolean control (say, Record/Stop), so that it goes to the consumer loop only when I press it.

2. I want to use a system, that you will ask to select the folder once, and it would create text files like, film1.txt, film2.txt and so on as many times as I press (Record/Stop). (did some thing like this in the 1st vi of this topic, can not implement it here.)

3. I also attach the file that it generates. I want 6 columns instead of this strange format! 

0 Kudos
Message 5 of 9
(2,555 Views)

Sorry, forgot the data.

0 Kudos
Message 6 of 9
(2,552 Views)

This should be 98% correct.  Key things is you need to stop on errors and not ignore them.  Second, since data shuld be coming in faster than you can display you need to make sure queue is empty before exiting the program.  Did what I could.  Busy day.

 

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 7 of 9
(2,546 Views)

I tried to play with the system a little more in order to get the functionalities that I want to have (as mentioned in my last post.). It kind of works but shows an error "Release Queue". I am using the "Release Queue" function at the end of the vi. But some how there is a problem. Can any one please help?

 

I will really appreciate if some one can give any other correction or suggestion for the vi. 

Small description again: 

1. Read at a speed 10kHz (6 channels) when click on start acquisition button.

2. Save the data in a text file when click record button.

3. also do a 10 point average of the data to get 1 kHz reading. 

0 Kudos
Message 8 of 9
(2,505 Views)

You don't need the Release Queue from the bottom loop.  You can't release the same queue reference twice.  That's why you're getting the error.

 

Now for your top loop.  Get rid of the Queue Status.  It is worthless.  Plus you are looking at the wrong terminal.  So with it removed, remove the case structure.  Just let the Dequeue be.  It will sit there and wait until data comes in.  This is fine.  In fact, it is desirable.

 

You have a bunch of other code that is not needed.  For instance, your global variable.  The producer loop will complete before the consumer loop.  So there is no need for the consumer loop to set a global variable that the producer loop will never read.

 

Attached is a quickly cleaned up version of your VI.  There's still work to be done with it, but hopefully it will get you a little closer.


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 9 of 9
(2,485 Views)