wannabecontroller Posted May 13, 2019 Report Share Posted May 13, 2019 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 Quote Link to comment
jcarmody Posted May 13, 2019 Report Share Posted May 13, 2019 Remove any wires connecting them. Quote Link to comment
infinitenothing Posted May 13, 2019 Report Share Posted May 13, 2019 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? Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 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. Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 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. Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 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 Quote Link to comment
JKSH Posted May 14, 2019 Report Share Posted May 14, 2019 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. Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 1 minute ago, JKSH said: 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. trying now, thank you so much for your idea Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 tried it still wont run Quote Link to comment
JKSH Posted May 14, 2019 Report Share Posted May 14, 2019 13 minutes ago, wannabecontroller said: still wont run Post your code. Without it, we can only rely on our crystal ball. Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 (edited) 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 This is the Sub VI in Loop 2, just for an LED blink This is Loop 2 in the main VI The Sub VI for blinking LED is the one pictured here Edited May 14, 2019 by wannabecontroller Quote Link to comment
JKSH Posted May 14, 2019 Report Share Posted May 14, 2019 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. 1 Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 (edited) 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 May 14, 2019 by wannabecontroller Quote Link to comment
ShaunR Posted May 14, 2019 Report Share Posted May 14, 2019 Perhaps this makes it clearer. What you are doing: What you want to do: 1 Quote Link to comment
JKSH Posted May 14, 2019 Report Share Posted May 14, 2019 (edited) 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 May 14, 2019 by JKSH Quote Link to comment
wannabecontroller Posted May 14, 2019 Author Report Share Posted May 14, 2019 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.