Static VI reference

When do people actually use the static VI reference?  It seems to me that it is only useful if you want to hardcode a vi reference with its location into the code.  I can only use it with the call by reference node.  Is the static VI reference useful elsewhere?  I know how to use it with the call by referene node when it is stictly typed, but when it is not strictly type, I don't know when to use it.
Kudos and Accepted as Solution are welcome!

tst wrote:
I use it for two additional things:
If I want to place a free running subVI into a subpanel or otherwise control it programmatically.
If I want to generate reentrant copies of a VI. The static reference ensure that the VI is in memory (included in the build) and you can then use its name or path property to open the new reference.
Number 2 for me as well.  This makes reentrant calls to dynamically called VIs work nicely in EXEs as well.  If I just reference a VI by name I need to be sure that that VI is in memory.  This use to mean include it in the build in an EXE, and then build the path to it (my.exe\reentrant.vi) and call it.  But this means I need to remember to add this to a build ever time I use this VI that calls the reentrant VI.  With the static reference, the calling VI knows that the reentrant VI is needed and a dependency so it will be included by the application builder.  Then when I need to call it I can get the name from the static reference it self, so again I don't even need to know the name of the VI.
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

Similar Messages

  • How to access a property in a static vi reference

    Hi,
    I'm completely new to Labview and I'm working on a project that includes controlling CANalyzer from LabView by an ActiveX control.
    In CANalyzer I have a CAPL function that I need to call from LV. The problem is that the function must be created in the onInit event when starting a canalyzer measurement. The only way I have found to create the function is to use a "reg event call back" and create the function in a "static vi reference". This works and I can call the funtion from that vi, but I'm not able to call the function from anywhere else but from the "static vi reference" and since it must be strictly typed I can not add any output connector where I can add a reference.
    I've been trying to solve this for thee days now and it's starting to feel hope less.
    In VB the complete code would look something like:
        Dim WithEvents gCANApp As CANalyzer.Application
        Dim WithEvents gMeasurement As CANalyzer.Measurement
        Dim gSendFunction As CANalyzer.CAPLFunction
        Dim Y
        Set gCANApp = New CANalyzer.Application
        gCANApp.Open ("C:\...xxxx.cfg")
        Set gMeasurement = gCANApp.Measurement
        gMeasurement.Start
        gSendFunction.Call
       'Measurement OnInit event handler
       Private Sub gMeasurement_OnInit()
           Set gSendFunction = gCANApp.CAPL.GetFunction("MyFunction")
       End Sub
    This would work fine since I have a reference to gSendFunction in my main code.
    My LV code looks like this:
    and my static vi ref looks like this:
    What I think I need is a reference to the data thread coming from "GetFunction"
    If any one can help me solve this I would be very happy!
    Best Regards
    Henrik

    Hi,
    you could add another input to your static vi ref where you input the reference to a reference display element which sits in your other vi (upper image).
    Then you could make a signaling value change to the reference display element from within your static vi ref.
    In your other vi set up an event structure to detect the value change. In that event close the vi - this will let you have the desired reference as output of that vi.
    Regards Florian

  • Wire: Function Conflict, Static VI Reference

    Hello Community,
    Sorry if this has already been answered before, but I have spent an hour searching. I am trying to learn a little about using subVIs to clean up my code.
    I'm trying to connect a static VI reference of a Gaussian function that I made to the Nonlinear Curve Fit.vi, but I get a broken wire which says "function conflict".
    When I create constants for the output of my Gaussian VI and the input of the Nonlinear Curve Fit.vi, they are clearly different classes.
    Could someone show me how to edit my Gaussian VI to match the class properly? I'd greatly appreciate it.
    Thanks,
    -Patrick
    Solved!
    Go to Solution.
    Attachments:
    pat_gaussian_fit.vi ‏24 KB
    pat_gaussian_fit.vi ‏24 KB

    Your model subvi needs a connector pattern that is identical to the template. Start with the template mentioned in the help and only modify the code, not the existing controls and indicators. Simply leave unused terminals disconnect, don't delete them.
    LabVIEW Champion . Do more with less code and in less time .

  • Static vi reference read indicator values

    The objective of my code is to open a separate VI when a certain boolean button is clicked, wait for action from the user, then close the separate VI, and return its values to the main function. I have put a static VI reference in my block diagram, and then two invoke nodes: "FP.Open" and "Run VI". That works fine, but I still haven't figured out how to obtain the values of the indicator from the reference. I thought I might use a Property Node, but I couldn't find the right property to select. Any help? Thanks!

    And
    if you still want to proceed with the idea of calling by reference, set the invoke node 'Run VI' to wait till complete as 'True'.
    Then, place another invoke node after it, for Get Control Values. You will get an array of clusters, each cluster with the control/indicator name string and its value in variant data type.
    Process that array of clusters.
    Post your code if need further help.
    i would support 'Christian's first option, of calling the vi as a sub vi and pass the indicator value as a terminal on the connctor pane.

  • How to change parameters of Static VI Reference

    Can anyone let me know how to change the parameters of a static vi reference please? right now when I right click on it, just says "Strictly Typed VI". I don't know how to add/delete/change the parameters of it.
    Thanks,
    Solved!
    Go to Solution.

    Hello Triple H,
    This is Andrew Brown, an Applications Engineer with National Instruments. You will need to go through the process to create a new strictly typed VI reference in order to update the parameters of your Call by Reference Node. An article that details this process is Creating a Strictly Typed VI Reference That Calls VIs Dynamically. 
    Please let me know if you have additional questions or issues in this area.
    Regards,
    Andrew Brown
    Applications Engineer
    National Instruments

  • Using static VI references in an application

    Hello all you helpful forum-goers!
    I am using 4 different static VI references hooked directly to "Run VI" invoke nodes, with the "Wait Until Done" and "Auto Dispose Ref" parameters both False, to run four VIs dynamically, each of which does nothing except call my re-entrant serial port input/output VI with a different COM port index number.  Overall this is working pretty well.  However, I have a couple questions about improving my setup.
    1) Is it possible to somehow set an input parameter to the re-entrant serial port VI, and thereby be able to Invoke it directly four times in a for loop, each with a different input value?  I'm not sure how I would do that, except that I've heard that you can set the value of a control of a VI using a reference to it.  I also worry that using the same static VI reference to Invoke the VI 4 times would somehow re-start the same dynamic VI instance 4 times, instead of spawning 4 copies of it.  However, this solution would allow me to delete the 4 VIs which do nothing except call the re-entrant VI, and my code would be simpler and more expandable (e.g. making it easy to interact with 8 serial ports in the future just by increasing the number of for loop iterations).
    2) It seems to be required for me to add the 4 VIs which I Invoke dynamically to my lvproj file, and then add to the "Always Included" section of my application build properties in order for them to be included in my application executable.  This was what I had to do in previous versions of my code when I referenced the VIs via a path name, but now that I changed to using static VI references, I thought they would be included automatically.  LabVIEW already knows to automatically load them in memory (e.g. when I do a search it searches them even when they are not open), and they are included in the Dependencies list in my LabVIEW project, so why would they not be built in to my executable?  I'd prefer not to have to add them explicitly, as it is just one more thing to forget if I change it in the future.  Is there a setting or something somewhere which I can change so that they will be included in the executable automatically?
    Thank you very much for your time and assistance, as always!
    -Joe
    Solved!
    Go to Solution.

    Nope.  If you look at the Help for the "Run VI" method, you find the following information for "Auto Dispose Ref":
    "If TRUE, the target VI detaches the reference from the main VI.  When the target VI finishes executing, LabVIEW automatically disposes of the reference, along with the parallel data space.  If FALSE, the main VI retains control of the target VI."
    So by setting "Auto dispose" to T, you pass control of the reference to the subVI itself, and LabVIEW will dispose of the reference when the subVI finishes running.
    I will second Jeff and urge you to get rid of the global variable!  I haven't used a global variable in something like 14 years.  I haven't needed to.  Myself, I love a good notifier and would urge you to use a notifier instead of a queue if you're going to be spawning VIs.  Why?  Because the first instance of your spawned VI to receive the "stop" message from the queue will remove that message from the queue, thus preventing the other instances from receiving the message.  So you'll have to send the message repeatedly and hope that everyone eventually receives it.  If you use a notifier, anything that contains a "Wait on Notification" with that notifier reference will receive the message.  I think you want multiple listeners here, right?
    Ok, this afternoon I'll try to write some dummy code with a statically called VI in it, compile it into an exe, and see if I can duplicate your problem...
    One question, were you just using the static VI reference by itself to call your VI, or were you using it the same way I showed in my earlier post, with "Open VI reference"?  I'm just trying to look for differences between what I've done in the past which has worked, and what you're doing now which isn't working...
    Jeff, what say you?

  • From Classic abap FMs to ObjectOriented instance/static methods: reference

    Hi All,
    we are migrating one of our project developed using classic abap to abap objects.
    mostly we are replacing the Function modules with either instance methods or static methods.
    for e.g.
    if there are FMs like GUI_UPLOAD, SO_NEW_DOCUMENT_SEND_API1 are used, after exploring in sdn for abap objects, we realized
    we can use cl_gui_frontend_services=>gui_upload( ) instead of the GUI_UPLOAD.
    send_request = cl_bcs=>create_persistent( ). send_request->send( ).  can be used instead of SO_NEW_DOCUMENT_SEND_API1
    like that there are several FMs present, is there any easy way where we can find this reference of object oriented methods corresponding to the plain old Function modules of classic abap.
    i was thinking, after seeing the blogs of people like Thomas Jung, Horst Keller, they encouraged a lot on abap objects over procedural abap. are there any such guidlines, references present to migrate (rather upgrade) to abap objects from existing procedural abap
    thanks,
    Madhu_1980

    I don't think it makes sense to do 1:1 mapping and replacement in your code.
    It does make sense to refactor using Object oriented techniques and patterns but it is usually a non-trivial task.

  • Static class reference

    Below we have a class containing a static class variable and a static accessor method.
    The method is responsible for assigning the variable, which it does on demand.
    public class MyClass
        private static int INFO = -1;
        public static int getInfo()
            if(INFO < 0)
                try
                    INFO = ...;
                catch(Exception e)
            return INFO;
        }When using this class is it not safe to assume that the assignment of the variable will ever only occur once for the life of the system that uses this class? (afterall is it static within the class)
    I am experiencing the situation whereby EVERY time the method is called, the assignment of the variable is necessary. I can only assume that the static instance of this class in memory has been lost between each call and therefore the state/value of the variable has also been lost.
    It is worth noting that no object instances of this class are ever created. The class is accessed only through its static interface. It seems that since no local reference to objects of this class are held in memory then the entire class, along with its internal static state, is cleared from memory (garbage collected?).
    How is it possible to ensure that the state of static fields within such a class is preserved over time, without create instances of the class.
    John

    When using this class is it not safe to assume that
    the assignment of the variable will ever only occur
    once for the life of the system that uses this class?First of all, you haven't said what you assign it to, so we can't say. If you assign a value less than zero then it will be reassigned next time the method is called.
    Secondly, it depends on whether or not you're expecting it to be thread-safe? It isn't.
    If your code is not multi-threaded, then the section of code in your getInfo method that assigns the field should only execute once during a single run of an application.
    Thirdly, you explicitly assign it (to minus one) at class initialisation time, so stricty speaking, the variale will always be assigned at least once, and will be assigned at least once more if the getInfo method is ever called.
    I am experiencing the situation whereby EVERY time the
    method is called, the assignment of the variable is
    necessary. Can you offer any evidence to this? A small, complete, compilable and executable example that demonstrates the problem will help, and will probably get you an answer pretty quickly around here.
    I can only assume that the static instance
    of this class in memory has been lost between each
    call and therefore the state/value of the variable has
    also been lost.Then either there is a bug in your JVM, or at least two versions of the class have been loaded, and at least one of those was not loaded by the system classloader. Without further info, we aren't going to be able to help much more here.
    The class is accessed only
    through its static interface. It seems that since no
    local reference to objects of this class are held in
    memory then the entire class, along with its internal
    static state, is cleared from memory (garbage
    collected?).This is not allowed under the JLS if the class was loaded by the system classloader. If it was loaded by another classloader, then it is only allowed if it can be determined that the class will never again be used throughout the entire run of the application. Since you are referencing the class again, this should not be happening.
    How is it possible to ensure that the state of static
    fields within such a class is preserved over time,
    without create instances of the class.From what you have told us so far, it should be. You will probably have to provide some code for us to help you further.

  • How to call static VI reference

    Sir , I have problem to call static VI refernce in my main Program of ODE solver.Give solution to my problem.this is example problem given in labVIEW 8 i.e.,ODE circuit.
    Attachments:
    rlcmain.vi ‏25 KB

    The Help for that function tells you what to do:
    ODE F(X,t) is a strictly typed reference to the VI that
    implements the right-hand side of an ordinary differential equation
    dX/dt=F(X,t). Create this VI by starting from the VI template located in labview\vi.lib\gmath\ode.llb\ODE rhs.vit.
    There are also several examples that ship with LabVIEW showing you how to use ODE Solver.

  • Static member reference

    Hi:
    I have a question regarding how static members are referenced. Here is a simple example.
    public abstract class A {
    public static int a = 1;
    public void printA()
    System.out.println(a);
    public class B extends A {
    public static int a = 2;
    public class C extends B {
    public static int a = 3;
    Now when I do this:
    A x = new A();
    B y = new B();
    x.printA();
    y.printB();
    they all print 1, but I was expecting x.printA() to print 2 as x's a is 2 and y.printA() to print 3 as y's a is 3.
    I have a class structure where each class has some static members, now i am writing methods in each class to access these static members
    repeatedly. They are the same code, just in different classes. I would like to just put these code into a super class so I would not need to
    rewrite the same thing over and over again. Somehow I have not found a way.
    To me, rewriting the same piece of code usually indicates bad programming. But I am not smart enough to figure out a way.
    Is there a way?
    Thanks a lot in advance.
    FTC

    freetochoose wrote:
    my problem is quite practical.
    I have many classes that all have the same kind of static members. For example, each class has a filename and database table name where i save the data.
    so if i have a super class that has a method like
    savetofile() or savetodatabase()
    each subclass will supply the filename and table name.
    but as my example shows
    in the super class method public void savetofile(), filename will only refer to the super class's static member, and will not
    refer to the sub class's static member, filename, which is what i want.Then don't use static members, use instance-variables, or make the superclass abstract and add abstract methods to get the filename / table name, so every subclass needs to implement that method to return the correct name.
    so i have written code and tested out that in a super class, a reference to a static member is only to that class's static member.
    it will not refer to a subclass's static member even when the object is an instance of a subclass.
    in the end, i concocted the method using java reflection, getClass().getField(this, staticMemberName).toString()
    and it works the way i want it. but somehow, it does not seem too elegant in the sense that reflection should be
    used rarely and i am wondering if there is a better way of doing the same thing without reflection.Never use reflection unless you really have to, and you don't.

  • Static Variable References

    Hello,
    I want to create a variable in one class and have other classes alble to share and manipulate this variable without using subclassing. I think that I may be able to do it by declaring a variable static. Will this work, if not how can I accomplish this?
    Thanks in advance for your help!!

    Yes I'm only sychronizing on this variable, each of
    the classes will modify the boolean variable to
    indicate if they are about to execute a critical
    section of code.You are reinventing the wheel. Synchrionization is built into Java. All you have to do it lock on an Object.
    public void example()
       synchronized(this)
          // critical section
          // only one thread can execute this code at a time
    }Using a boolean won't work anyway. If two threads read from this varaible at approximately the same time, they may both think they can enter the critical section. In addition, the threading memory model allows that variable to have multiple copies, one for each thread. There is no guarantee when the copies will be refreshed, if ever.

  • Static variable reference.

    I have written a small synchronized code
    class Foo implements Runnable {
    private byte[] myLock = new byte[0];
    public static void display(Foo f){
         synchronized(f.myLock){
         //Code to lock.
    }My question is:
    If I use synchronized(f.myLock),how can 'f' refer to a non-static variable
    myLock?
    Shouldnt static methods refer only to static variables?
    Am I missing a point?

    f is an instance of Foo, and f.myLock refers to the lock object of that very instance.
    If you just write myLock without specifying the object, it refers to the instance against which the current method is executing. But such an instance does not exist for a static method, so you can not use that "unadorned" myLock in a static method.

  • Static Forward References

    hi everyone
    i have the follwoing program, and the output was:
    sf1: 50
    sf2:30
    my question : why sf2 in particular was 30, i thought that would be 20
    class StaticForwardReferences {
        static {           
            sf1 = 10;
            int b = sf1 = 20;
            int c = StaticForwardReferences.sf1;
        static int sf1 = sf2 = 30; 
        static int sf2;            
        int if1 = 5;                //  Non-static field
        static {             
            int d = 2 * sf1; 
            int e = sf1 = 50;
        public static void main(String[] args) {
            System.out.println("sf1: " + StaticForwardReferences.sf1);
            System.out.println("sf2: " + StaticForwardReferences.sf2);
    }thunx for anyhelp

    but she has a good point.OOp....plz. change (she) to (he), and such this conflict must be no matther, no problem.
    Code should be easy to read. It's not about "who can decipher the
    most complicated code".this code from a java book, not from my head, the author is Khaled Mughal,
    http://www.ii.uib.no/%7Ekhalid/pgjc2e/source.html
    I read the explanation of the author twice, but I don't beleive his thinkness, SO I ASKED.
    thunx for any help, if no help, no problem
    about your question:
    static int sf1 = sf2 = 30; Why should it be 20?because sf1 is modified to 20 in the FIRST static block
    about your commet:
    Sure. Avoid using constructs people, including yourself, are likely to >understand only after an extensive study of the Java Language >Specification. Just because you can do something doesn't mean you >should to do it, especially not if you can hardly understand it yourselfwhat is this? do u have another way to talk?
    I suggest that you learn how to speak instead of how to learn java

  • How do I use a static reference to keep a VI in memory but then call it in parallel?

    Hello all,
    I have a MainVI and I want to call from it a SubVI in parallel so that I can have both windows open and responsive at the same time.  The SubVI may be closed and reopened any number of times, but only one in existance at a time.  I know how to do this using Open VI Reference, providing a relative path to my SubVI, checking its state to see if its already running, and if so bring the window to the front (using Front Panel: Open method with True/Standard inputs), and if not run it using the Invoke:Run method (and optionally opening its front panel programmatically).  This method was working fine.
    Now I have added functional global variables in my SubVI, and I want to keep them in memory inbetween opening the SubVI window.  I can do this by putting a copy of the functional global in my MainVI, even though I don't use it there for anything.  This works fine.
    By accident, I have come across a reference to a Static VI Reference, which sounded like a vast improvement to my methodology, for the following reasons:
    1) Keeps SubVI in memory all the time, eliminating the need to put the functional global in MainVI when it is not used there.
    2) Tells LabVIEW to include SubVI when I build my executable, rather than me having to specifically mark it as Always Include in the build specification.
    3) Eliminates the need to keep the path and SubVI name updated in a string constant in my code, in order to use the Open VI Reference.
    However, trying to implement this solution, I have run into the problem that once you put a strictly-typed static VI reference (strict typing is required to keep it in memory) onto the block diagram, that VI is reserved for execution.  That means I cannot run it using the Invoke:Run method.  I haven't tried just putting it on the diagram directly as a subVI because I need it to run in parallel to the MainVI.  I have searched through these forums extensively, and although there are several references to a static VI reference, none of them say explicitly how to actually run the darn thing!  :-P
    I very much appreciate any insight into my problem.  If I have to go back to the old way it will work fine, but I really like the seeming elegance of this solution.  I hope that it is technically feasible and I'm not misunderstanding something.
    Thank you for your help,
    -Joe
    Solved!
    Go to Solution.

    > If I understand you correctly, they can only really be used for re-entrant VIs. 
    No, a static VI reference can be used anywhere a regular VI reference (property nodes etc.) The reason for the hoop-jumping above is that we are really opening a reference to a CLONE (copy) of the VI identified by the static VI reference.
    > Okay, I tried it, and got the code shown below... Any idea why it isn't working?
    The VI you want to clone can't be on the diagram as a "normal" subVI. When you run your application you should be able to open that VI and see it just sitting there with a run arrow waiting to run. See attached example (LV2009SP1).
    "share clones" vs "preallocate" has to do with whether you want each clone to preserve state (such as in an uninitialized shift register). Generally you use share clones. Occasionally it is useful to have multiple copies on a diagram that each remember some data, like "timestamp of last execution" in a shift register.
    Other VIs in your spawned process don't have to be re-entrant unless they are functions that "wait forever". All the built-in G functions are re-entrant. It's pretty common to use a queue to feed data to a spawned process.
    Spawning a process is more difficult than just running two parallel loops. It's useful because once you've made 1 copy, you can make 50. If you just want to do two things (vs n things) at once, I would just use two loops.
    Attachments:
    SpawnProcess.zip ‏20 KB

  • Open VI reference from a static reference

    Hello guys,
    To open VIs dynamically, instead of hardcoding the VI name in a string constant, I do this as shown below to keep a dependency to my VI, so if someone ever delete the VI from the project, move it, rename it, it will create a broken wire somewhere so we'll be able to fix it faster.
    However, don't you think it's a bit weird to have the reference to the VI already, but we need to open a new reference, is there a way to get rid of the property node to get the VI path? Is the static VI reference should be closed after the other reference is opened?
    Would it make sense to be able to right clic the static reference and specify the option to open a call and forget reference?
    Is there a better practice?
    Cheers,
    Solved!
    Go to Solution.

    From the LabVIEW help:
    vi path accepts a string containing the name of the VI that you want to reference or a path to the VI that you want to reference. If you wire a name string, the string must match the full delimited name of a VI in memory on that target. If you wire a path, LabVIEW searches for a VI in memory that you previously loaded from that path on the same target. If a matching VI is not found in memory, LabVIEW then tries to load the VI from that file on disk. An error occurs if LabVIEW cannot find the file or if the file conflicts with another VI in memory.
    So, basically, if you use the string, you load the VI in memory and get an error if not found.  If you use path, it will still use the VI in memory at that path, or attempt to load it.  In your case, it won't make much difference.  I typically use VI Name myself since I know it is in memory.

Maybe you are looking for