08-18-2015 09:07 AM
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:
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?
Solved! Go to Solution.
08-18-2015 09:09 AM - edited 08-18-2015 09:29 AM
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.
-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)
Learn NI Training Resource Videos
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> ---'
08-18-2015 09:29 AM
@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....
08-18-2015 09:37 AM - edited 08-18-2015 09:48 AM
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> ---'
08-18-2015 09:40 AM
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.
08-18-2015 09:48 AM
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
08-18-2015 09:56 AM
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.
08-18-2015 10:47 AM - edited 08-18-2015 10:48 AM
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.
08-18-2015 12:27 PM
There are more details in this thread:
http://forums.ni.com/t5/LabVIEW/Notifier-for-loop/m-p/3179244?lang=en
08-19-2015 02:10 AM
@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?