LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When to make a sub-Vi

I've reciently been trying to improve my LabVIEW ability and use good more advanced practices like those mentioned here:

http://www.ni.com/newsletter/51735/en/

 

My main questions involves sub-Vi's. I understand that they're great and need to be used much more than I am currently, however I was wondering if there are any good litmus tests regarding:

 

1) an "off the bat," (before you start programming at all) understanding as to if a peticular section of code warrents making a sub-vi

 

2) The best way to recognize that existing section of code should be made into a sub-vi.

0 Kudos
Message 1 of 6
(5,154 Views)

If either of these 2 things apply, in my opinion, you are definitely talking subVI.

 

1.  There is a distinct set of calculations that belong together.  You know you have well defined inpus and outputs to those calculations.  Particularly if once you group those operations together into a subVI, you can test it and trust it to be correct and then treat that section of code as a "black box" in the next higher level VI

2.  Anytime you need to do something more than once.  You create a subVI, you don't want to duplicate code.

0 Kudos
Message 2 of 6
(5,146 Views)

If you plan to use a section a code in multiple places or in multiple projects then it certainly deserves a SubVI. Some very experienced LabVIEW developers will even make a SubVI just to hold a constant. That way, if you decide to change it (for instance, the version number) it will be changed everywhere it is used.

 

It can also be very useful to make SubVIs for cleaning up a top level diagram. For instance, you might have a piece of code that checks for errors after each time a loop runs. If there is an error, it might write something to a file or create a pop up or just enqueue an error handling state. This could take up a significant amount of space on the top level VI, so you can put it in a SubVI to keep it 32x32 pixels. This second usage is definitely more subjective.

 

Once you get into some more advanced projects you might have publicly scoped (can be called from anywhere) and privately scoped (can only be called from other VIs in the same library) VIs. So even if there is a very simple action, like enqueueing an element, you might only want that to be available privately, so you can make a SubVI for it. 

0 Kudos
Message 3 of 6
(5,142 Views)

In addition to what was mentioned above, if your effort is very requiremetns driven, you might consider making a subVI for each major paragraph as well.  It makes the job a lot simpler for a validation engineer if you could list a subVI as the place where a certain requirement is fulfilled.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 6
(5,102 Views)

The above points are all pretty good.

 

However, one way I often decide to make a SubVI is if my block diagram can't fit on the screen all at once.  I define "screen" as roughly 1600x900 pixels, since most monitors in my company are 1920x1080 or 1920x1200, and I want to allow buffer space for an open project file, the taskbar, etc.

 

Sometimes I can see easy ways to move things in closer to fit it all on the screen, and sometimes (especially on my "main" VI or on pop-up user interface VIs) there's just too many items that can't be made cleanly into SubVIs (Event structures, controls/indicators, references, linked property nodes, etc).  So it's not a 100% thing.  But it's a guideline.  

0 Kudos
Message 5 of 6
(5,074 Views)

@Kyle97330 wrote:

The above points are all pretty good.

 

However, one way I often decide to make a SubVI is if my block diagram can't fit on the screen all at once.  I define "screen" as roughly 1600x900 pixels, since most monitors in my company are 1920x1080 or 1920x1200, and I want to allow buffer space for an open project file, the taskbar, etc.

 

Sometimes I can see easy ways to move things in closer to fit it all on the screen, and sometimes (especially on my "main" VI or on pop-up user interface VIs) there's just too many items that can't be made cleanly into SubVIs (Event structures, controls/indicators, references, linked property nodes, etc).  So it's not a 100% thing.  But it's a guideline.  


I think this was kind of covered in a previous post, but you've graphically illustrated a common problem.  That's the beuaty of "Create SubVI from Selection" - although how pleasant the experience is depends upon which version of LabVIEW you are running.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(5,071 Views)