Reference in a while loop

If you open references to a LabVIEW object, such as an application,
control, or VI, close the references by using the Close LV Object
Reference function. Otherwise, the reference stays in memory even
though the VI no longer uses it.
The above quote is from Development Guide from NI. I realized that I have been using references without closing them. Even though I have never encountered any problem, I decided to add close reference to my programs. My question is, should I put the reference and close reference vis both in a while loop and open/close every iteration or should I use open reference in front of a while loop and close it after the while loop, this way, I will have to use a shift register to keep the reference. Or whether there are some other options. Can someone give some advice?
Thanks in advance,
Guangde Wang
Solved!
Go to Solution.

The fact that you didn't encounter problems with keeping the refs open is because LabVIEW has some quite good garbage collection.
In the case of a for loop you should use shift registers, because a for loop can run zero (0) times after which you will have a NULL-reference.
Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas
LabVIEW, programming like it should be!

Similar Messages

  • How to close FPGA reference out from different while loop

    Hi Friends,
                  I`ve different while loop which performs the FPGA read port on different loops I`ve the FPGA out on every terminal at the end of the while loop. I`ve just connected the merge error function in which all the error out of the FPGA are combined and given to simple error handler. How to close the FPGA Reference.

    Can you attach your VI?  I'm not clear on what you mean.  Are you saying that you are using the FPGA reference which is passed into multiple loops, and then continuing the reference wire to pass the ref out of each of the multiple loops?
    If that is the case, I don't believe you can't merge references like you can error clusters.  You will just need to wire one of the reference to the close FPGA VI.  Additionally though, I'd recommend that you use your error clusters in some manner to ensure data flow so that all the other loops stop first, and you are sure you are closing the reference after all the other loops are done with the ref. 

  • How can I reset the value of an indicator in a while loop, from another synchronous while loop?

    I am running 2 synchronous while loops, one which is keep track of time, and the other is measuring periods. In the while loop that is measuring periods, I have a boolean indicator displaying whether the signal is on or off. My problem is that when the signal is off, the VI I use to measure the periods is waiting for the next signal, and displays the boolean value from the previous period measurement. While this VI is waiting, I want the indicator to display false and not the value from the last iteration of the loop.
    I am using LV 5.1 for MAC.

    Two things you can try:
    In preface to the first, the most common (perhaps ONLY) use of local variables should be in transferring data between parallel loops. This is a matter of discipline, and creates programs that are easier to understand, take less time and memory, and are just plain cleaner. Having said that, to transfer data between loops, use a local variable.
    Second solution: Instead of setting the value to false, just hide the indicator in question by using control references (property nodes for prev. version of LabVIEW). Control references are a great way to control items on a dialog or HMI screen.

  • Getting data from a while loop while running.

    Hello,
    I did a program that call a sub-VI which is doing experiment and have its own timer.
    The sub-VI is a while loop and the stop condition of this loop is the elapsed time of my timer.
    What I want to do is to be able to get the elapsed time in my main program during the execution of the sub-VI (every second of its execution).
    First I assign the elapsed time in the sub-VI as an output of it. But of course the elapsed time is only updated in the main VI only when the while loop has finished. So I tried several solution: property nodes, local variable, global variable.
    When I am using global variable, I can see the elapsed time being updated during the while loop when I open the global variable VI. But the result is always the same: in the main VI the elapsed time is only updated at the end of the while loop.
    I think that is the global variable is updated every time, I could be able to get its data to my main VI?
    Does anyone have an idea?
    Thank you,
    Meach

    I tried using shared variable and reference without succes.
    I will keep searching.
    I enclose my VI that I simplify the most but with still keeping the shape of my real program. If you can take a look I will really appreciate.
    The goal is on the top-level VI to be able to see the updating data time in real time.
    Thanks,
    Meach
    Message Edited by Meach on 07-23-2008 04:13 PM
    Message Edited by Meach on 07-23-2008 04:14 PM
    Attachments:
    Elapsed Time.zip ‏25 KB

  • How can I update cluster items from inside a while loop that does not contain the cluster?

    I have a VI that contains front panel clusters and two while loops. The main cluster contains items such as a doubles "distance" and "stepsize" and boolean "step" (a whole buch of this type stuff). The first loop contains an event structure to detect front panel changes and the second contains code and sub VIs to perform operations based on detected events.
    The operator can enter data into either double or click the boolean. If distance is changed the second loop does what is required to process the change. The same happens with stepsize. If step is clicked the ±stepsize value is added to distance and the result is processed. In each case the front panel should track the result of the input and subsequent processing.
    Because the clusters are outside the while loop, they are not updated unless I click 'highlight execution' which seems to allow updating each time the execution highlight is updated. There are other issues if I move the clusters into one of the loops.
    I've tried referencing the clusters and using local variables and nothing works. It looks like overkill to use shared variables for this.
    Any ideas would be greatly appreciated.
    Thanks,
    Frank    

    Hi Ben,
    Thank you for the response. I followed the link and tried reading everything you posted on AEs but I'm afraid that I didn't understand it all. It seems that each AE example had a single input and a single output (e.g. a double). Is this the case? 
    What I have is a couple of front panel clusters containing (approximately) 18 control doubles, 8 indicator doubles, 5 boolean radio button constructs and 26 boolean control discretes. I clusterized it to make it readable. In addition I'll eventually have a cluster of task references for hardware handles.
    All I want to do is update the front panel values like I would do in a C, VB or any other language. I've tried referencing the cluster and using the reference from inside the loops. I've tied using local variables. Neither works. I'm experimenting with globals but it seems that I have to construct the front panel in the gloabal and then I wouldn't know how to repoduce that on the front panel of the main VI.  Sometimes it seems that more time is spent getting around Labview constructs than benefitting from them.
    I hope the 'Add Attachment' function actuals puts a copy of the VI here and not a link to it.
    Thanks again for the suggestion,
    Frank 
    Attachments:
    Front Panel Reference.vi ‏33 KB

  • Is there a way to run a For Loop independen​tly within a While Loop in LabVIEW 2013?

    In my program I would like to run a For loop inside of a While loop, and have them run independently, at their own execution rates.  As a test, I wrote a simple VI with a While loop with 1 second timing, and into this I inserted a For loop with 3 second timing.  I created indicators for both iteration terminals.  Upon running the VI, I found the While loop waits for the For loop to run N times before the While loop executes again.  I also found that sometimes the first iteration of the For loop will end at 1 second rather than 3 seconds, and the STOP button to terminate execution of the While loop does not always work.
    Solved!
    Go to Solution.

    ksinks wrote:
    Thanks, how would you synchronize the loops?  I have gone through the Getting Started exercises and manual.
    Why would synchronization matter? Did you want them to run independantly at their own speed or not?
    Regardless, there's a synchronization pallette with functions for this, as Occurance.
    Other solutions include a common loop counter and a case structure executing every X'th iteration, or having the faster loop send a queue or event every X'th loop that controls the slower loop.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to get the loop sequence time (i) out of the while loop in the sub-vi to the main vi?

    I tried to search for the answer but no much luck.  My situation is that I used a sub-vi containing a while loop in my main vi. Now I need to see the while loop sequence number (i) from that sub-vi in my main vi.  In the sub-vi I have the indicator to show this loop sequence flawlessly, but that's inside the loop itself.  If I use this indicator as a terminal in the sub-vi, I can only see the last sequence number in the main vi after the loop finished its execution.
    Is there a way to accomplish this? Thanks.

    Hi nobody,
    well easiest (but error prone) way is to use globals to move data from subvi to main vi. You can also give the reference of the main vi indicator to the subvi to write to a "value" property node. You can also use queues, and there are other techniques too
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • While Loop - Object Creation

    Hello,
    I have a question on object creation and while loops. Have a look at the following code snippet:
    while(true)
           Object obj = new Object();
           // Pass off obj to a new thread
           Thread job = new Thread(new ObjectHandler(obj));
           job.start();
    }My question is, do I have to wait until the newly created Thread is finished with the Object obj before I can create a new Object called obj in the while loop?
    Also does anyone have any documentation on this sort of thing?
    Thanks,
    Tony.

    Jaxie wrote:
    I'm still not sure you get what I'm on about, you might want to read up on java methods and pass by value.I think we know how it works. Most of us have been programming in Java for serveral years.
    >
    When you pass an object to a method in java you pass it a copy of a reference to that object. Leading on from that, before an object is eligible for garbage collection in java, all references to that object must be dropped.
    So with all that in place, my question was, is the creation of an object in a while loop dependent on previous objects of the same name? Objects don't have names. Have we mentioned that before?
    You have a reference, larry that is referencing an unnamed object. You can also create other references that reference the same object. The thread will have one reference. You can then make larry reference another object. That will not change anything in the thread. It will still reference the old object, and that object will not be claimed by the gc until that thread stops referencing it.
    So the second time we go through the loop below, do we have to wait until larry has been garbage collected, before a new larry can be created?Read the articles/tutorials and what I have written above. What do you think?
    Do also note that the GC isn't executed synchronously.

  • 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

  • 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

  • While loop halted

    Hello Folk,
    I am developing an application which acquires data at 1 ms and store it to TDMS file. I have two seperate loop for acquisition and data writing. I set starting of acquisition on trigger pulse so while loop halts untill my system is triggered  and resume on trigger pulse. Now that writing into TDMS file is slower than acquisition, I queue acquired data and dequeue it in another loop.
    Here my problem comes, 
    As of faster acquisiton, for 600 seconds data acquisition my file is written with only 195 seconds data. The rest of data is in queue. As soon as the stop trigger comes my acquisition loop halts and with it my writing loop halts too. It is not being possible for me to write another 405 seconds data in to file though my program is running. 
    Is there any way that my writing loop never halts? I havenot configure anything for my writing loop to halt however the dequeue reference of my writing loop is the same as queue reference of acquistion loop.
    Your help will be truly appreciated.
    Thank you,
    CLAD
    Passionate for LabVIEW

    Hello,
    I designed this code for RT and that is why I used timed loop and dint put any condition to stop the loop. I m not sure am I right or not on this.
    Answers to your other questions are below,
    Only latest packages are missing and I removed that sequence. 
    Can you please put some more sense into me for well designed RT code?? 
    One more thing I would like to ask is there any way to write the data faster,? I meant as soon as the data queued up it should be written into file. 
    Norbert_B wrote:
    Several things to consider:
    - Without seeing the complete code (VI), we can only guess about things
    - You use nested case structures which rely on shared variables to enqueue data. I doubt that you enqueue the amount of data you *think* you enqueue
    - Have you ever checked the iterators for the loops? For the enqueuer, you should create a custom iterator to count the enqueues you are performing (seems that you are already counting this, but not "using" it)
    - Which "packages" are "missing"? Only the latest? Some "in between"?
    - Why do you use a timed loop as producer?
    - Why are both loops running without the option to stop? Is that a program running on RT, please learn how to desing code for RT.... (as your code is obviously not designed for RT)
    - Why all those sequence structures? Please remove them
    All in all, i currently assume that the VI is working "perfect" as it only does what your code tells it to do. If that is the same that you *want* it to do.....is the question.
    Norbert
    Norbert_B wrote:
    Several things to consider:
    - Without seeing the complete code (VI), we can only guess about things
    - You use nested case structures which rely on shared variables to enqueue data. I doubt that you enqueue the amount of data you *think* you enqueue
    - Have you ever checked the iterators for the loops? For the enqueuer, you should create a custom iterator to count the enqueues you are performing (seems that you are already counting this, but not "using" it)
    - Which "packages" are "missing"? Only the latest? Some "in between"?
    - Why do you use a timed loop as producer?
    - Why are both loops running without the option to stop? Is that a program running on RT, please learn how to desing code for RT.... (as your code is obviously not designed for RT)
    - Why all those sequence structures? Please remove them
    All in all, i currently assume that the VI is working "perfect" as it only does what your code tells it to do. If that is the same that you *want* it to do.....is the question.
    Norbert
    Thanks for your concern
    CLAD
    Passionate for LabVIEW

  • Code golf: stop two while loops with guaranteed iteration ratio

    Proposal
    In the vein of the Perl tradition, I'd like to see if there's any interest in solving short programming puzzles in LabVIEW. Anyone can post a problem and define the rules for solving it.
    Here's a beginning/intermediate question to whet your "palette".
    Description
    With one user-action, how would you stop two while loops such that the ratio of their iterations is the always the same? One concrete way to visualize this situation is in taking measurements: two instruments use the same timing source to take measurements, but second divides the clock down so that it is an integer factor slower than the first. For example, if the slower instrument is four times slower, then at the end of the VI, if the slower instrument takes 100 measurements, the faster instrument has taken 400.
    Rules
    You may only use vi.lib
    You cannot include any other subVIs
    Your solution must pass for loop1 interval as low as 25 ms
    Template (attached in LabVIEW 2009)
    If folks are interested in this, then let's figure out how to make future problems better. Please post your suggestions and critiques, but only if you also post a submission ;-)
    Solved!
    Go to Solution.
    Attachments:
    Multirate Loop Code Golf.vi ‏11 KB

    Norbert_B wrote:
    a) You work with an integer factor of speed. While this matches many application areas, there are still cases where the factor has to be floating point (e.g. 2.5). Additionally, the factor might "invert", so the master loop runs slower than the slave (factor 0.5 for instance).
    It sounds like you're about to post another code golf question. If you think the problem scope is too small, you're welcome to fashion one to your taste. Thanks for volunteering :-D
    Norbert_B wrote:
    b) This example does not take into account that the hardware has to be synchronized with more accuracy than the software supplies (PXI?). If hardware synchronization is required, there are two possible ways:
    - The factor can be included in the synchronization (using PLL for instance)
    - The factor has to be software implemented by data reduction for the task running at the lower pace.
    Hrm, maybe puzzles aren't really your thing after all. You are correct: I did not define every constraint that can lead to a provable best closed-form solution, but that does not prevent people from stating their assumptions and forming creative, well-reasoned, and still correct designs. I overlooked this reading of the description and neglected to add a statement that said solvers were free to add their own conditions. I will do so in the fugure :-)
    If we choose the first of your suggestions, the VI must still retrieve the data at different rates. You can dedicate a loop for each instrument to decouple any jitter and latency introduced by their connectivity or internal operation; this adds some margin of safety when there is thread and driver contention. You can also implement a single counting loop like altenbach and forego the multiloop complexity.
    Norbert_B wrote:
    c) You don't state anything about "what happens with the data". Is this time consuming? Does it introduce additional delay in loop iterations? Is it OK to have data loss?
    I don't know -- you decide, you disclose, and you solve :-)
    In my specific situation, the measurements are time consuming and do add delay (each data "sample" is 5-20 megabytes), none can be lost, and the data must be available for others to analyze later. In addition, the amount of data is saturating the hard disk throughput. If a particular write takes too long, the instrument driver may overwrite a yet unfetched sample, which is unacceptable. I did not add these details to the problem discripton becuase they don't impact the puzzle.
    I don't want to burden people with my situation and ask them to solve my problem: I want to encourage them to bring their intuition and experience to a discussion. This is the design process at its heart: understanding why and how constraints affect your decisions. If a person states the additional conditions they've assumed, readers can learn why, and more importantly, when a Notifier might be more desirable than an Occurance or a Queue more robust than a Data Value Reference.
    The best NI-published advice for stopping multiple while loops (https://www.google.com/search?q=labview+stop+multiple+while+loops) is laughable (and is the "solution" in my template).
    Would you care to re-approach and contribute to this puzzle? I suspect you have a lot to offer :-)

  • Question about while loop using Timer?

    I am trying to use a while loop to read data from oscilloscope through
    GPIB card continously(lasting for a fixed time, for example,1 minute). I
    want a Timer, when it expires, the while loop will stop. But I do not
    know how to implement it.
    Any help would be greatly appriciated!
    Thanks in advance.
    zhljh
    Sent via Deja.com http://www.deja.com/
    Before you buy.

    In article <87q5t2$7kh$[email protected]>, wrote:
    >I am trying to use a while loop to read data from oscilloscope through
    >GPIB card continously(lasting for a fixed time, for example,1 minute). I
    >want a Timer, when it expires, the while loop will stop. But I do not
    >know how to implement it.
    So, you need it to count down, then I assume? Okay, you need to put a
    true/false node within your for loop. Set the true case to i=1 (iteration
    of the for loop) so that it will initialize one time (and be true one
    time). Then, add whatever time you need for the vi to run to that
    indicator (where you send a numeric value on the first iteration). Put a
    greater than comparison to the timer and the additoin of the indicator and
    your value. Let that be the term
    inating thing on your for loop.
    Now, this might present a problem with a circular reference. If it does,
    you'll need to basically do the same thing, only you'll need to send the
    value through a shift register in the for loop.
    Harry

  • Labview Crashes when I try to close my while loops

    Hi
    I have written a LV Vi  for  simultaneously  aquiring a
    video stream from 4  Fire Wire cameras. In this vi I use multiple
    while loops(running parallel).
    Nearly every time I try to stop the VI labView crashes and doesn't respond at all.
    The only chance to stop LV is to close it with the task manager.
    I'm using LV 8.2.
    Has anybody got an idea.
    Thanks a lot
    Matthias

    Hi Mathias,
    this behaviour I experienced often when using large amounts of memory by creating large arrays (with many copies). Another proplem is to create references without closing them, this consumes windows ressources. While the VI runs, is there an increasing use of memory in the task manager?
    When the VI tries to stop, are you able to switch to the block diagram? Then you could activate the highlight mode (debugging) and LV shows, which node is still working with the green arrow at the node.
    Just a few ideas...
    Greets, Dave
    Greets, Dave

  • Iterate while loop on command

    This seems like it should be a relatively simple application of a while loop, but I can't seem to find the solution :/ Basically I have a string control on my front panel for a filename (minus path/extension), and when I start up the VI I check if the file already exists. If it does, I'd like to start a while-loop in which each subsequent iteration only occurs when the string control is changed by the user.
    The way I have it wired up now works fine (see attached), but it loops every 50 ms even while there's an invalid string. If possible I'd like to pass to the next iteration only after the control value has changed. This way I can display an error dialog of some sort that won't pop up every 50 ms. (Note: this is a piece of code from a subVI, hence the refnums and property nodes.)
    Thank you!
    Attachments:
    input_loop.vi ‏12 KB

    phogan wrote:
    The reason for all the refnums is that I'm trying to check controls that are on the main front panel while I'm within this subVI loop. If you have a better idea than that, feel free to let me know. As far as I know references are the only way to access a control that may be changing once you've already entered a subVI.
    Thanks for the tip on the event structure, I'll give that a shot tomorrow.
    Yes, refs are the only way to control front panel objects from another vi, but do you need to? Send the value to the checking vi and react to that, if need be return a Valid boolean or similar, that's how it's usually done.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

Maybe you are looking for

  • Developerday  VM Ora-12505 Getting Started with Oracle SQL Developer 3.0

    Just downloaded the VM , Started the tutorial Getting Started with Oracle SQL Developer 3.0 As mentioned in tutorial , I was trying to make a new connection and I am getting following error Ora - 12505 : TNS Listener doesn't currently know of SID I g

  • Searching for dashboard Talent Management in OBI APPS

    Hi All, I have question to the Gurus that I am searching for Talent Management in OBI Apps Human resource , is it available in 7.9.6 version because we have 7.9.5 and it is not there in that ? Thanks for quick response, Amol

  • From File Server to SharePoint

    Hi, I would like to move all the files in several folders on a fileserver and put them on sharepoint. The files in the fileserver are organized in several folders and subfolders (quite deep) and the security is controled via user Group membership (AD

  • Small annoyance after migrating with Tiger

    Hello I have recently had to purchase this iMac G5 computer (spec below) after being struck down with the Apple-recognised Video & Power problems on my eMac 1.25GHz. Having updated iMac to OSX 10.4.8, I proceeded to use migrate assistant to copy over

  • Creative Cloud opened with a small box and cannot do anything

    Hello, I decided to turn on Creative Cloud when this appeared and I can't seem to do anything but move the small box around. Can someone help me?