From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-16-2015 10:37 AM
Hi,
I Would like created a subVI with FGV of my code in labview but I cant see how to make the local variables to put them in subVI.
Someone could show me an example with local variables in fgv pls?
Best regards
07-16-2015 10:48 AM
@eecharlesbr wrote:
I Would like created a subVI with FGV of my code in labview but I cant see how to make the local variables to put them in subVI.
Someone could show me an example with local variables in fgv pls?
Charles,
I cannot figure out what you want to do. You talk about an FGV, which (to me) is a Functional Global Variable, a type of sub-VI with a Shift Register that "holds" one or more pieces of information for a particular purpose, and usually has an auxilliary input that indicates what the user wants to do with these held data (sometimes it is a simple Boolean, Get/Set, but it can also take other forms such an an Enum of "Actions", in which case this is sometimes called an Action Engine).
Your code shows some VISA operations -- is that where you want the FGV? Explain a bit more what you are trying to accomplish and we'll have a better idea of what to suggest.
Bob Schor
07-16-2015 02:52 PM - edited 07-16-2015 02:52 PM
Hi eecharlesbr,
A functional global variable does not use local variables, but stores the data in the shift register of a while loop. The key is to not initialize the shift register, and to only run the while loop once each time it is called (wire a "true" to the stop). Here is an example that uses an enum to decide what to do with the data. You often want to run the "init" mode before using the variable so you know what is in it. Then you can read, write, or do any action you'd like (in this case, multiply by 5). They can be very useful, but they can still lead to race conditions like a global variable, so be careful and intentional with your usage. Drag the snippet into LabVIEW to see an example.
07-17-2015 02:58 AM
Hi Bob Schor,
I have a Giant code to compress and this part could well be compressed with an icon. To do this, I thought I'd create a subVI with fgv to call the local variables that are present in this code. For you, this would be a good solution? Do you have any example?
Thank you
Charles Pereira
07-17-2015 10:13 AM
Charles Pereira,
No. For one thing you cannot move the local variables to a subVI. Local variables are not local variables in the sense that term is used in text-based programming languages. In LabVIEW a local variable is essentially a remote access point for the terminal of an indicator or control. The wire is the actual variable. The scope of a local variable is the VI in which the control or indicator is found.
In looking at your lab.vi I see that most of the reason for the large size of the diagram is that some of the control terminals are located far from the code. Moving them closer would make the diagram almost readable.
Further, none of the local variables is even required. Except for the "Control active at this panel" boolean, each is read at only one location. Just remove the local and wire the terminal. The "Control active at this panel" boolean indicator local is read at two places, but nothing is ever written to it. So it could be replaced by a constant.
With those changes and removal of some empty space the block diagram fits on one screen.
Lynn
07-17-2015 10:16 AM
Hi Charles,
You should absolutely use SubVIs to layout your code in an easier to read style. If your SubVI has so many outputs that you are finding you need to store them into global variables, then you are probably putting too much into the SubVI. Alternatively, if all the information truly does belong together, you can put them into a cluster so that you only have one output, and avoid the use of a lot of globals.
07-20-2015 04:59 AM - edited 07-20-2015 05:03 AM
Lynn and Gregoryi,
Thank you for yours answers.
but my question was not well reformulated, because i have a giant code to compress and these locals variables corresponds to the terminal in the same code.
The first VI that I have sent is a small piece of code that I want to turn into a icon.
I'll send the complete code.
CPA
07-20-2015 06:26 AM - edited 07-20-2015 06:36 AM
crazy... 🙂
This VI is a complete nightmare! Lots of local variables and possible race conditions...
This was written by someone who has no idea how to program in LV in a proper way.
In such a case, I would try to create a flowchart with the required functionality. After that, you can choose an appropriate framework to go with it. Some variation of a state machine for sure (producer consumer, etc...).
edit: as I see you have three options now:
07-20-2015 06:40 AM
That VI really is something. How are you doing on LV Skills yourself? If you're new to LabVIEW I would highly suggest investing at least some time into the free courses and maybe even some money into a LabVIEW course.
Here's a short list of the stuff available:
3 Hour Introduction
6 Hour Introduction
LabVEW Basics
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Learning NI
Getting Started with NI Products
There you will learn many concepts of which I believe, FGVs, State Machine and Queue Driven State Machine (QDSM) should be particularly useful for you.
07-20-2015 09:53 AM
Blokk and PeterFoerters,
Yes, I agree with you that this code is very poorly structured however was a company that made the code. So I'm trying to compress the code to be easier to read and I would like know what is the best way to do this. With fgv?
CPA