The following sections explain how to create and configure a LabVIEW SubVI.
-
Create a LabVIEW SubVI
-
Edit the SubVI Icon
-
Build the Connector Pane
Create a LabVIEW SubVI
You can simplify the block diagram of a VI by converting sections of the block diagram into subVIs. There are two ways to make a subVI in LabVIEW:
- Creating a standalone VI and then use it (drag and drop it) in a higher-level VI as a subVI
- If you have already created the code that you would like to use in other VIs as its own standalone VI, continue on to the Edit the SubVI Icon section
- Create a subVI from a section of code within another VI.
- Launch LabVIEW and open the VI from which you want to create a subVI
- Highlight the code you would like to convert into a subVI
- From the Edit menu, select Create SubVI to create a subVI from your selection.
- The selected section of the block diagram is replaced with a default icon for the subVI. LabVIEW creates controls and indicators for the new subVI, automatically configures the connector pane based on the number of control and indicator terminals you selected, and wires the subVI to the existing wires.
- In the following sections, we will step through how to adjust the default icon and connector pane configurations.
Edit the SubVI Icon
The subVI icon is what you see from the block diagram that the subVI is placed on. Although it is not necessary to change it, updating the subVI icon is useful to create easily-identifiable functions. This is especially helpful if you creating many subVIs to include in your code. You have options to update like adding built-in glyphs, text, or importing your own images.
- Open the subVI
- If you created the subVI from a section of code in an existing VI, double-click the newly placed icon to open.
- From the front panel or block diagram of the subVI, double-click the icon in the upper right-hand corner to launch the Icon Editor
- Explore the pages of the Icon Editor dialog box and update your icon as desired.
- Press OK to save the icon.
Build the Connector Pane
In order to use the subVI in line with other code, you need to configure the connector pane. The connector pane is a visual representation of how inputs and outputs are connected to the subVI from the calling VI.
- If you created a subVI from a subsection of code, LabVIEW configures inputs and outputs automatically.
- If you created a standalone VI to be used as a subVI (not created from sections of code), your terminals will be blank. You will assign inputs and outputs to terminals on the connector pane in the next step.
- Select the connector pane pattern by right-clicking the connector pane icon >> Pattern >> choose from the arrays available to suit your function's needs.
- Each rectangle on the connector pane represents a terminal. You will use the rectangles to assign inputs and outputs.
- See Building the Connector Pane in LabVIEW Help for more considerations when deciding on patterns and wiring terminals.
- Examine the connection terminals that are connected (if any).
- You can check the default configured connections by left-clicking on the colored boxed in the connection pane. The linked input/output will become highlighted on the front pane
- Assign (or re-assign) connection terminals to controls and indicators.
- Click a terminal of the connector pane.
- Click the front panel control or indicator you want to assign to that terminal.
- It is generally good programming practice to organize the inputs to a subVI on the left and the outputs on the right.
- Note that the terminal color changes to that of the data type to which you have connected it.
- You also can select the control or indicator first and then select the terminal.
- If you need to unassign a terminal, right-click the terminal and select Disconnect this Terminal
- Click an open space on the front panel to deselect the control.
- Repeat these steps for all the controls and indicators that you will use to pass data to and from the calling VI.
- Set the Required, Recommended, and Optional Inputs and Outputs
- Right-click a terminal in the connector pane.
- Select This Connection Is from the shortcut menu.
- Select Required, Recommended, or Optional.
- In the Context Help window, the labels of required terminals appear bold, recommended terminals appear as plain text, and optional terminals appear dimmed. The labels of optional terminals do not appear if you click the Hide Optional Terminals and Full Path button in the Context Help window. Output terminals cannot be set as Required.
- Alternatively, you also can select Tools»Options»Front Panel and put a checkmark in the Connector pane terminals default to Required checkbox. This option sets terminals on the connector pane to Required instead of Recommended. This applies to connections made using the wiring tool and to subVIs created using Create SubVI.