Customizing LabVIEW
Customizing LabVIEW
LabVIEW Tools
After using LabVIEW for a good period of time, a developer or organization will accumulate many tools to help them do their work. These tools will include LabVIEW primitive-like VIs; toolkit-like packages of VIs; instrument drivers; VI, control, and software component templates; application architectures; and edit-time development tools. Fortunately LabVIEW provides several mechanisms to tailor the LabVIEW development environment to suit the working needs of the developer. In this article I will examine those mechanisms and explore ways that the developer can use them to customize their work environment. In the conclusion, I will describe a way to propagate those changes onto LabVIEW installations on other machines. Again, the types of tools that a developer or organization will create can typically be divided into the following categories: LabVIEW Primitive-like Functions - These are small reusable VIs that look and feel like the functions in the default palette, which come stock with LabVIEW. Developers who use LabVIEW daily will often find gaps in the functions found in LabVIEWs palettes and need to augment them. LabVIEW Primitive-like Custom Controls - These are custom control, which are similar to those in the default controls palette. They may be buttons with fancy graphics, or things like the clever codeless radio button that appeared in LTR a long while ago. LabVIEW Toolkit-like Packages - These are groups of VIs that collectively achieve some task. An example would be GOOP classes or any of the GOOP-like synchronization tools such as the queue, semaphore, notifier, and rendezvous as well as LabVIEW add-ons like the PID, Fuzzy Logic, or Internet toolkits. VI and Control Templates - In an effort to save time, when design patterns are common to an organization or repeatedly used by individuals, VI and control templates may be used as a starting ground for development. Software Component Templates These are a collection of VIs that work together to achieve some compartmentalized functionality, like a configuration dialog with configuration data file storage and retrieval. It may have one or more VIs, custom control type definitions, and data files that need to be copied to a new location and possibly renamed while preserving the relative linking of the files Application Architectures - These are project templates or recycled projects. To save time one can reuse entire collections of several tools that have been implemented to solve specific large-scale tasks. Examples might be a data logger, test executive, device controller, etc. Instrument Drivers Companies that work with a specific set of instruments and use them in a specialized manor may develop a custom library of instrument drivers that suit their classes of experiments. They may wish to share one collective set of drivers company-wide. Edit-time Development Tools - These are LabVIEW programs that are designed to run while you are developing in LabVIEW. Some of the best examples of these are tools that 1
ship with LabVIEW, for example the VI Library Manager, Web Publishing Tool, and Application Builder. These are all applications written in LabVIEW that are designed to help you when you are building your own LabVIEW application. Most of the edit time tools that an individual or organization might write would be designed to reduce the time spent doing mundane repetitive tasks like renaming groups of VIs with a common prefix, or changing VI properties of groups of VIs at a time. However, they may also be designed to provide information and insight into the development environment itself. For example, an application might list all VIs in memory or all top-level VIs. It might allow you to select a VI in memory and open the VI by selecting it from the list or edit the VIs properties, such as its VI Info Description or Execution options. With the advent of VI server and hence LabVIEWs introspection capabilities, the possibilities are limitless for new developer tools written purely in LabVIEW.
Customization Options
I have defined the types of tools that one may wish to integrate into the LabVIEW development environment, so now an exploration, is necessary, of the options available for bringing them into the work area. LabVIEW provides some out-of-the-box tools for customizing the LabVIEW development environment, but also has some undocumented and under-documented features that the developer can employ as well.
Custom Palettes
Chapter 3, Section 1 of the LabVIEW User Manual (<LV>\manuals\lvuser.pdf) is entitled Customizing the Controls and Functions Palettes. It describes several mechanisms for modifying the LabVIEW Controls and Functions palettes. The simplest way, and the one that most people are familiar with, is to place their reusable VIs and Controls in the <LV>\user.lib or the <LV>\instr.lib directories. When LabVIEW starts up, it looks in these locations and builds subpalettes and icons reflecting the contents of those locations. The <LV>\user.lib contents are reflected in the FunctionsUser Libraries palette and the <LV>\instr.lib contents are reflected in the FunctionsInstrument I/O palette. Another option that you have is to add a toolset, (LLB or directory of VIs) to the <LV>/vi.lib/addons folder. These toolsets will appear as subpalettes at the top-level of the Controls and Functions palettes. Lastly, you can create an entire palette view. A palette view allows you exact control of VI and Control icon locations and subpalette icons, names and locations within your custom palette. This is by far the most powerful of the palette customization options, so I will further describe its features. LabVIEW stores all the palette views in the <LV>\menus folder. The menus folder contains subfolders, each of which corresponds to a palette view. Inside the palette view folders are one or more files. Lets take a good look the contents of a palette view folder. root.mnu - This file defines the top-level Functions and Controls palette contents of the palette view. However, LabVIEW will continue to add the contents of <LV>\vi.lib\addons to every palette views root menu readonly.txt - this file, if present, disables some of the palette editing features. It effectively makes the palette view read-only. This file consists only of a carriage return \r character. *.mnu All the other .mnu files in the palette view folder define the palette views subpalettes. It is worth noting that a .mnu files palette can embed any other .mnu files 2
palette, regardless of location. However, if you plan on distributing your custom palette view, you should ensure that any .mnu files that you created or used as subpalettes are located inside the palette views folder. It is bad practice to link to .mnu files that exist inside of other palette views. This could happen if you tried to insert a submenu from an existing .mnu file and you selected the file manually with the file dialog. You could potentially insert, and therefore edit, a palette that belonged to another palette view. The bottom line is: when you create new submenus, make sure that you save your .mnu files in the palette view directory of the one you are editing and dont insert subpalettes from existing .mnu files in other palette view directories.
Submenus A palette contains links to other palettes within LLBs or .mnu files and their locations on the palette. Synchronize with Directory - This option, if enabled causes the palette to build itself dynamically on startup based on a specified directorys contents. This option may only be set from a parent palette by right clicking on the submenu icon and selecting Synchronize with Directory. When set to TRUE LabVIEW will ask you to define the directory with which to synchronize.
file called dir.mnu inside of the folder you select. This .mnu file will have the setting Synchronize with Directory set to true and the target directory set to the .mnu files parent directory. This effectively allows you to create a folder similar to <LV>\user.lib and <LV>\instr.lib. It will automatically generate icons and submenus based on the folders contents. Inside this folder, you can place LLBs, VIs and other folders containing dir.mnu files.
text file called MyBuggyCode.txt that contains the contents Elegant Solution and placing it in the same directory as MyBuggyCode.vi. Note that this override method works for LLBs, folders, .hlp, and .chm files, but for .hlp and .chm files you must also add the characters .hlp or .chm after the menu item name in the overriding text file. The file MyCHM.chm should have an override text file called MyCHM.txt that contains the contents All The Help You Need.chm This will cause its menu name to be All The Help You Need. How does the developer use this feature, whereby they can open VIs and help files from the menu? VIs placed in the Tools menu (<LV>\project folder) should always be set to Run When Opened. This will cause them to look and feel like a functional dialog or tool once they are opened after being selected from the menu. In the Help menu, .chm and .hlp files are opened just as if they had been double-clicked from a file explorer window. However, the developer may want something fancier. There is a function in the Application ControlHelp palette called Control Online Help. This function may be used to open a help file and have it automatically jump to whichever topic you are interested in by wiring the topic name to the String to search for input. If you have one help file with several topics but want a menu item for each topic, you would want to put a VI inside the <LV>\help folder for each topic and have the VIs call Control Online Help with the appropriate topic argument. Just like the VIs placed in the <LV>\project folder, these VIs should be set to Run when Opened. Another thing you may wish to do is open an online help document located on the Internet or perhaps a PDF file located on local computer. NI does this by calling the VIs <LV>\help\_browser.llb\Open URL In Browser.vi and <LV>\help\_browser.llb\Open Acrobat Manual.vi. If you wish to do the same, you would want to put a VI inside the <LV>\help folder that calls these VIs with the appropriate path or URL arguments.
tool that will copy a project folder to a new location, load all project files into memory and then rename and relink them according to your project name. The process of renaming and relinking is achieved by doing a Save As starting at the bottom of the hierarchy and working upward. That being said, advanced templates are best left for a development tool application or the next version of LabVIEW ;-)
2. Create a palette view called OrganizationName. Doing this will create a folder called <LV>menus\OrganizationName 3. Inside <LV>vi.lib\ OrganizationName create a folder tree structure that reflects LabVIEWs default palette structure, and populate the folders with your primitive-like VIs, custom controls, and Toolkit-like Packages. Make sure you place these in a logical folder location, based on where you plan on placing them in your custom palette view. Now add these VIs and custom controls to your custom palette view. Add new submenus where appropriate, and make all your icons look good! They should look similar to LabVIEW-primitive icons, which are simple yet easily interpreted. 4. Inside <LV>project\ OrganizationName depending on how many tools you have you may create a folder tree structure, or simply put all of your VIs and LLBs in the root folder. Make sure to set the VI execution options to Run When Opened for those that open via the menu selection. This will make them feel like a stand-alone application. 5. Inside <LV>help\OrganizationName put your toolsets compiled help file or VIs that will open a PDF or help page on the Internet via a web browser. 6. Inside <LV>addons\OrganizationName put all the Toolkit-like packages that dont naturally fit anywhere except at the root functions palette. These will be specific to your company, such as a widget testing toolkit, or something like that. 7. Inside <LV>instr.lib\ OrganizationName place all of your organizations instrument drivers. 8. Now all that is left are VI and Control Templates, Software Component Templates, and Application Architectures. For the very simple stuff you can just put them in the <LV>templates folder. For the big stuff, you will either have to manually copy a source project/component folder to a new location. You may or may not have to rename the VIs in the hierarchy, depending on if you will have more than one instance opened at a time. Another option is to create a tool, which automates this process. That tool should then be placed inside the <LV>project\ OrganizationName so that it is available from the Tools menu. Installing (uninstalling) your tools distribution is now just a matter of copying (deleting) the above-mentioned folders into another installation of LabVIEW. Automating this is step is easy. The user may have to manually change over to your OrganizationName 7
palette-view, but you can automate that, too, by having the installer change the LabVIEW preferences file menuSetup keys value to OrganizationName. Thats all there is to it! To see a working example of all of these principles in action, visit OpenG.org at http://www.openg.org/ and download the OpenG Toolkit, which contains man-years worth of Open Source LabVIEW tools. All this for the low price of free. Lastly, I would like to thank Albert Given and Jean-Pierre Drolet for their valuable feedback and input into this article. I would also like to thank the community at OpenG.org for the content, inspiration, and feedback needed to create the OpenG Toolkit, which was the underlying reason for accumulating the knowledge contained in this article -- special thanks, in particular to LabVIEW Development Tools project team.