From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW 2010 - Display data in real-time, but only save the data once a button is pressed?

Hello everyone,

 

My name is Joe and I'm having a bit of a problem with a VI I am building for my summer research position at Cleveland State University. I have a VI that collects volatge readings coming from a quadrant photodiode through my [NI cRIO 9201]-[NI USB 9162] system. There are three channels of data coming in through the DAQ Assistant (Dev1/ai2, Dev1/ai6, Dev1/ai7) into the VI. The VI starts when a button event occurs and then seperates the data, normalizes the readouts by dividing ai2 & ai6 by ai7, finally graphing the two new signals. 

 

Currently I have a Write To Measurement File block writing each data cycle to a .tdms file. However, it starts saving as soon as I start up the While Loop for the continous data collecting. What I'd like to have it do is have a user press a "Start Saving" button on the front pannel which begins saving data collected at the button click.

 

This sounds simple (and it probably is), but I am having one hell of a time getting it to work. I've tried nestling another event structure to look for the button press and even polling the button in a loop every 500ms (which I'd rather not due as it drains free CPU %). However, when the VI is ran and the start button is pressed, the VI doesn't allow me to press onto the buttons (which I find very strange). I've heard of Producer/Consumer structures, but I honestly don't understand how to utalize them fully for multiple signals.

 

If anyone has any ideas, please let me know. I'd like to get this whole thing squared away by my presentation next Tuesday.

 

Warm Regards,

Joseph Glaser

0 Kudos
Message 1 of 35
(11,139 Views)

Joe,

 

Have you tried something along the lines of the code snippet below?

 

log on press.png

 

As far as why your VI will not let you press buttons once the start button is pressed, it probably has to do with the way you have set up your event structure.  It would be helpful for you to post your VI, if the solution above does not work.

 

Good Luck!

Drew T.
Camber Ridge, LLC.
Message 2 of 35
(11,110 Views)

Hello Drew,

 

Thank you for your quick responce. This is basically the set up I had to start with. I have recreated the VI with a fresh start and included your code. The problem is that I am getting a delay between hitting the boolean switch to record and the actual recorded data. Also, hitting the stop button also creates a delay and doesn't end the loop right away. Is there a way I can have LabVIEW respond faster to Boolean status changes?

 

Warm Regards,

Joseph Glaser

0 Kudos
Message 3 of 35
(11,107 Views)

Pressing the stop button does not cause a delay.  The delay becomes apparent because you are now waiting on the program to respond to your action.  The delay is probably caused by the response of your measuring devices.  Your stop switch is "latch when released" which is what you want.  It stays depressed until LV reads it;  otherwise, LV could miss the toggle action of the switch.  Unfortunately, because of the response time from your rio system, you may see a delay.  Enable "highlight execution" and watch the data flow through your block diagram.  It should be apparent where your delay is occuring.  I have the same issue with my cDAQ system (slow response time when measuring).  I don't know if there is a way to speed this up or not.  There isn't with the cDAQ.  It is what it is.  Different instrumentation may give you a better response time, but given what you are using, the delay time may be neglible.  You will have to decide that.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 35
(11,099 Views)

Joe,

 

I want to point out that the delay you are experiencing is most likely due to the way you have your measurements set up.  By acquiring 100k samples at 100kHz, you are tying up the DAQ Assistant for 1 second each loop.  It would be better to, for instance, acquire 1k or 10k samples at 100kHz, which would allow your loop to run 100 or 10 times a second, thereby reducing the delay.  This would also prevent the delay between hitting the switch and recording, because the button is only polled once a loop, once all the data from the DAQ Assistant has been acquired for that loop/second.  I hope that was clear and informative, but let me know if you need more assistance.

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 5 of 35
(11,060 Views)

Thanks Drew. That worked wonderfully for speeding up the VI. I rewrote the thing again and trimmed down the extra fat as well. I am reading 5K samples at 100kHz and everything is responding wonderfully.

 

Now the question I have now is with the "Write to Measurement File" VI. Currently the processes loops every 0.05 seconds and therefore appending a new sheet of data to the TDMS file's export in Excel at that rate. Is there a way I can have the data collected and then appended to the same sheet so each sheet covers a fixed amount of time?

 

Another method that I think could work (but amhaving a hard time writing in LabView) is to have the program store the Data on the ram and then export it after the start button is clicked again.

 

I have attached the current version of the VI as a picture below: 

 

Warm Regards,
Joseph Glaser 

0 Kudos
Message 6 of 35
(11,042 Views)

Hello Joseph,

 

I am not sure how your data is writing to the measurement file, but if I understand you correctly in what you are wanting to do, you could store the measurements in a 2D array and then write to the mfile upon exiting or trigger it as you mentioned.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 7 of 35
(11,033 Views)

Hi MoResse,

 

This is Joe. Just to restate it, the TDMS file currently exports each loop as a separate Excel Sheet upon importing it into Excel. This is quite taxing on file size and makes the data to work with. What I need it to do is have the data imported into a single Excel Sheet when the append option is ticked in the "Measurements File" VI.

 

Now if we can store the data that each loop produces into a 2D array, appending to the end of it after every loop and then sending that to the Measurement VI, it may work. However, I am unsure of how to do this with the block diagram in Labview 2010. Anyone have a reference I may be able to look at? This is the last thing I need before I can start collecting data with my optical tweezers.

 

Warm Regards,

Joseph Glaser

0 Kudos
Message 8 of 35
(11,027 Views)

It can be something like this.  The Insert into Array function will insert at row 0, shifting the other rows down.  You will have to load a 1D array first with a set of data (one measurement), then you can load into the 2D array.  After all your measurements have been taken, you can then load to the file.  There are some examples in the Example Finder on working with arrays.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 9 of 35
(11,025 Views)

To set up the Measurement File vi along the lines you suggested, give this a try. Double click on the Write Measurement File Express vi and under Action, select Save to one file and Append to file.  That should reduce the size of your data file. You may want to create a new file for each run to keep things separated. To do that select Ask User to choose and Ask only once. Alternately you change the file name manually for each run.

 

JohnCS

0 Kudos
Message 10 of 35
(11,007 Views)