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.
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.
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.).
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.
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!
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.
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.
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.