06-05-2013 12:56 PM - edited 06-05-2013 01:08 PM
I am writing a rather large program and my current goal is to make it all fit on my screen at once. I have been breaking parts of my code into Sub-Vi's: One sub vi sets up all the lab equipment, one gathers the data from the lab equipment, one returns all the equipment to local mode, etc. This is working fine, but these sub-vi's are very specific to this program.
My worry is that in the future, as I write more similar programs that would benefit from these same reductions, that I will have a laundry list of similar sub vi's all created for specific purposes within each program.
So Gather Data 1 communicates with the DMM and the Scope, while Gather Data 2 communicates with the Scope and a Power Meter.
Is there any way to save a sub-vi locally? In other words, package it into the current VI somehow? That way they aren't saved somewhere else creating copies of themselves in another folder that quickly becomes overgrown and impossible to navigate?
I am thinking in terms of how powerpoint, for example, handles pictures and video. You can have it save the locations of these objects BUT you can also package them into the powerpoint. Powerpoint saves the images on the slides themselves and no longer needs to reference them from another location. For powerpoint this isn't necessarily space efficient, but since I have to save the sub-VI somewhere anyway, I would prefer these simplifications to be saved within the current VI for simplicity. Is this possible?
Obviously each VI could be contained in its own folder that contains a Sub-VI folder. But this still requires each sub-vi to be saved as a seperate file, thus creating clutter.
Just a thought that I know would be useful for me, and possibly others.
06-05-2013 01:11 PM
I don't know anything about putting them directly in your Main VI (doesn't sound like a good idea to me), but you can:
1. Save all the subVIs for a particular experiment in its own folder (or subfolders), and
2. Name your subVIs more specifically, i.e., instead of Gather_Data_1, call it Read_DMM_and_Scope, Gather_Data_2 becomes Read_PowerMeter_and_Scope, and they are both built up from subVIs used for the single instruments. You could expand this to specific conditions of the experiment if you want, such as Scan_UV-Vis_Spectrometer_1_w-o_Background_Subtraction. The names might seem long, but they'll lead you right to what you want.
You're not creating extra copies of the subVIs in other folders, you're pulling them into the mainVI when you load it. If your folders are below your mainVI folder, they will be easy to find.
Cameron
06-05-2013 01:51 PM
For some of the more useful and easily describable vi's I have been giving them more descriptuive and useful names for future use, but as a general rule they are much too compicated and too specific. My current Record Data vi calls 7 or 8 different instrument I/O routines which each have a GPIB constant and 2 or 3 settings that may or may not change. I condensed these 20 or 30 items into one little box. I could call it Read_Current_Voltage_ScopeVoltage_Power_ACAmplitude.vi but I am not likely to use it again in this exact context. The idea is to not have all of these VI's floating around, within a folder with the main VI or not.
06-05-2013 02:56 PM - edited 06-05-2013 02:58 PM
To give a visual example. I have the following VI that changes all the lab equipment to the local state so we don't have to rememeber to switch them over every time we want to use them. A section of my code appears to the left (i deleated some of the repeated GPIB local stuff and reconnected the error terminals).
For this example in particular a universally called VI is fine because the VISA REM/LOC command doesn't care if a certain GPIB address isn't in use, so a general VI with every piece of equipment in my lab would be fine.
Assume this program did something else however. Something that did care what specific equipment was being used. I don't want to save 10 different copies of essentially the same program for each varied use. I want a way to condense a section of repetative code into a VI shaped piece, while still saving the entirety of the code in the main VI.
It is genuinely unhelpful and unreasonable to have a new VI for every combination of lab instruments in use for a given task.
Put simply, the bulk of these types of repetative tasks have forced me to use VI's to clean up my code, but I don't want to clutter up my computer as a result of cleaning up my code.
06-05-2013 03:06 PM
There is no way to save a subVI "locally" within a VI. Each subVI must be it's own separate file. You can facilitate the situation you describe by creating a re-use library that you share across projects. If you watch this on-demand video from a prior Virtual Users Group, it will address the topic and suggest some solutions. The long and the short of it is VI Package Manager (VIPM) from JKI is your friend. The VIPM not only makes you able to manage your own libraries it also gives you access to a vast respository of libraries (some free, some pay) that people and companies have made available.
You can get VIPM community version for free at http://jki.net/vipm. It is definitely worth using.
Wire Warrior
06-05-2013 03:10 PM
A piece of code like the one you posted is a prime candidate for two simple changes to make it much more versatile:
1. Replace the constants with controls. Then you can enter any addresses. See also 2.
2. Use an array of instrument I/O Resouce Name controls and place just one copy of the REM/LOC function inside a for loop.
You might also add some error handling which is matched to the needs of the VI.
06-05-2013 03:54 PM
The idea behind creating a sub-vi containing these rem/loc snippets is to reduce the bulk of my program. Creating controls is counterproductive as it increases the number of items on my FP, which I do not need or want to do. The ability to select the GPIB addresses may be nice, but in such a large program it is a hassle. I want it all to fit on my screen. Coming from a linear text based background I want certain things hard coded into my programs, and certain functions to allow my program to remain manageable.
As far as arrays are concerned: I do not know how to manually create an array of those resource names. Of course I can use the build array vi and drag wires, but that is again, increasing the bulk of my program for no real benefit.
As the number of entries increases building an array out of the I/O names and sending into a for loop may be helpful, but I would still have to save a seperate VI for each combination of entries.
Thank you for the suggestions in general, however. I am a new LabView user and every tip helps.
-Nukem
06-05-2013 09:22 PM
I think you'd be better off creating some text files containing the names of the different combinations you might want to shut down. Then you run the VI, use the file dialog to choose a text file, then read the names in from the text file as an array and loop through that array to close your resources.
@Nukem wrote:
As far as arrays are concerned: I do not know how to manually create an array of those resource names. Of course I can use the build array vi and drag wires, but that is again, increasing the bulk of my program for no real benefit.
You drop an array container on the front panel. You drag and drop the resource name control into that. You can expand the array to show more items at once on screen.
06-06-2013 12:44 PM
RavensFan wrote:
You drop an array container on the front panel. You drag and drop the resource name control into that. You can expand the array to show more items at once on screen.
That is helpful, as is the idea to write the programs in such a way that a simple text file determines the specifics of execution.
Is there a way to similarly combine references into an array? I am passing them through a cluster to send to my sub-VI, but the 10 different references have just become a wild mess on my block diagram. Making them an array or making them a cluster manually instead of with the build cluster command would clean up sections of my code significantly.
My end goal is to disable and gray out all but 3 items from my front panel while my program is collecting data. I can still pause, resume, stop, and change one parameter, but the rest are disabled. So I am left with a slew of references that I pass through a cluster to a loop.
06-06-2013 01:20 PM
You can pass a reference to the main as an input to the subVI. In the subVI use property nodes. The first one will get the Panel property, which is a reference to the front panel of the main VI. Connect that to another property node and select the Controls[ ] property. This produces an array of references of all the front panel controls. You can use the control: label property to determine which reference points to which control. (This requires that each control has a unique name).
Lynn