LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need advice on creating SubVIs

Hi all,

 

My code is getting bulky and I have created SubVIs to handle certain tasks. Here is what the code does: take in multiple data file paths from the user, and generate

data summary tables, and lots of plots (table and plot formats controlled by property nodes) and place objects (tables and formats) on different tabs of a control tab on the FP.

 

Here is what I need help with:

 

1. Is it a good idea to feed file paths to inputs of a SubVI? The code reads 2D numeric data from data files using Read from Spreadsheet File.vi.

2. Should I make the input of my SubVI the actual 2D data input instead of file path?

3. Does it make sense to have graphs, charts, etc. in a SubVI? This is how I have them right now (also feeding references to these plots into the SubVI), but someone suggested that I shouldn't do that.

 

For my plots, the legend, X-axis label, and Y-axis lable are read automatically from the file name and updated through property nodes, which is why my SubVI takes in file paths.

Does it make sense to generate a cluster of properties and feed that into my SubVI?

 

Any other thoughts?

 

 

0 Kudos
Message 1 of 11
(2,581 Views)

You should graph data within the main VI, plotting it in a subvi which isn't shown is wasteful.  Unless of course you are planning to show the front panels of the subVI (which I doubt since you have so many).

 

Generally, code which is used repeatedly should be converted into subVI, such as data processing or hardware communication, to save the most space.

 

Is the data from each file represented by the same number & type of objects? (1 graph & table per file??)

If so, you could do the following.  Place the paths into an array, and make an array of references (graphs and tables).  Use a for loop, auto-indexing the path, and feed it into your read file subvi, which will output the data and necessary strings (for labels).  Use property nodes and the associated object references to update the indicators.  In this manner, a for loop and 1 subvi can be used to process all of the identical files (which have the same displays).

 

If you treat each file differently, then turning segments into subVI may help clean up the block diagram but little else as you will still need 1 for each unique file format

0 Kudos
Message 2 of 11
(2,565 Views)

You can pick up an old version (that references LabVIEW 8.x or newer) of Peter Blume's LabVIEW Style guides for a few bucks on ebay.  It has some pretty good "best practices" advice.  I am recommending older versions because they cost less, and basic LabVIEW good coding hasn't really changed in forever.  😉

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 3 of 11
(2,561 Views)

Thanks pjr1121.

 

Currently, my SubVIs do take an array of file paths and inside the SubVI I am using a for loop to auto index this array of file paths.

 

"Use property nodes and the associated object references to update the indicators"  - should this be done inside the SubVI or in the main VI?

 

 

0 Kudos
Message 4 of 11
(2,537 Views)

@murchak wrote:

Thanks pjr1121.

 

Currently, my SubVIs do take an array of file paths and inside the SubVI I am using a for loop to auto index this array of file paths.

 

"Use property nodes and the associated object references to update the indicators"  - should this be done inside the SubVI or in the main VI?

 

 


The idea there is that you are doing the same updates to different graphs.  So if you make a subVI which you pass in the graph reference, you then can reuse that subVI to update any graph.

 

When dealing with subVIs, think "specific function" and "reuse" as main priorities.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 11
(2,521 Views)

@murchak wrote:

Hi all,

 

My code is getting bulky and I have created SubVIs to handle certain tasks. Here is what the code does: take in multiple data file paths from the user, and generate

data summary tables, and lots of plots (table and plot formats controlled by property nodes) and place objects (tables and formats) on different tabs of a control tab on the FP.

 

Here is what I need help with:

 

1. Is it a good idea to feed file paths to inputs of a SubVI? The code reads 2D numeric data from data files using Read from Spreadsheet File.vi.

Sure, i do that all the time.

 

2. Should I make the input of my SubVI the actual 2D data input instead of file path?

Why not, make a 2nd sub-vi which uses the data inputs inside the #1 subvi.

 

3. Does it make sense to have graphs, charts, etc. in a SubVI? This is how I have them right now (also feeding references to these plots into the SubVI), but someone suggested that I shouldn't do that.

This is 2 different issues. Having graphs inside a sub-vi is ok for debugging purposes, if never shown they should have no effect later on. Feeding references is a way to update graphs in another VI (presumably main), but i'd recommend returning the data array to main and simply feed the graph there instead.

 

For my plots, the legend, X-axis label, and Y-axis lable are read automatically from the file name and updated through property nodes, which is why my SubVI takes in file paths.

Does it make sense to generate a cluster of properties and feed that into my SubVI?

3 string inputs are fine. You'll also need the graph ref. I'd make a state or event in the main of it instead.

 

Any other thoughts?

 

 


/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 11
(2,511 Views)

The question is when an object (in my case an XYGraph) is placed outside of the subVI, does it even make sense to place the property node of this object

inside of the subVI? I think not. 

In my picture below, I am calling the subVI 3 times to generate 3 XYGraphs. Then in the main VI, I have created 3 references to these three XYGraphs

and update the properties of each XYGraph with outputs from the subVI. Is this the correct approach?

 

 

subvi.jpg

0 Kudos
Message 7 of 11
(2,497 Views)

@murchak wrote:

The question is when an object (in my case an XYGraph) is placed outside of the subVI, does it even make sense to place the property node of this object

inside of the subVI? I think not. 

In my picture below, I am calling the subVI 3 times to generate 3 XYGraphs. Then in the main VI, I have created 3 references to these three XYGraphs

and update the properties of each XYGraph with outputs from the subVI. Is this the correct approach?

 

 

subvi.jpg


To be clear, you are just using the sequence structure as a guide to show us how things are flowing like in your other post, and not representative of the actual code?

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 8 of 11
(2,482 Views)

murchak wrote: Is this the correct approach?

Who is to say what is correct?  More efficient?  Easier to read?

 

Personally, since you are setting the same properties for each graph, I would make a subVI that you pass the graph reference to.  Inside of that subVI you generate the data and set its properties.  Then you can use that subVI in a FOR loop.  Much easier to understand what is happening and you don't have duplicate code running around.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 11
(2,477 Views)

Yes billko.

 

But is there anything wrong with placing the graphs in an earlier frame, and update the properties in a later frame? Wouldn't that guarantee that the curves 

have been plotted before the properties are set? Otherwise, wouldn't you get that 1077 error code, where the property node is attempting to set certain

properties for curves that haven't been drawn yet? 

0 Kudos
Message 10 of 11
(2,476 Views)