LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help/Feedback - How to continuously monitor data and record it every few seconds (can't stop loop during readings)

Solved!
Go to solution

Hello everyone!

 

I want to preface this that I'm looking for some feedback and help with a problem seeing as I consider myself an amateur coder, especially in Labview, so anything you can shoot my way is great.

 

I'm building a program that works in tandem with a data collection system and the program is composed of vi's that enable the user to analyze and continuously display, read data and save it and display data for X amount of time and every Y seconds add the data to an array and save it to a spreadsheet along with a timestamp.

The user can open up these "menus", from a "main menu" and close them. (They work fine and the while loops are able to be stopped in order to navigate the menus).

 

I'm running into trouble with the last one that requires some user interaction and running tasks in parallel. Basically the user can open up the program, inputs the total process time and the delay between readings and can then click to start the collection data but I'm having trouble getting the process to stop, once the monitoring loop starts it has to wait the time out in order to stop and I can't seem to find a way to get it to stop.

I've tried quite a few ways that I found in the forums and online but none seemed to work, the cancel button is still frozen while the data gathering is running. 

 

Attached I have the VI with a simulated wave, and the data saved pop up is just in place to check if the data saving is working.

 

Right now all I can think is that the time express VI's are causing the problem but to me that makes no sense so I could use some feedback and in the meantime I'll keep trying it. On a side note I managed to get my continuous one to stop because it also has a delay between displays so I created an event case and used that delay amount as the timeout and the other case would be the go back button.

 

Thanks for your input!

0 Kudos
Message 1 of 8
(2,731 Views)

Don't put long running loops inside of event cases.

 

It is possible that you won't even be able to stop your program.

 

Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2016 Help

Message 2 of 8
(2,691 Views)
Solution
Accepted by topic author lululilv

Here's a simple Producer/Consumer design.  The Producer generates 200 random numbers every 200 msec (or 5 times/sec).  As fast as the data come in, they are "exported" out of the Producer Loop into a neighboring Consumer Loop for further process (which might take additional time, such as doing an FFT, opening and writing files, etc.), leaving the Producer to chug along unimpeded.

Simple Producer-Consumer.png

I've chosen to use Asychronous Channel Wires (introduced in LabVIEW 2016) as I find it an easier "metaphor" than a Queue for shuttling data between parallel loops.  The rectangle originating the "orange pipe" is a Stream Channel Writer, which accepts data (in this case, an array of Dbls, hence the orange color of the Channel Wire).  The Stream Writer has an additional Input, "last element?", that has the Stop button wired to it, allowing it to tell the Consumer, containing its Stream Reader, that no more data are coming, and allowing the Consumer to stop.

 

For Extra Credit, why did I put a Frame Sequence (which I almost never use) around the Stop Button?  If you aren't certain, try wiring 2000 into the For loop, slowing the loop way down to every 2 seconds, run (and stop) the loop several times, then remove the frame and do it again.  To understand what (any why it) is happening, think about the Principle of Data Flow.

 

Bob Schor

Message 3 of 8
(2,632 Views)

Hello everyone, 

 

I'm currently working on a sub VI that continuously reads and plots a signal from a USB device, for a certain period of time and every few minutes the VI will save the data values and append them so the user can save them.

 

I'm quite new in Labview (<1 year) and so I've run into quite a few problems. The one I have right now is that in the version with the data acquisition VIs for the USB device the program will crash as soon as you hit start because it's out of memory.

I assumed this is because of the way Labview handles variables and my "generous" use of them crashes, so I started trying to switch them out for shift registers whenever possible.

 

The pause function (section in pics attached) worked well when I used local variables (when the user hit pause, the elapsed timer would sit still and when readings were resumed the timer would resume regularly and would only read when it was the correct time). Using a shift register, as soon as I hit pause the accumulated pause time just shoots up to insane amounts so when reading is resumed the elapsed time goes to negative values.

 

Can someone explain what's going on and how this could be fixed? Also, is the reason the actual VI is crashing due to the fact that I read/write to local variables so often?

 

Best regards!

Lu 

0 Kudos
Message 4 of 8
(2,611 Views)

Hey!

 

Sorry for the late reply, I posted again and wasn't getting updates for these, thanks for your response!

 

I "managed" to fix it by discarding the event case altogether, I opted to use a series of T/F cases that checks which button is pressed, for example while the monitoring loop is running, there are 2 checks that also run, one for pause check and the other for cancel check. The pause starts a timer to figure out how long the process has been paused and checks to see if the pause button has been pressed using a local variable, if it's pressed again (switch not latch) it resumes the main loop and updates the total pause time variable.

If the cancel button gets pressed (latch) it just cancels the loop and appends data to the header (if there is data).

 

0 Kudos
Message 5 of 8
(2,603 Views)

While I was waiting for feedback I did find something about Producer/Consumer designs but I don't think I fully grasped how they worked. I discarded the Event case altogether and used a series of T/F checks as you can see in the attached VI, my initial problem seems to be solved but due to what I assume is my overuse of Local Variables, the VI crashes if I place in the data acquisition.

 

I'm gonna try the design you posted and will try to study it to see what I can do with it but I'm gonna try to answer your EC. I think that the FS is there so the user can actually stop that loop with a whole data set finished (not sure if that's the correct use of words). The For loop would runs at the same time as the FS but without it, if the user clicked stop it could stop without the 200 random numbers. I'll go check it out and see if I got it right.

 

Thanks a lot for your help and feedback!

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

Hey Bob! I tried what you sent over and this is great!! Super helpful stuff and very easy to understand, I'm gonna restart my VI from scratch and I'll try to implement these system.

 

I think I got the question right but just want to check one thing, I know it might sound basic but: the miliseconds timer value is wired to the FS so for example, if I press the stop and there is still 1 second remaining out of the 2 total, it waits, sends/plots data and only then does it allow an exit right?

 

 

Thanks once again!

0 Kudos
Message 7 of 8
(2,558 Views)

@lululilv wrote:

I think I got the question right but just want to check one thing, I know it might sound basic but: the miliseconds timer value is wired to the FS so for example, if I press the stop and there is still 1 second remaining out of the 2 total, it waits, sends/plots data and only then does it allow an exit right?

Glad you like the Channel Wire demo.  I'm not sure you got the Frame-sequence question.  Let me phrase it another way --

 

Make a While loop that has a 10-second Wait (wire 10000 to it) inside.   Start it, push Stop at any time, and guess how long it will take to finish.  I'll trust you in this, but here's a bet -- you pay me 10 cents if it takes more than 9.9 seconds to finish, and I'll pay you $1 if it finishes before 9.9 seconds.  Run this 10 times, then donate the dollar you'll probably owe me to a Charity of your choice.  Why did this happen?

 

Bob Schor

0 Kudos
Message 8 of 8
(2,537 Views)