07-21-2014 02:22 PM
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?
07-21-2014 02:38 PM
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
07-21-2014 02:44 PM
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. 😉
07-21-2014 03:04 PM
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?
07-21-2014 04:19 PM
@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.
07-21-2014 04:36 PM
@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
07-21-2014 04:55 PM
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?
07-21-2014 05:08 PM
@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?
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?
07-21-2014 05:12 PM
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.
07-21-2014 05:13 PM
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?