Storing DAQmx Task in a Functional Global variable

Happy New Year to everyone!
I got a nice little question hoping some of you might be able to help me....
After initializing an starting a DAQmx task (V7.5), I wanted to store the task out reference in a functional global variable, but it seems, it didn't work.
Everytime I tried to call a DAQmx VI with the opened reference, I get an error, the task would not be existing....
I already made a workaround, so everything works fine. I'm just curious what I made wrong....
Thanks in advance!
Cheers
Oli
Programming languages don't create bad code, programmers create bad code....

Helo Oli,
Normally, you should not have a problem storing a task reference in a variable. However, the vi that created the task has to stay in memory for it to work. Closing the vi will result in the destruction of all created hadles -
that is why your reference might be regarded invalid if you use it in
another vi.
That is why I can just assume that you are closing the VI that created the task before you are using the handle somewhere else. You can use variables to store the task ID, but as a workaround you have to keep the vi which reated the reference running.
Hope this explains the behaviour.
Regards
Ingo Schumacher
Systems Engineer Sound&VibrationNational Instruments Germany

Similar Messages

  • Using functional global variables to transfer data between touch screen device and other targets

    Hi,
    We are currently developing a control system that will operate on a cRIO with a touch screen interface. During development we have been using functional global variables (FGVs) to handle most of the settings/data etc, however we have just realised that we may have an issue updating the data on the touch screen, and vice versa.
    Previously we have implemented similar programs using shared variables, however we were wondering if there is anyway to implement FGVs in a similar manner, whether it'd be a combination of FGVs and shared variables.
    Regards,
    Mike
    Software version: Labview 8.2.1

    See this thread on LAVA about sharing FGV's across projects. THis should be extendable to cross paltforms (I believe).
    You also may want to concider an upgrade to LV 8.5.1. We have found a number of performance related issues with LV 8.2.1 and RT.
    If you decide not to upgrade, just remeber what I wrote (above) when you have reason to question the performance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Functional Global Variable in the CLAD sample Exam

    Hello,
    A question in the CLAD sample exam #2 keeps puzzling me. It's question number 32 about FGVs:
    32. Which is not an important part of creating a Functional Global Variable?
    a. Using Shift Registers to store information
    b. Changing the VI’s execution settings to Reentrant
    c. Setting the VI to inline into calling VIs
    d. Setting the While Loop to stop after one iteration
    The answer given is the following
    32.Correct Answer: B
    Topic: Functional Global Variables
    Justification: It is not necessary to inline functional global variables into their calling VIs. In fact, inlining requires that the subVI be reentrant, which is forbidden for functional global variables.
    Clearly, for an FGV to work properly, the VI must NOT be reentrant. So I would have selected answer B, but the justification seems to clearly point to answer C as well, doesn't it? Is it a typo, a subtlety in the wording? I am stuck on this one!
    Solved!
    Go to Solution.

    Well, inlining requires reentrant.  Therefore, the best answer should technically be C.  This looks like one of those rejected/retired questions since it isn't quite right and/or left up to too much interpretation.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Functional Global Variable on Hold

    Hello everyone,
    I understood, by reading threads on the forum, that a call to a Functional Global Variable will block its execution if the FGV is already being accessed by another VI, correct? Is there any other way it would block, apart from the stated?
    The motive of the question is that I have one FGV (non-reentrant) that is read by 8 subVIs concurrently (they are, actualy, the same vi, but configured to reentrant) and whose access time varies, strangely, based on the number of subvis running.
    When less than 5 VIs are trying to access the FGV, the execution is blocked (I assumed it, because when the FGV is disabled and replaced by a constant there is no problem with the execution) and the access lasts at least 50 ms; if this number is between 5 and 8, the execution is done much faster. My first guess was that the FGV hasn't been initialized until the fifth subVi is called, but I don't know how to check that.
    I can figure that there is something wrong with the FGV, but can't put my finger on it. Any ideas?
    Thank you in advance for any help.
    Solved!
    Go to Solution.

    Thank you for your response, Ben
    I'll try to explaing the problem better with the images that follow.
    I have 8 concurrent instances of the "bitDefiner.vi" - shown below - in the program.
    It reads from the AE (a simple read-write one) and it's the only one to call it besides the writer (that generates the appropriate signal), gets the rising edge of a waveform and determines how long it takes until the falling edge, giving a category to this time later on. If it doesn't determine the period between rising and falling edge before the timeout runs out, it aborts the execution of the while loop. This VI execution is setup like this:
    That being said, let's go to the problem.
    Assuming there is nothing using the AE but one instance of the bitDefiner, it won't get the rising edge, due to the fact the signal is not being generated, resulting in a timeout. The return value on the diff indicator should be next to the one defined to timeout(image below)
    However, when the subvi concludes its execution, the diff indicator shows 54ms intead of 15ms; so I concluded that the AE is taking to long to process the call. Besides that, I'm quite positive that there is only one thread accessing the AE.
    After this result, I ran the other instances of the bitDefiner and after the 5th one got activated, the diff went to the expected 15 ms (I'm still thinking how to show that on picture).
    I tried highlighting the execution, but it didn't show me anything unsual. The call chain just present that the caller is the bitdefiner VI as expected.
    Any thoughts on that?

  • Functional global variable question

    Hello,
    I fully understand how a functional global variable (FGV) works and its purpose but I have one last question.
    How do I guarantee (or how is it guaranteed) that my sub-VI (the FGV one) is not re-entrant, in other words, how am I sure that when an instance of the FGV is running it does not loose the processor to others?  Is this an option that I can choose in a sub-VI or is it related to the while loop or case strucure that compose a FGV?
    Joao

    Hi Joao,
    For a little more background on configuring reentrancy and the options you have available if you do want to make a subVI reentrant:
    LabVIEW Help: Reentrancy: Allowing Simultaneous Calls to the Same SubVI
    http://zone.ni.com/reference/en-XX/help/371361K-01/lvconcepts/reentrancy/
    As Lynn said, all new SubVIs will be non-reentrant by default.
    Regards,
    Tom L.

  • Functional global variable

    I would like to ask to the experts a question about functional global variables. 
    In the labview basics 2 course was said that a functional global variable is not reentrant. 
    My purpose is to implement a code in such a way.2 main vi's. The first vi deals with some hardware that writes data in an output file with 1 Hz rate (more or less 1Hz, I cannot decide it).
    The second vi deals with a different hardware (thermocouples). This works at a different rate (I cannot match exactly the different rates). I would like to write the data from the second hardware in the same output file of the first vi. 
    I am thinking to use a functional global variable to pass the information from the second vi to the first vi. In this way I am using the data from the thermocouples at a rate given by the first vi. But at the same time in the global variable the data are written at a rate given by the second vi.
    My question is: what exactly happens if the subvi (functional global variable) is called exactly at the same time? As you can understand it's not really important if I read the temperature with an error of 1 second, but I would not like the execution would stop or something like that. 
    A functional global variable is a subVI that is not reentrant. This means that when
    the subVI is called from multiple locations, the same copy of the subVI is used.
    Therefore, only one call to the subVI can occur at a time.functional global variable is a subVI that is not reentrant. This means that whenthe subVI is called from multiple locations, the same copy of the subVI is used.Therefore, only one call to the subVI can occur at a time.

    A couple of quick comments to add to this thread.
    FG's can be involved in Race Conditions if two callers attempt to direct set the same value. An Action Engine (well what do you expect?) can be coded to help with those situations.
    Example:
    In arecent app I needed to set the heaters to "0" if an over-pressure condition was detected. The Heater set points where driven by a PID. The safety conditions where controlled by a process monitoring the input values.
    So how do I keep the PID from setting the heater when the rig is not safe?
    A Safety AE !
    Actions used by the pressure monitoring set the Safety AE in an "go-safe" state where setting the heaters results in a null op.
    This particular pattern (two writters) screams for an AE to coordinate the vaious actions. Do this same thing with queues could get tricky.
    So for the Q in this thread we have a pattern of "two source of info, one sink for each" that screams for a queue.
    BTW:
    The AE Nugget linked above addresses what happens when two callers attempt to call the same non-re-entrant sub-VI.
    Have fun,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Function global variable(FGV) template

    Hi All 
    if NI adds the Fuctional Global Variable (FGV) tempalte in design pateren tempates in hte New window, it is easy to create FGV VI's.
    and Helps the programmers, no need to create from the begining of VI.
    Even it is usefull for CLD Exam also.

    Something like this? Note that I would use the term "Action Engine" instead of "Functional Global Variable" specifically to discourage the use of this template as a global variable and instead emphasize its role as an action performer on centralized data (as noted in the comments).

  • RT executable causes functional global variable VIs to become non-reentrant

    Hi,
    I am having a small issue with functional global variables (Repositories). The attached VI is a sample functional global variable I created that stores double precision numeric values. The VI properties are set to normal execution. I use this VI to pass data between loops running in real time on a PXI platform. When running my application from the project explorer (not creating executable) the VI functions as it should and passes data between my loops with no issues. But when I create a real time executable of my application and run it on the PXI, it does not share data between instances of the VI. My work around this issue is to change the VI properties execution priority to Subroutine but it forces me to modify my VI slightly for this to work (I have to remove the property node). I am not sure why this is happing. I have seen some applications with this VI that appear to function normally in development and in executable with the VI properties execution priority set to Normal. Any comments or suggestions are welcomed.
    I am running LabVIEW 2009, PXI-8186, and Windows XP
    Thanks
    Attachments:
    RT Repository DBL Numeric Command Ver 2.ctl ‏5 KB
    RT Repository DBL Numeric Element Ver 2.ctl ‏5 KB
    RT Repository DBL Numeric Ver 2.vi ‏25 KB

    Many properties require the front panel to be loaded in memory; the property you're using, NumItems, appears to be one of them (look at the help, you'll see that it says "Loads the front panel into memory.")  However, VIs running in an executable on RT do not have front panels, so those property nodes will not work.  If you were to log the error out terminal from the property node in your executable, you should see that an error occurs.  As a result, you're getting a 0 value out of the property node, causing your VI to output unexpected results.
    My recommendation is that you replace the property node with the function GetNumericInfo found in vi.lib\utility\VariantDataType.  It has an output called EnumNames.  Take the size of the EnumNames array and use that in place of the output from the property node.  This will work on RT.
    Note that this has nothing to do with re-entrancy, and the key hint is that the VI works when you remove the property node.

  • Would you Open and Close DAQmx tasks within a function or Globally

    Hi Guys,
    This should start something.
    The subject is DAQmx Tasks.
    If you were writing a function that is called many times, say MeasureVolts (double *Value) to obtain a reading from an Analogue Input Channel.
    Would you.
    1. open and start the task inside the function, do the measurement and then close the task inside the same function.
    or
    2. open the task globally and later do the measurement inside the function using the global task then close the task only when the application is closed.
    I am mostly concerned with the overhead of task generation and closing, what do you guys and girls out there do?? and what is the general opinion?
    I would appreciate your views.
    Regards
    Paul.

    I would definitely NOT keep configuring and clearing (I think that's what you mean by open and close) the same task over and over.  I would configure once, read many times in my main app, then stop & clear once.
    I typically like to package such data acq into an "Action Engine" that keeps track of its own DAQmx task id so I don't need to sling that task id wire around into multiple parallel loops / vi's.  Attached is a very stripped-down example for Digital Input. 
    I would typically do more with error testing and would make the "Action" enum into a typedef custom control, but this gives you the basic idea.  The action engine approach works very nicely when there's a small # of different kinds of input parameters and output info needed to support all the necessary action cases.   When you start needing a large number of differnent kinds of inputs and outputs to support the desired actions, then you start having difficulty with (1) having enough terminals to wire and (2) remembering which inputs and outputs are meaningful for which actions.
    -Kevin P.
    Attachments:
    DI Action Engine.vi ‏75 KB

  • Dynamic call of a vi with a reference stored in a global variable

    Hello,
    I am trying to program a VI which calls DAQmx functions in some cases, in other cases DAQmx may not even be installed. To prevent a broken arrow on machines where DAQmx is not installed, I want to use a sub-VI containing the DAQmx function calls which is called dynamically by a main VI. For speed I want to prevent continuous opening and closing the VI reference, so I want to store the reference to the sub VI in a global variable. In this variable I also want to store the Analog Input Task. I want to use an initialization VI to write the VI reference of the sub VI and to configure and start the Analog Input Task and write the Task ID to that Global, too. In that way I was hoping to be able to improve the performance of the dynamic calls and the Task calls. BUT - when I write the refererence and task to the Global and read it out from another VI, the reference is not valid anymore and the Analog Input task is also not valid, even if both the initialization VI and the Global are still open (but not running). Does somebody have an idea how to solve that? It is a bit difficult to describe, so here is what I want to do in a shorter description :
    - run a initialization VI which
      defines a reference to a sub VI which will be called dynamically later on
      and a AI task ID definining a DAQmx physical channel configuration to use for subsequent read cycles
      and writes both (VI reference and AI task) to a global variable
    - run another VI which
      reads the VI reference of the VI to call dynamically from that global
      runs the corresponding VI dynamically
      the dynamically called VI performs an AI task corresponding to the DAQmx task ID read from that global (it reads an analog value for instance from the  
      physical channel configured by that AI task) 
    Why all that? To prevent creating and destroying the VI reference for each call of the sub VI for speed. And to use the configured DAQmx channel for subsequent read tasks only if the subVI is called dynamically - if it is not, then the application will not see the DAQmx calls and therefore no broken arrow will occur if no DAQmx is installed on the machine.
    Can somebody help me with this? Why can't I store and read out the reference to the sub VI to/from a global, and why is the AI task not valid when read out from the dynamically called sub VI? I am somewhat lost with all that...
    Thanks in advance,
    Gabs

    Uh - I am almost getting crazy with that
    Kevin, that solution is the right one for programming an application. In that case everything will work fine. But during testing, it is more convenient to call all VIs from their front panels one after another. That's how I'm doing it for everything that needs to be exchanged between such VIs: store them either in a global or in a functional global variable. In that way the user can "play around" with the VIs without wiring them together in a main VI. Therefore, after some thinking I liked Davids idea with that daemon VI (I solved that by adding a boolean in the initialization VI to choose if that daemon is necessary - during testing phase - or not - when using the VIs in a main application). BUT:
    David: It does not work!!! I have exactly done what you proposed and this daemon VI is really running, having a True/False frame with a constant of False wired to the selector and holding both the functional global and the dynamically to call VI in the True frame. In that way, after initialization is finished, both VIs are still running but idle. Anyway, when I read back the value of the reference or the DAQmx task, it is invalid again!
    That really costs just too much time. Does anybody have any idea what to do now? David, I was hoping that your suggestion would solve the problem, because it would be logical that it would - why then is LabVIEW destroying the reference and task anyway even if that daemon VI containing the functional global is still running???
    Regards,
    Gabs

  • How can I run two different vi's in same project which are accessing same global variable with out effecting the speed of the execution of both the vi's

    Hi
    I have build an Labview project with FPGA target .  I have configured an FPGA VI and an host Vi to acquire data and logged the data to a file and stored the latest data in a global variable simultanously. I have configured one more VI in the same project  to access the global variable.  I have build a dll to access both the VI as functions in LabWindows/CVI code.  My task in CVI is to update configured GUI with latest data periodically and run the  host VI continously for a long time and log the data to a file. GUI should update for every one second with latest data for this I am using the second VI in which I am accessing the global varibale in which the latest data has been stored in host VI.

    Duplicate Post (go here)

  • Software timing - Functional Global?

    I was reading NI Intermediate manual to prepare for the CLD exam, and noticed that they used Functional global variable in combination with timed loop for the software timing. Also, the error handling was implemented using functional global.
    However, I was reading in one post( not this forum) that the functional global is obsolete, can anyone shed any light on this issue, why would the functional global be obsolete: and if it is, what are acceptable design for software timing.
    Thank you.

    Cory K wrote:
    I dont see why a global would be obsolete.
    There are some instances when using a global variable is the best option, especially in cases when a resource will be used on several different computers.
    A functional global variable isn't the same thing as a global variable. A functional global variable is what was used before global variables were introduced in LabVIEW 3. It is the heart of an Action Engine.
    As for their obsolesence... Hah! That's all I have to say on that.
    As to the original post:  I'm a tad suspicious. What kind of software timing and error handling is being done with a functional global variable? Can you post the code?

  • Functional global set as reentrant vi in CLD sample?

    In the CLD atm sample question attached. It set its functional global as a reentrant vi...
    Now let me get this right , a non reentrant vi, no matter how many times it's called, stores its data into one location. So a functional global should be a nonreentrant vi so the functional global can SET the same data in the same place, and GET the same data in the same place.
    Whereas a nonreentrant vi creates clones everytime it is called, and each clone stores a different set of data in a different place. So a functional global should not be a reentrant vi because it cannot retrieve the same copy of data; there are many different data sets stored in different places, the functional global would not know which data set to retrieve.
    But how come this CLD sample set its functional global as reentrant vi and it works???
    Attachments:
    ATM Simulator LV86.zip ‏116 KB

    richjoh wrote:
    In your VI code "Shared clone is selected"
    Below are past from the LV manual --
    "Memory Usage - Only allocates clone VIs for the maximum number of simultaneous calls to the reentrant VI. Decreases memory usage..."
    "Execution Speed - Creates clone VIs on demand. Slightly decreases execution speed and speed may vary per call.."
    ...and Preallocate is versa of above.
    Yes the only reason to use Reentrant in any LV example is to keep separate copies in memory. This author uses the reentrant VI to track 3 different transaction in his example (looks like an banking ATM, I have not run it as yet). The author reentrant is for "deposit", "withdrawal" and "pin entry". Ctrl+F, the VI is used in 4 instances, one of them is to Get current action, the other 3 are Set.
    IMHO, the example is overblown. Wonder how long it took the author to create it?
    The reason it works is all access is sequential.
    Overblown, yes. Reminds of the kid trying to show-off by climbing over the fence to pose next to the lion's cage. It will bite them eventually.
    Keep It Simple Sir has clearly bee violated.
    I will watch for someone who can explain WHY that was a good decision unless they felt there would 500 of these ATM GUIs running in parallel.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Duplicate sub vi with the same global variable

    This is a simple question, that probably was answered before:
    I had a sub vi that uses a global variable. Now I need two of these sub vi's working simultaneously in a while loop. The problem is that they are both adressing the same global variable, but I need them to be isolated. How do I do that?
    Thank you.

    Hi Ivan,
    This Developer Zone article explains a little more background about why functional global variables are the best option for you. Happy coding!
    Amanda Howard
    Americas Services and Support Recruiting Manager
    National Instruments

  • Problems with global variable!!

    Hi!
    I am using some cluster (global variable), and certain fields in the cluster don't be updated.I can't understand where is the problem, because some fields are updated correctly and others no!!
    Any idea?
    Thanks in advanced!!
    Graci

    A functional global acts as a global variable in that it allows LV applications to access the data from different parts of the vi or from different vis for as long a LV is running. The vi is set to not be reentrant so that race conditions are avoided. Since functional globals are subvis that you write you also have the ability to store many global variables which are dependent upon only one input by performing the calculations within the functional global vi. You can certainly achieve this by using semaphores, but with functional globals this synchronization is built in.
    In the functional global vi you have a while loop which is set to stop after 1 iteration. This while loop has a shift register which holds the global data. There is a cas
    e structure to determine whether to read or write the functional global variable. In the write case the data from the input is written to the shift register on the right side. In the read case the data from the left shift register is written to the output and also passed on through to the right shift register. A good example can be found at the following link.
    http://sine.ni.com/apps/we/niepd_web_display.DISPLAY_EPD4?p_guid=B45EACE3DB4956A4E034080020E74861&p_node=174821&p_submitted=N&p_rank=&p_answer=&p_source=External

Maybe you are looking for