While loop in subVI

Hello
I have a doubt about using while loops in VI and subVI. I have a VI, with two loop that are executed in parallel, and stoped with the same button, by using property nodes and references. One of the while loop executes a subVI.
If the Block Diagram of the subvi there is a while loop covering all the code, it's the same to put it in the main VI with another while loop, or it's not necessary?
it's the same if this subVI has a while loop covering itself that if the subvi doesn't have this while loop because the loop is in the same VI?
Thank you very much

Hello,
I hope I understood you correctly... In general, it's better to use sub VIs to organize and modularize your code. So, if you can separate part of the code into a sub VI, do it.
And if your main VI is calling the sub VI in a loop, the sub VI executes every iteration of the loop. So, you do not need a loop in sub VI, normally. But it depends on what exactly you are trying to do.
Use the Execution Highlight mode (the light bulb on the diagram toolbar) to see how the code gets executed, and make changes accordingly.
Regards,
Khalid

Similar Messages

  • Busy Waiting While Loop in SubVI?

    I'm working with a motor drive that sets a busy waiting flag while an instruction is executing and clears the flag when an instruction has been completed. I need to poll the busy flag, so I was planning on creating a subVI that contains a while loop to poll the flag. But, I know that it is recommended that while loops should not be placed in subVIs. I was wondering if there's an alternative. Would it be ok to put my code in a subVI? I've posted the code as an attachment.
    Thank You,
    Molana
    Message Edited by Molana on 08-21-2006 02:18 PM
    Attachments:
    BusyWaiting.GIF ‏12 KB

    I don't see any "flag" in your code. Is this just a boolean indicator on the calling VI that is lit while the subVI executes and reset once the call completes? Are you just setting the "busy" cursor?
    You should make sure to place this in a paralell loop in the main VI so you're not blocking the UI code and other processes. Also, as others have mentioned, your while loop needs a small wait.
    LabVIEW Champion . Do more with less code and in less time .

  • Handling while loop in subvi

    I have a subvi that currently contains a while loop.  The while loop is responsible for sequentially illuminating a grouping of LEDs continuously.  This is the desirable function of this subvi.  (if there is a better way to do this without a while loop I'm all ears)
    Secondly, I have a main vi using event structures.  To make things generic, lets say the user can select the LED grouping by selecting the 1st LED and the last LED to illuminate by editting two text fields in the main vi.  After the user enters the LED values in the two text fields, they click OK, the range is sent to the subvi, and the subvi starts controlling the sequential illumination of LEDs.  Got this working great!
    Here is where I have the problem.  The user now wants to change the range of LEDs and send these to the subvi.  Nothing happens because the subvi is stuck in it's while loop.
    whats the best way to handle this.?.it's kick'n my butt currently, and a simple example would be wonderful!
    Thanks,
    Mike
    Solved!
    Go to Solution.

    Robert Cole beat me to the punch, but here is an example of his solution.
    - tbob
    Inventor of the WORM Global
    Attachments:
    LED_Main.vi ‏8 KB
    LED_Sub.vi ‏14 KB

  • SubVi with feedback nodes used more than once inside a While Loop

    All,
    I have a subvi that does a set of operations and uses 3 feedback nodes. I am using this subvi inside a While Loop a total of 4 times. I've noticed that all instances used share the same result at each corresponding feedback node but I would like to have an individual result from each of them. Is there an easy way to go around this problem? I have come up with ways to avoid this: a) create a different vi for each time the subvi was used. b) use global variables instead of feedback nodes. Is there any easier way to go around this issue?
    ExamplePlease note that both subvi's are the same) If on my first subvi I calculate a maximum value and get 1.29 (then goes to feedback node) on my second subvi i get 1.01 my feedback node at the second subvi still registers the maximum value to be 1.29. (and I want it to be 1.01!)
    Hope this is not too confusing, I've been scratching my head with this for a while, can't find the "easy" button. Thanks in advance.
    -Pop
    Im using 9.0.
    Solved!
    Go to Solution.

    Attaching the code would be helpful. Anyway, I am not sure how multiple feedback nodes are supposed to operate so I will defer that to others to answer. As far as being able to use distinct values or instances if you are using a subVI you could mark it as reentrant. That way each call to it will behave as it it were a copy of the VI and it will have its own memory space. This should include the feedback node. You may be ending up with a single subVI and in reality a single feedback node. If you need to pass data between calls than simply wire the data through. You could also use an Action Engine to store and retrieve values. An AE is a MUCH better solution than a global variable.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Execution conflict between a SubVI and a while loop

    Hi,
    I have wired the conditional terminal of a while loop with a boolean control. The same boolean control is responsible to terminate a SubVI (not inside the while loop) which also contains a while loop (I am using a reference to the control here). When I first use the boolean control, the SubVI is being terminated, but the while loop in the main VI is not. In order to terminate the main VI, I have to use the boolean control once more. In order to avoid that, I created a "status"-indicator within the SubVI, which is set to true once the SubVI is terminated, and wired that from outside the main VI's while loop to its conditional terminal. Of course, now the while loop does only execute once the subVI transmits the status value.
    The thing is, I want both the while loop to execute before the status value is being transmitted (so, only the conditional terminal is supposed to wait for the value) and use the boolean control only once in order to terminate the VI.
    Any ideas?

    Ok.  I kind of expected to see this.
    First of all, change the "Control: Mouse Down" event into "Control: Value Change".  DO NOT USE  A LOCAL VARIABLE!!!  Wire the result straight out to the termination terminal.  You want something like this:
    Your writing to a local is a race condition.  The control was read before you wrote to it.  Therefore the loop was going an extra time around.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Stop loop.png ‏13 KB

  • Controlling a SubVI with while loop from another VI

    Dear All,
    this might be an easy Question but i couldn't catch an answer for it.
    first of all i have a VI which i will use as a subVI , this VI  is simply as shown in the "test_out of scope.vi" attached file
    now i will use it inside another VI called "Main VI" as shown in the file "Main_VI.vi"
    i'm just wondering , why couldn't i control the "Frequency" and "Stop" as i can do so while running the SubVI only without accessing it from another VI ?
    isn't it possible to access objects inside a while loop from another VI if i just connected them in the connection Pane terminals ??
    Thanks in advance to everybody
    Message Edited by Mohammed.Ashraf on 06-09-2009 10:27 AM
    Eng. Mohammed Ashraf
    Certified LabVIEW Associated Developer
    InnoVision Systems Founder, RF Test Development Engineer
    www.ivsystems-eg.com
    Attachments:
    Main_VI.vi ‏10 KB
    test_out of scope.vi ‏30 KB

    Do you need the sub-vi to run iterations for an undertermined period of time? 
    If so, then why not implement it as a parallel loop to the main one.  Maybe part of a consumer loop.
    If not.  Where the main loop would take care of each iteration and call the sub-vi in one shot. Then no need for a loop in the sub-vi.  
    It's all a matter of how you want the software to behave.  Have you looked at Event Structures?
    R

  • Create subVI with while loop

    Hello,
    i have a big program which is in a while structure and when i try to make a subVI, i have a message which tell me that my selection contain a front pannel which is in a while loop. How can i do to make a subVI?
    Thanks a lot

    Hi macarel,
    just proceed
    You should ask yourself: Which front panel control? Is it intended to be used in the subVI?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • SubVI with while loop + event structure not working in multi tab VI

    Hello Everyone,
    I am developing an interface for the control of a prober using Labview 2012, and I am stuck with some issue.
    To start with I provide you with a simplified version of my control interface VI, and with the sub-VI used to build and manage the wafer maps.
    The VI consists of several tabs: Prober Initialization, Wafer Handling, Wafer Map, Status, Error.
    The sub-VI can:
    1/ initialize the grid to display the map (sub VI Init Grid not provided here)
    2/ import XY coordinates from a txt file (sub VI Wafer Map Import)
    3/ display the coordinates and index of the die below the cursor
    4/ and when a die position is double clicked, and the boolean "Edit Wafer Map" is true, then the user can change the state (color) of the die between On-wafer die and Selected Die
    My issue:
    If I use the sub-VI by itself, it works fine. However when I use it as a sub-VI in the tab "Wafer Map", the map does not build up and I can no further use the embedded functionalities in the sub-VI.
    I suspect the while loop + event structure of the sub-VI to be the bottleneck here.
    However I don't know which way to go, that's why I'd be glad to have some advice and help here.
    Thank you.
    Florian
    Solved!
    Go to Solution.
    Attachments:
    Control Interface.zip ‏61 KB

    Hi NitzZ,
    Thank you for your reply.
    I tried to save the VIs in LV10, please tell me if you can open them now.
    Inside he event structure there is quite some code, and since I don't want to make the main vi too bulky, I would like to keep it as a sub-VI. 
    As you can see from the sub-VI, the event structure is used for extracting cursor position and tracking the double click action. These events are linked, through a property node, to the image "Wafer Map" which is passed to the main vi through connector pane.
    All values are passed this way as well (through connector pane). Is there another way?
    Maybe "refnum", but I don't really understand how to use them...
    If I use the event structure in the main vi, the wafer map is still not working. I tried it earlier.
    To implement the multi tab front panel, I used a tab control, and a for loop + case structure. For each element of the case structure, there is a corresponding action.
    For the case where I put the code (element=2) for Wafer Map, I also control the execution of the code with a case structure activated by the button "REFRESH". Otherwise I end up with a freezing of the panel right after the start.
    I hope these comments help you understand better.
    Regards,
    Florian
    Attachments:
    Control Interface.zip ‏104 KB

  • Accessing Data within while loops

    I have LabView 6.0
    I have a while loop for my GUI that accesses various sub VIs. One of the Sub VI is a LED on/off thing, which basically checks the communication with the PIC board that I have. For turning the LED on or off, I have to sent a unique command.
    Since the Sub VI for the LED on/off is inside a while loop it continuously executes. I want the SubVI to execute only when the status of the boolean controlling the LED has changed from the previous value. I tried giving a feedback from the SubVI to indicate whether there is a change, but Labview will not allow such loops.
    I then took the SubVI outside the while loop, keeping the boolean control (so that it continuously checks) inside the while loop. I would like the SubVI to execute depending on the boolean control change. I tried using occurances, but I think these execute only once. I tried accessing the boolean control through a local variable, but the value of the local variable would not change outside of the while loop. (even tried property indicators).
    Any solution would be appreciated.
    I could post the VI, but there are too many sub VIs... Dunno if it would be appreciated.
    Thanks!

    If you need to post a VI, it is best to strip out those parts which do not have any effect on the problem you are facing. With subVIs, do a Save with Options..>>Development Distribution. This will create an .llb file with your VI and subVIs.
    Queues and global variables can transfer data between independent nodes. I am not sure when the datatypes of queues changed. In LV6 you may need to flatten your data to string typpe before passing it to a queue. The functional global or LV2 style global is a subVI consisting of a loop which executes only once and which contains the data in an uninitialized shift register. Many threads on this forum have discussed these options.
    Lynn

  • How to out from infinite while loop in sub VI

    Dear Sir,
    how to out from infinite while loop in sub VI from main VI
    attached photo for solution but I can't understand it and i can't find the function in photo 
    please help
    Attachments:
    stop_subVI_frm_main.JPG ‏36 KB

    Asking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
    This is your top level VI
    And this is your subVI
    If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
    =====================
    LabVIEW 2012

  • Re: exit from a while loop in sub vi

    I think the mail didn`t get through first time. Repeat posting - Sorry if
    this occurs twice
    Shane
    Hallo,
    Can the use of occurrences solve this problem?
    The Main program can create an occurrence which can be passed to the
    sub-VIs. Upon pressing the button to cancel the loop, the occurrence can be
    set, instantly transmitted to all other VIs sharing which were passed the
    same occurrence. Of course a small handling routine has to be written (say
    a sequence parallel to the executing while loop waiting for the occurrence
    and then setting the exit parameter to "true") but this is trivial.
    I have checked this with a small program splitting an occurrence to three
    seperate VIs and it works.
    If you want, I can send a cop
    y of it.
    It may well be possible with notifiers or something else, but I have far
    less experience with them.
    Hope this helps
    Shane
    >pcu schrieb in Nachricht
    ><[email protected]>...
    >>Main vi has several sub-vi's. Each sub vi has a while loop and Boolean
    >>button. When program runs, sub-vi front panel appears, and I can
    >>stop/continue the while loop. But when I stopped a while loop in a
    >>sub-vi, I cannot control other while loops in other sub vi.
    >>I need exit function from a while loop, not stop function of entire
    >>program.
    >>Thanks.
    >
    >
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

    The notifier is probably better than occurence at this case - than it is not neccessry to write a parallel sequence.
    The use of notifier is very simple, just follow an example in Help/Search example -> Advances -> Execution control -- Synchronization -> SubVI notification.
    Good luck
    Ferda

  • How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

    I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
    1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
    2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
          i. the for loop has finished execution
          ii. the queue is empty.
       when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
    Here's the problems.
    1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
    2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
    3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
    suggestions are totally welcome!
    thanks,
    -Z
    Attachments:
    daq01v1.vi ‏59 KB

    I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
    altenbach wrote:
    zskillz wrote:
    So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
    Yes, you got it!
    As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
    rasputin wrote:
    I tried to open your VIs but it doesn't work. LV
    is launched, the dialog box (new, open, configure...) opens and then...
    nothing. Not even an error message. I guess it isn't a problem of LV
    version or a dialog box would appear saying this. Could you, please,
    send a image of the code?
    Thanks,
    Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
    thanks
    -Z
    Message Edited by zskillz on 10-20-2006 11:49 AM
    Attachments:
    daq01v1MODv2.vi ‏63 KB
    daq01v1MODpic.JPG ‏116 KB

  • How do I store 4 hours of data and get it out of the "while loop" into a spreadshee​t file for documentin​g purposes? "See additional Text for additonal info"

    What a have is a VI that uses the following SUbvi's, starts with FP OpenVI, then FP Create TagVI, into a "While Loop" which contains a FP ReadVI outputting data into a Index ArrayVI outputting to a Display (DBL). This shows the output of a FP-AI-100 monitoring a 9v battery. I have to monitor this battery for a 4 hour period my problem is storing the 4 hours of data and getting it out of the "while loop" into a "Write to Spreadsheet File VI" all I seem to accomplish is just one data sample which I get into a spreed ship file with no problem. I just can't get 4 hours worth. By the way this is my first VI and I'm self
    trained so have mercy.

    I figured it out thanks.
    John Morris
    Glendinning Marine

  • How do I store 4 hours of data and get them out of the "while loop" into a spreadsheet file for documenting purposes? "See additional Text for additonal info"

    What a have is a VI that uses the following SUbvi's, starts with FP OPENvi, then FP Create Tagvi, into a "While Loop" which contains a FP READvi outputting data into a INDEX ARRAYvi outputting to a Display (DBL). This shows the output of a FP-AI-100 monitoring a 9v battery. I have to monitor this battery for a 4 hour period my problem is storing the 4 hours of data and getting it out of the "while loop" into a "Write to Spreadsheet File vi" all I seem to accomplish is just one data sample which I get into a spreed ship file with no problem. I just can't get 4 hours worth. By the way this is my first VI and I'm sel
    f trained so have mercy.

    I figured it out Thanks.
    John Morris
    Glendinning Marine

  • Making a connector in while loop

    I want to make a subvi with a while loop.
    For example, there is a indicator inside while or for loop as my attachment.
    Actually, the indicator will be used as a progress bar which need to be updated in realtime in main vi.
    In my first thinking, the subvi is used in a simple event-driven structure(main vi) to start by a button (for user interface).
    But I realized this method is not suitable for updating the indicator in realtime after pushing the start button.
    How to make a subvi for the indicator and use it?
    That is, how to extract the value inside while loop to outside the loop in realtime?.
    Lee
    메시지가 08-12-2007 07:30 PM에 labmaster에 의해 편집되었음
    Attachments:
    aaa.jpg ‏13 KB

    trivial example attached, two vis in labview 8.2.1
    Paul <--Always Learning!!!
    sense and simplicity.
    Browse my sample VIs?
    Attachments:
    mainVi.vi ‏7 KB
    subviThatUpdatesMainProgess.vi ‏10 KB

Maybe you are looking for

  • How to disable one check box when another is checked

    Hi, I'm a first time user. i am trying to make text fields appar and dissapaer when check boxes are ticked. but only alow one check box to be active at one time.  I am making a simple form in Acrobat pro 9, I have two check boxes Checkbox1 & Checkbox

  • Lumia 920 locks up with Black Update

    I'm using an unlocked Rogers (Canada) phone on T-Mobile (USA). My phone had been working fine with the Amber update but as soon as I updated to Black it started hanging and acting weird. These are the symptoms: 1. If I have a device pin setup it hang

  • 890gxm-g65 strange bootup problem

    After I change my OC profile and revert back to optimal/default settings sometimes it does not POST wherein only led1 is lighted and my graphics fan is extremely blowing at high speeds. What I did is just to turned off the pc for about 5 to 10 minute

  • Wish List an option?

    Just to confirm: there isn't a Wish List option on the App Store for OS X? I've been hunting for it and it just doesn't exist, right??

  • How to check Navigational attribute in Planing book?

    we have 5 characteristics and 1 navigational attribute in our MPOS. after loading data into PA and checking planning book, I do not see navigational attribute in the planninng book selection window. on the left side object selection and drill down my