LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

real time storage of data programmatically

Solved!
Go to solution

Hi,

 

I have been trying to solve this problem for a while now and there seem to be no similar examples out there. I'm trying to store data programmatically, firslty by pressing a switch when I want to start taking data and pressing the same switch when I want to stop and save the file . I have created an example VI which demostrates what i want to do; the Generate sine wave function inside a infitnite while loop represents the real time data acquisition, the other while loop would opens the file and saves the data until the Save Data Switch is pressed again. The file is closed after the loop finishes executing. 

 

I have not gotten this to work and so I was hoping to if somebody could point to me where I've gone wrong.

 

Thanks

0 Kudos
Message 1 of 6
(2,671 Views)

Your VI has several problems, amny of which suggest that you do not usderstand dataflow.

 

The generation loop is an infinite loop, as you are aware. The save loop will not run until after the generation loop stops.  This is basic dataflow: A node or structure will run when all of its inputs have data and its outputs will have data only after it completes execution. Thus, the array output of the generation loop does not have any data until it stop running - which is never. The save loop does not start until data is available at its input - which is never. Like Peter Pan, your VI seems to live in Never-Never Land.

 

The fix is parallel loops and a queue.  Look for a Design Pattern called Producer/Consumer (data). I think LV 2009 had this.  It is probably under File >> New.. >> From Template >> Frameworks >> Design Patterns.

 

Lynn

0 Kudos
Message 2 of 6
(2,659 Views)

Thank you for pointing out my mistakes, I have read quite a bit about data flow programming and Producer & Consumer queues. I have had trouble in passing the waveform data to the Enqueue VI. The data that its specified for the Obtain Queue is the same as in this example (https://decibel.ni.com/content/docs/DOC-2431). But since my generated signal is not encapsulated into an array and its a standalone Waveform(DBL) type, the Enqueue Element won't accept my data. On the other hand if I convert the specified data to Waveform DBL, the file created contains no data whatsoever. 

 

See the attached VI

 

Thanks again

0 Kudos
Message 3 of 6
(2,620 Views)
Solution
Accepted by topic author jquinno

Hint: While programming, always keep the Context Help window open. When you have a problem like the broken wire in the Producer Loop, hover over the wire with the wiring tool, and the context help window will display a description of the error. In your case it says: "Broken Wire ... You have connected two terminals of different types. The type of the source is Waveform(DBL). The type of the sink is 1D array of Waveform(DBL)."

 

The solution is to make both datatypes the same.  If you will be using multiple channels for your real data, than an array of waveforms (one waveform per channel) may be appropriate. If you are just using one channel as in your test VI, just use the Waveform datatype. The image below shows both methods.

 

Array or not to array.png

 

Also you do not need the Wait(ms) in the Consumer loop.  The Dequeue function will wait until it has data and then execute.

 

Lynn

Message 4 of 6
(2,604 Views)

Another thing is that you have to be careful of overwriting data from the previous loop in your save file.  In order to append data, first set the file position to the end of the file, then write the data.

Message 5 of 6
(2,600 Views)

** sorry, double post ***

0 Kudos
Message 6 of 6
(2,597 Views)