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 .

Similar Messages

  • 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

  • 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

  • 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

  • Using the Wait function in while loops?

    Hi,
    I have a rather complicated top level VI with about 20 subVIs and the main VI has on big while loop around it and another smaller one inside, basically it runs rather slow and I have no idea how to set the wait function. I mean what factors should I consider..what would be the difference between setting it to 10 and 100 (besides the obvious 10ms vs 100ms)? I just want to increase the performance of the executable, so it is not that slow. Can you offer some hints as to what I need to take into consideration when determining my delay? And also, are while loops the only place that I should use the delay or are there other instances too?

    Adding waits is not a fix-all for slow running applications. Its just one thing that can be done to improve things. If you determine that a sub-vi is causing your problems then you need to find out exactly what that vi is doing to slow you down. If its because there is a loop inside it that is running constantly as fast as it can, then a delay in that loop may help. If that is not your problem then you need to look at other ways to boost performance. It sounds like you have alot of locals variables, each instance of a local variable makes a copy of the data that's in the control. If the controls/indicators that you have local variables of contain large amounts of data then you may be filling up memor
    y with copies of it.
    I suggest that you study the "Performance and Memory Management" chapter of the LabVIEW manual. This can found in the printed manual of the older versions, in the online manuals that install with 6i, or on NI's web site here: http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/732cec772aa4fbe586256a37005541d3?OpenDocument , which is Application Note 168. This should give you some good ideas of what to look for to improve your performance.
    Hope this helps.
    Brian

  • How can I make a while loop wait 10 seconds before iterations​?

    I am using labview to for an osmosis system that measures the amout of water lost from the reading on a scale.  
    I currently have the program displaying the data from 3 scales every second.
    I also need to calculate the flux through the membrane over time.
    I do this with a function that takes a change in the scale reading over time (with a shift register) followed by a series of mathematical conversions.
    The readings from the scale display OK every second, but I need to have at least 10 seconds between flux calculations.
    So my question is, how do I make a the shift register take one value from the scale, then wait 10 seconds before taking the second value?  That way I have the mass of water lost over a 10 msecond period.  
    Below is my current while loop for Flux using shift registers from data from 3 scales.  
    Any helkp would be great!
    Also, I'm new at LabVIEW...

    Bob_Schor wrote:
    Do you understand how Dataflow (a key idea behind LabVIEW) works?  If you put a Wait (ms) function (on the Timing Palette) with 10000 (10,000 milliseconds = 10 seconds) inside your While Loop, the principles of Data Flow will require all of the functions inside the While (specifically the Wait function) to finish their execution before the loop can run again.  As everything else in the loop takes approximately 0 seconds, this will make your loop run once every 10 seconds.
    Bob Schor
    I do not think that is a good idea. 
    The inner loop should be in sync with the outer loop, not run independent on it's own timer.
    If the inner loop is running independently you run the risk of using stale data.
    Actually  altenbach is right the inner loop does not need to be a for loop at all, but rather just a case like my suggestion (without the for loop) and the shift registers should be out on the main loop.
    My suggestion was a quick solution going by what little bit of the block diagram I could see, but if the entire code was posted I am sure we would see where more improvements could be made and possibly even a better solution.

  • 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

  • Please wait while windows configures SAP Business One Client

    Hi
    I have just upgraded to SAP B1 8.8 PL16
    All is fine apart from when I run vb 6 to compile some early programs of mine I get the following window which you can't seem to easily cancel
    Please wait while windows configures SAP Business One Client
    Can anyone suggest anything please ?
    Thanks
    Regards Andy

    Hi,
    You may check this: SAP 8.8 PL13 - Client keeps getting Configuring Client dialog box.
    Have you searched the forum or web? There are quite a few discussions regarding the possibility for this.
    Thanks,
    Gordon

  • I am using a timed while loop and am unable to get the loop to run at a speed of less than 1ms (I am currently using the Wait(ms) function). How can I get a faster response?

    I am trying to create a virtual engine within a timed while loop and am unable to get the loop to run at a speed of less than 1ms (I am currently using the Wait(ms) function). This does not however allow realistic engine speeds. How can I overcome this? I have access to a PCI-MIO-16E-4 board.

    andyt writes:
    > I am using a timed while loop and am unable to get the loop to run at
    > a speed of less than 1ms (I am currently using the Wait(ms) function).
    > How can I get a faster response?
    >
    > I am trying to create a virtual engine within a timed while loop and
    > am unable to get the loop to run at a speed of less than 1ms (I am
    > currently using the Wait(ms) function). This does not however allow
    > realistic engine speeds. How can I overcome this? I have access to
    > a PCI-MIO-16E-4 board.
    Andy,
    Unless you use a real time platform, getting extactly 1 ms loop rate
    (or even less) is impossible. It starts getting troublesome at about
    0.1 Hz for standard operating systems.
    I'd tackle your problem with "if i mod 10 == 0 then sleep 1 ms".
    Of
    course this is jerky by design.
    HTH,
    Johannes Nie?

  • Wait time within a While Loop

    I was always under the impression that Wait Timers (e.g. Wait and Wait Ms Multiple) always executed last within a while loop. As I'm reading up on timing of real-time loops I'm finding that NI suggested using a stacked sequence structure to force timing to run last. Has my assumption of wait timer execution been wrong all this time or do PC and RT systems differ in how loops handle timing?
    Thanks,
    Craig

    So, ok, coming back on this.
    Attached you find a small example to show my remarks in the previous post.
    How to use it:
    The main focus is in the first iterations once "Wait now!" is pressed. So it is usually not of interest to run the "waiting" for more than 5-10 iterations.
    In order to see an "understandable" behavior, i suggest to wait at least 100ms. I configured "Time To Wait" to be at least 10 (coercing).
    The second focus is "Time Value".
    For "Wait (ms)", the "Time Value" will have any number, but increase each iteration by the amount of "Time To Wait".
    For "Wait Until Next Multiple (ms)", "Time Value" will be initialized to a value, which is a integer multiple of the "Time To Wait" and will increase each iteration to the next multiple.
    My example does not contain parallel code, so it does not show the parallelism of the waiting functions!
    Nevertheless, understanding the shown behavior is the key. Because if the code running in parallel to the waiting requires less execution time than the wait function will wait, the behavior will be exactly as shown.
    If the parallel code requires more execution time than the waiting, "Wait (ms)" is already finished and therefore the loop will immediatly continue with the next iteration (high CPU load!).
    If the parallel code requires more execution time than the waiting, "Wait Until Nexty Multiple (ms)" will wait that long that the "Time Value" is again in line to an integer multiple of the "Time To Wait" (so this one keeps on running in parallel until waiting time is calculated and over). Hence, "Wait Until Next Multiple" will still introduce a waiting time (reduced CPU load), but you will "miss complete iteration slots".
    As you can see, using a single "Wait Until Next Multiple" outside the loop for initialization can make sense if the first iteration should also have a "close to normal" execution time.
    Please note that the Timed Loop does something similar once started. As it does it during the iterations, the first 1-3 iteration(s) are called "warmup iterations". Most often, the first single iteration is sufficient for this though....
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.
    Attachments:
    TimingVI_Behavior_2011.vi ‏29 KB

  • Wait time in while loop: wait before all other code in the loop runs

    My vi is attached. 
    In the 'Check for Equilib' case, there is a while loop that takes data from a pressure gauge and compares it against data taken equilibTime seconds previous.  equilibTime is hooked up to a wait(ms) function inside the while loop.  Currently it appears that the code in the loop runs, and then the loop waits so many seconds before the next iteration.  I would like to reverse this process, i.e. in each iteration, the loop will wait so many seconds and then run the rest of the code in the loop.  I want to do this because I don't want there to be any delay between then time the 'check for equilib' code finishes and the start of the 'add shot' case.
    Can anybody suggest an elegant way of implementing this?
    Thank you
    Attachments:
    Take Isotherm.vi ‏294 KB

    No.  Use Flat sequences they are far preferable to stacked sequences.  Functionally they are the same.  But a flat sequence is easier to read, doesn't hide code, and you don't have to worry about backwards wiring caused by sequence locals in stacked sequence.
    Note, you have two oddities in your lower while loop.
    1.  Write a value to an indicator's terminal node and to a local variable of the same indicator is pointless.  They do the same thing.
    2.  Reading from a local variable of an indicator and writing to its terminal node is just as pointless, as you aren't doing anything.
    In your middle loop "Add shot" case, you have the local variable of DC estimate righting to a right hand side shift register, but you never use the left hand shift register.  So you are saving that value for future loop iterations, but never use it.

  • Implications of using a while loop for a wait.

    Hi,
    I need to make a thread wait until a condition is met before it can continue. I am currently using:
    while(locked){
          //Wait
    }What would be a better way of doing this as i need to keep the CPU usage as low as possible.
    Thanks for any help.

    Yes, thanks for the link. I am reading it now.
    Its not too easy becasue i am not writing pure java classes.... (Hard to explain) I dont have access to all threads.
    While im reading this could you re-asure me that im thinking about this in the right way (or not).
    I have one thread that executes some stuff then sets a global variable to true (locked = true). This thread then needs to wait until the global variable is set back to false (by another thread).
    Another thread does some processing and then sets the global variable to false (locked = false) meaning that the original thread can carry on.
    At the moment i am using the above while loop to wait but im sure there is a better way of doing this.
    Thanks

  • 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

  • In our program, we are concerned about reducing CPU work; how to wait until a boolean condition changes in a "while loop"?

    Is there a way to wait until a boolean condition changes (instruction is sent) in a "while loop" (because I want the program run until I press exit button)? Now it is consuming a lot of CPU because it is running the loop very fast waiting for instructions unless I stop the program.
    Thank you.

    Use /functions/time and dialog/wait until next millisecond multiple in the
    loop. Input 100ms.
    "mcdesm" wrote in message
    news:[email protected]..
    > In our program, we are concerned about reducing CPU work; how to wait
    > until a boolean condition changes in a "while loop"?
    >
    > Is there a way to wait until a boolean condition changes (instruction
    > is sent) in a "while loop" (because I want the program run until I
    > press exit button)? Now it is consuming a lot of CPU because it is
    > running the loop very fast waiting for instructions unless I stop the
    > program.
    >
    > Thank you.

  • 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

Maybe you are looking for