LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Record data on button pressed, and then save the recorded data to a spreadsheet on another button pressed.

Solved!
Go to solution

Hi,

 

I am a new Labview user. I am developing a program in Labview 7.1 that will record data on a button pressed. On another button pressed, it should stop the recording, and then open a file dialog to let me save the recorded data to a spreadsheet. I have read in this forum that I should run multiple loops in parallel but unfortunately I cannot view the examples because I am using an old version of Labview. I tried to do that to pass the data to an array once recording is started and then I route the data to a write to spreadsheet function inside another case statement. However, once I put the write to spreadsheet to the case statement it fail to write. I tried to put it outside of the case statement but it only record a single set of data. Sorry if I am not being clear with my explaination. It will be greatly appreciated if anyone can give me some advice on this.

 

Thanks in advance for your information.

 

Cheers,

 

Anson

 

 

0 Kudos
Message 1 of 10
(7,437 Views)

It sounds to me like you may want to use a Producer Consumer Architecture with User Events, there is a VI template you can navigate to:  File>>New>>VI From Template>>Frameworks>>Design Patters>>Producer/Consumer Design Patterns (Events)

 

Take a look at this template. 

 

 

 

Ask questions!


Message Edited by jmcbee on 03-20-2009 11:30 AM
Message 2 of 10
(7,434 Views)

It dosnt have to be very complicated, just do something simple.

Begin gathering data in a while loop.

 

Inside this while loop, put a case structure.

This case structure will be controlled by a button, you can call it "collect data" or whatever you want.

 

When this button is pressed, the 'True' case will run.

Put code in the true case to write the data to a spreadsheet file.

 

When the button is pressed again, the 'False' case will run.

Leave this case empty, and nothing will happen, and no data will get written to the file.

Message Edited by Cory K on 03-20-2009 12:36 PM
Cory K
0 Kudos
Message 3 of 10
(7,425 Views)

Hi Cory,

 

Thanks for your quick reply. I have done something based on your suggestion but for some reason it is still not working (it doesn't record after I press the stop button). However, if I remove the most inner case structure and just route the array directly to the "write to spreadsheet" then it only record the data for 1 cycle. I have attach an image of my block diagrams for my program. Can you please try to point out what is wrong with it?

 

Thanks,

 

Anson

0 Kudos
Message 4 of 10
(7,406 Views)
Solution
Accepted by Anson Wong

You are going to want to build an array of the data.
If the boolean is true, you will add a data point to the array.

If it is false, you will not add anything, and the loop will re-iterate.

 

In the example below, the same code is shown twice.

The top half shows the 'True' case and the bottom half shows the 'False' case

 

 

Message Edited by Cory K on 03-21-2009 11:09 PM
Cory K
Message 5 of 10
(7,376 Views)

Hi Cody,

 

Thanks for your reply. I have tried to implement your code. It is a bit different that I first feed in the random data generator to an array initiator before put it into the build array function because for some reason it is complaining that i am feeding a scalar into an array. I guess this might be differences in the old labview version that I am using (i.e., labview 7.1). Also, I am not very sure if the function at the left side (outside of the while loop) in your example is an array initiator or not, but that's what I put for the time being. Basically I try to initialize a 2D array (double type) with no elements in it. I put a time delay of 1 second, which i hope achieves what your example intend to do.

 

However, I still experience the same problem that it only record the last set of data into the file despite that many cycles should have run.

 

I have tried to use a different input signal also, but the same problem occur: only the last set of data is recorded. I have include the picture files of the 2 different cases (2 pictures for each, true/false). Can you please let me know what is causing the error? (i.e., what should be done so that it records all the data from the moment the collect data button is pressed to when the collect button/stop button is pressed.

 

 Thanks a lot!!

 

Cheers,

 

Anson

Download All
0 Kudos
Message 6 of 10
(7,350 Views)

Hi Cory,

 

Sorry i was only able to attach 3 pictures in the last reply. Here's the last picture.

 

Cheers,

 

Anson

0 Kudos
Message 7 of 10
(7,345 Views)
You forgot to turn the tunnels that go into and out of the outer while loop into shift registers.
Message 8 of 10
(7,342 Views)

Hi Cory,

 

Thanks so much for your code. It seem to be working now!

 

Also, thanks Ravens Fan for pointing out my mistake!

 

Cheers,

 

Anson

0 Kudos
Message 9 of 10
(7,328 Views)

You're welcome. I'm glad that answered you're question.

And yes, Ravens Fan was correct, the problem was that you didnt have shift registers on either end of the loop

Cory K
0 Kudos
Message 10 of 10
(7,303 Views)