Jump to content

two while loops one VI


Recommended Posts

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?

 

Link to comment

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. 

Link to comment
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.

Link to comment

 

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
Link to comment

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
Link to comment

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
Link to comment
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
Link to comment

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. 

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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