LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Button for saving data using Write to Measurement File

I am new to LabVIEW and I am having some trouble creating a button that would save data from a DAQ device. The goal was to have the button record data that was being graphed on the Front Panel that my team would be able to turn on and off whenever we wanted. However since we need to run the main program and record data for several hours, the Write to Measurement File records too much irrelevant information and we would like it to record a sample of the data every couple seconds or so. In other words we want to see all the data in real time but when we look at it later we would just want to know the "gist of it" (not an average).

So far I have tried to connect a Boolean button to a Write to Measurement File VI in addition to using an Elapsed Time or Time Delay VI with limited success. With an Elapsed Time/Time Delay VI, we would usually encounter endless "Save As" windows while without using the Time VIs we either do not record any data, get only 100 data points (regardless of how long the button has been on), or we would get all the memory-clogging data, all depending on where we connected the Boolean button. Here are two different attempts:Recordsignal_type02.jpgRecordsignal_type01.pngThe Simulate Signal VI is standing in for the DAQ VI but the problems remain the same. Any ideas on what to do? I have already tried searching on various forums to solve this apparently common problem but there does not seem to be much help since these problems persist or solutions are too vague/out-of-date to be helpful.

Download All
Message 1 of 7
(5,708 Views)

As a first step, go back to the tutorial and learn about dataflow. Since you don't even have a toplevel while loop, it seems that you are using "continuous run" mode. That is a debugging tool and not a way to run a VI. Create a proper state machine!

 

(code 1): it does not make a lot of sense to use the case structure and the "enable" input.

 

(code 2): Your "simulate signal" probably belongs inside the loop. Currently you are simulating once and writing the same thing over and over to the file. Also, once the boolean is true, you enter the inner loop and the boolean will never be read again and since the loop is set to "continue if true" it will run forever. Your shift register makes no sense, since you never even look at the previous data. Why is it there? Your loop has no timing information and will run as fast as the computer allows. At what rate do you want to acquire data and write to the file?

Message 2 of 7
(5,678 Views)

Thank you for your input altenbach. As I said before I am still learning to use this program properly so I do not expect my formatting to be 100% correct. In addition both codes are different versions of achieving the same outcome in case there was any confusion.

 

For the first version I connected the Boolean to the enable input in order to make the Write to Measurement File VI only run if the button was pressed since that is what made sense to me.

 

For the second version I was trying to make the Write to Measurement File VI only add information if the iteration number was a multiple of 20000. This was just another method to limit the influx of all the data without using any Timing VI since I was having too much trouble with them. The shift register was to increase the N number of iterations indefinitely such that the program can run for any number of hours. Thank you for the clarification on the Simulate Signal VI, I was under the impression from LabVIEW tutorials that the signal continued running until the program was stopped (and either way the Simulate Signal was to stand in for a DAQ Assistant).

 

I do not mean to ask for hand-holding but I am still very confused on how to approach configuring the VIs in order to get the program to save data with the use of a button. Thank you again for the help.

Message 3 of 7
(5,639 Views)

All you need is an outer while loop that continuously simulates data and condtionally writes to a file. You either need to configure the simulation to "simulate acquisition timing" or place a small wait inside the loop. There is never a reason to run something as a random function of the current computer power. Place a case structure around the "save" code to conditionally save the current data. If the save operation takes long compared to the rest of the loop code, use a queue and save in a parallel loop. It is always better to stay away from express VI, because it does significantly more work. Typically you would open the file before the loop, keep it open while appending, and close it only once the while loop stops.

 

 

 

 

Message 4 of 7
(5,627 Views)

@ajmarcial wrote:

The shift register was to increase the N number of iterations indefinitely such that the program can run for any number of hours.


You never use the output of the shift register, so it makes no difference. It is also I32, (same as the iteration terminal), so you will run out of numbers (~2^31) at the same time and I don't understand the argument with the "hours" and such. If you delete the "+1" and the shift register, nothing would change. The compiler will remove the associated code parts behind the scenes anyway during "dead code elimination".

0 Kudos
Message 5 of 7
(5,626 Views)

Ok, since I was not getting anywhere with my original code I started looking around and found the Master-Slave design rather promising in concept. However, I could not find any decent tutorial or introduction to actually create such a system or anything to explain what each instrument in the Notifier's Palette does and how it affects the code so I was stuck using trial-and-error (I know that's bad but I'm still very much a beginner and desperate times call for desperate measures). Please correct my code since I really have no idea of what I am doing. Also if someone could point me to a proper worked-out example of the use of Notifier or Queue VI's that would greatly help my understanding. Thank you very much for any help.

0 Kudos
Message 6 of 7
(5,591 Views)

I think the problem is you don't understand dataflow in LabVIEW. Fortunately it is pretty easy to explain! Nodes (including structures, like loops) do not start until they have all of their inputs and do not produce any outputs until they are completely finished. Tunnels (the square things on the borders of your loops) count as inputs/outputs, and when you put data into a tunnel it won't "update" the tunnel later with new data - it just gets what it gets when the data flows in.

 

In the code you posted, your loops will not run in parallel (is that what you meant them to do?) because you have an input tunnel in your slave loop that comes from an output tunnel in your master loop, so the slave will wait for the master to finish. In addition, your master loop will continually send notifications of the exact same data, whatever the Simulate Signal first produced. Simulate Signal won't produce more data until both master and slave loops finish and the top level loop iterates again.

 

I hope this help. Try it again with this in mind, and if you get confused, try using the highlight execution tool to see how your code is running, and post again if you have more questions about this.

0 Kudos
Message 7 of 7
(5,575 Views)