LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FOR loop pause based on events (UI and non-UI)

Solved!
Go to solution

Hello,

 

I have made a FOR loop where I needed to be paused in each iteration, and waiting for an event to happen then continue with the next iteration.

 

Here is the snippet:

 

FOR-pause.png

 

It only executes when START button is pressed and STOP whenever the correspond button is pressed.

 

I need to have the same behaviour but in a event structure inside a while loop, (same structure for event driven machine states):

 

How can it be implemented?

 

I was thinking in using value (signalling) properties to trigger the events of the buttons.....but so far I am stuck....

 

some ideas?

 

 

FOR-pause_Event(fail).png

 

0 Kudos
Message 1 of 16
(4,060 Views)

The While loop version is literally the same as the For loop version you already have just with a different type of loop... You should never have even done a 1000 iteration For loop, it should have been a While loop from the start. The While loop goes around the outside of the event structure, and get rid of the Wait function. Look in to the Simple State Machine template that ships with LabVIEW 

 

Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 16
(4,057 Views)

@James.M wrote:

The While loop version is literally the same as the For loop version you already have just with a different type of loop... You should never have even done a 1000 iteration For loop, it should have been a While loop from the start. The While loop goes around the outside of the event structure, and get rid of the Wait function.

 

 


Thanks Morris, but the things there were for a purpose. The 1000 iterations was exagerated, but it was only for testing my FOR loop, I really need the FOR loop because I will do a process reading rows from a text, and here I am making it simpler.



The wait function was only for letting me see how it change with each push. So try not to see the specifics, but to focus on my real problem: reading events from a Paused-FORloop.

 

I was just making an example, that's not how my real program would be at the end. So please, stop giving me training tools....

0 Kudos
Message 3 of 16
(4,040 Views)

I give you training tools because you need them. What you're doing won't result in a good program and you'll have more bugs down the road when it becomes unresponsive.

You don't want a paused For loop inside of an Event Structure inside of a While loop. How would you un-pause the For loop? If you pypass the event structure to un-pause the For loop, you're asking for trouble.

 

You want a State Machine because you want the application to be ready for user events. If you have your paused For loop inside the event structure, the code will be stuck inside that For loop and the user will be locked out until it's done. If you want a parallel loop to run and triggered by user input, then you should look in to a producer/consumer architecture.

 

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 16
(4,018 Views)
Solution
Accepted by topic author Stavrosyt

I would use a Que state machine to handle this properly. This way you can add more functionality later if you so desire. If you have any questions please let me know. 




Joe.
"NOTHING IS EVER EASY"
Message 5 of 16
(3,982 Views)

Please keep to one thread. 

 

Original thread: http://forums.ni.com/t5/LabVIEW/FOR-loop-pause-based-on-events-UI-and-non-UI/m-p/3179778#U3179778




Joe.
"NOTHING IS EVER EASY"
Message 6 of 16
(3,977 Views)

I would like to add that you should rearchitect this to be a state machine.  Eventually, you will want to be able to just run through all of the files/inputs as fast as possible.  With a State Machine, you can easily not go into the Wait For Event state and process everything as fast as possible.  The State Machine will just make your life so much easier here.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(4,003 Views)

No.  Continue in this thread.

 

You should always use the original thread unless the conversation shifts off topic.

 

Also, you should use the thread that has the most details.  The other thread doesn't contain any additional information.  So the proper thing to do is direct that thread back here.  Not direct people to the other thread.

 

Scattering the messages between different threads results in duplication of effort, possibly contradictory information, and just wastes everyone's time.

0 Kudos
Message 8 of 16
(3,948 Views)
0 Kudos
Message 9 of 16
(3,911 Views)

@Joe_H wrote:

Please keep to one thread. 

 

Original thread: http://forums.ni.com/t5/LabVIEW/FOR-loop-pause-based-on-events-UI-and-non-UI/m-p/3179778#U3179778


I really don't understand how my threath was duplicated, I wouldn't start a new thread using the same name and the same content......so I don't know what happen there.

 

Thanks Joe_H for the file, it is really helpful, Please we can continue in the link you are mentioning.....how do I close this thread?

0 Kudos
Message 10 of 16
(3,881 Views)