Jump to content
Sign in to follow this  
wannabecontroller

two while loops one VI

Recommended Posts

Hello

I have two independent while loops i want to run in one VI

Both loops run continuous tasks such as running a wave form generator or similar

The second one wont start because the first has not "completed"

Is there a way to have two while loops run independent in one VI?

Thanks

Share this post


Link to post
Share on other sites

Remove any wires connecting them.

Share this post


Link to post
Share on other sites

To clarify the previous post, the two loops can share a wire as long as that wire is an input to both of them. If the wire is an input from one and an output to the other then the loop that is expecting the input will have to wait for the other loop to output the data.

If you intended to use that wire to communicate data between the two loops, maybe convert the wire between them to a channel wire?

 

Share this post


Link to post
Share on other sites

Thanks

Much Obliged

Ill give that a whirl. 

I have a few small functions that do some simply things like blink an LED for a status indicator. I cant put them in the main while loop because they onbiously never complete being continuous functions. 

Aka the LED never stops blinking so the while loop never iterates. I wanted to put it in its own loop is what i was up to. 

Share this post


Link to post
Share on other sites

I tried to while loops with no wires connected what so ever. They still will not execute independently

Putting a probe on the second while loop still says not executed. 

The only thing between them is a single shared variable of type bool

Frustrated that after 2 days i cant get two while loops to execute. 

Share this post


Link to post
Share on other sites

can anyone help?

i am loosing my mind over this

No matter what i do, two totally independent while loops will not execute

they  share only one "shared variable" I can not even comprehend why something so simple is turning out to be so difficult

 

 

Share this post


Link to post
Share on other sites
54 minutes ago, wannabecontroller said:

I tried to while loops with no wires connected what so ever. They still will not execute independently

Putting a probe on the second while loop still says not executed. 

The only thing between them is a single shared variable of type bool

Make sure you have a Wait node in both loops: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P82BSAS&l=en-AU

Without a Wait node, one loop will consume 100% of a CPU core. This could be why your 2nd loop is unable to run.

Share this post


Link to post
Share on other sites
13 minutes ago, wannabecontroller said:

still wont run

Post your code. Without it, we can only rely on our crystal ball.

Share this post


Link to post
Share on other sites

 

This is what i am doing. Its just a simple state machine example project

The second while loop is calling a sub VI that does nothing but blink an LED on the front panel to show the state machine did initialize

Its more for looks and practice then anything. 

It will not execute. I know the VI runs fine on its own. Its been tested

The state machine also runs fine with no issue until i try and make the LED blink

I know this is dumb but i really appreciate the help

 

 

Loop 1 in the Main VI

statemachine1.PNG

This is the Sub VI in Loop 2, just for an LED blink

blink.PNG

This is Loop 2 in the main VI

The Sub VI for blinking LED is the one pictured here

statemachine2.PNG

Edited by wannabecontroller

Share this post


Link to post
Share on other sites

So your subVI contains its own (perpetual) while loop -- is that right? You must understand: A subVI doesn't "finish running" until all of the loops inside the subVI stops. Therefore, Loop 2 in your Main VI cannot continue -- it is blocked because it is waiting for your subVI to "finish running".

You don't need that subVI. Just put all the blinking logic in Loop 2.

Anyway, it is best to post actual VIs, not screenshots. The screenshots might not show important connections.

  • Confused 1

Share this post


Link to post
Share on other sites

A subvi is nothing more then a function

so because the blinking LED is wrapped into a function labview falls on its face

 

The reason I am

annoyed and don’t understand what the problem is , to my understanding was suppose to be able to run parallel functions with ease

in your post above you mentioned that as long as they are not wired together they should run independently. 

Now you say they are dependent on execution.

 That is not parallel  that is concurrent 

Loop1 shouldn’t care what loop 2 is doing. 

So essentially creating a sub vi that has a continuous task is useless you are telling me because there is no way to execute it? Is that correct

I thought the whole point of being a good developer was to build re-usable code in the form of functions that can be used over and over. Is that not the case for continuous functions that never complete like  wave form generator or the like

 

thanks for your reply

 

 

Edited by wannabecontroller

Share this post


Link to post
Share on other sites

Perhaps this makes it clearer.

What you are doing:

image.png.fdec1b88de2e33ad2b2e593b6e6d1ac7.png

 

What you want to do:

image.png.8fd4d3e2c5ada30864747f9bb5cdd5e7.png

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, wannabecontroller said:

Loop1 shouldn’t care what loop 2 is doing.

In your code, Loop 1 and Loop 2 are parallel and independent as you expect.

Loop 2 not blocked by Loop 1. Loop 2 is blocked by the subVI inside Loop 2.

 

1 hour ago, wannabecontroller said:

A subvi is nothing more then a function

Yes, a subVI is a function.

But your function does not return, so it blocks the loop!

 

1 hour ago, wannabecontroller said:

So essentially creating a sub vi that has a continuous task is useless you are telling me because there is no way to execute it? Is that correct 

Not correct.

You can execute your subVI by putting it OUTSIDE of Loop 2.

 

Edited by JKSH

Share this post


Link to post
Share on other sites

Thank you for your continued support

Just for kicks i have taken out the SUB VI and just recreated the stuff in the subVI in loop 2.

It runs now

However i have created a new mess that is now causing issue

I have tried to add a few states to the state machine. Of course i broke it.

I will have to post the VI's some how. It is clear i am not understanding this execution. 

The state machine works fine with one function. I did not add any new functions just the cases for them and now im back to my initialization loop not running. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.