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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a subVI with fgv

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

 

0 Kudos
Message 1 of 31
(4,502 Views)

@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

0 Kudos
Message 2 of 31
(4,491 Views)

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.

 

FGV_example.png

0 Kudos
Message 3 of 31
(4,434 Views)

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

 

0 Kudos
Message 4 of 31
(4,379 Views)

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

Message 5 of 31
(4,324 Views)

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.

Message 6 of 31
(4,318 Views)

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

0 Kudos
Message 7 of 31
(4,266 Views)

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:

 

  1. You try to work with the recent VI as it is, and try to reduce the size, and eliminate / not create new race conditions / bugs. I would not recommend this way, as you are a beginner in LabVIEW and such an ugly patchworks usually create more problems later even if you save time...
  2. You start to learn LabVIEW to reach a level, where you can safely create a proper state machine with subVIs, and you program a totally new code based on the hardware/software requirements
  3. You hire a company to make the code in LabVIEW

 

 

 

 

Message 8 of 31
(4,238 Views)

That VI really is somethingSmiley Wink. 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.



Remember Cunningham's Law
0 Kudos
Message 9 of 31
(4,212 Views)

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

0 Kudos
Message 10 of 31
(4,173 Views)