This section describes the procedure for developing a LabVIEW Plug and Play instrument driver. The ideal LabVIEW instrument driver allows an end user to control all functionality of the instrument. Because it is not possible to specify required functionality of all different instrument types, such as multimeters, counter/timers, this section focuses on the architectural guidelines for all drivers. Use this information to help organize and package your drivers in a consistent way while still implementing functionality unique to your instrument.
Complete a three-step process to develop a LabVIEW instrument driver. In Step 1, you design the instrument driver structure. In Step 2, you use the Instrument Driver Project Wizard to create new instrument driver VIs. In Step 3, you add developer-defined VIs and create example VIs.
Step 1. Design the Instrument Driver Structure
The ideal instrument driver does what the user needs -- no more and no less. No particular type of driver design is perfect for everyone but by carefully studying the instrument and grouping controls into modular VIs, you can satisfy most of your users.
When the number of programmable controls in an instrument increases, so does the need for modular instrument driver design. Do not try to implement all of the functionality of an instrument with a single VI. However, do not design an instrument driver where each VI controls a single feature. This approach could result in an API with hundreds of VIs. Also, this could force the end user into understanding instrument-specific rules for command order and interaction. Modular design simplifies the programming needed to control the instrument.
Devise the overall structure of your instrument driver before you build the individual VIs. Design an instrument driver with the application and end user in mind.
Understanding the instrument is critical to the design process
The following steps outline one approach to developing the structure for a LabVIEW instrument driver.
- Familiarize yourself with the instrument operation. Read the operating manual thoroughly. Learn how to use the instrument interactively before you attempt any VI development.
- Use the instrument in an actual test configuration to get practical experience. The operating manual might explain how to set up a simple test.
- Study the programming section of the manual. Read the instruction set to learn about the controls and functions available and their organization. Decide upon the best features for programmatic use.
- Examine existing instrument drivers to see if you can find any that control similar instruments. Often instruments from the same family have similar programming command sets that you can modify for your instrument.
- Look for controls that are used together to perform a single task or function to aid in developing the structure of the driver. Often, the sections of the manual correspond to the functional groupings of an instrument driver.
Develop the driver structure by organizing instrument commands
The organization of an instrument driver defines the hierarchy and overall relationship of the instrument driver component VIs.
There are two types of API VIs in an instrument driver: those that are common to all instruments and those that expose the unique capabilities of the instrument. Template instrument driver VIs (initialize, close, reset, self-test, revision query, and error query) perform these common operations. You, as the instrument driver developer, define the VIs that expose the unique capabilities of the instrument. Some instrument drivers might define additional categories, such as “route” or “scan” for switch instruments.
Group common and developer-defined VIs into categories. A category is a group of VIs that perform similar operations. The most common categories of VIs are configuration, action/status, data, and utility.
The following table shows an example instrument driver organization for a simple oscilloscope. At the highest level of the hierarchy, you see the template VIs (initialize and close) and the typical VI categories.
Table 1. Organization Example for a Simple Oscilloscope
Autosetup and Read Waveform Example
Configure Acquisition Mode
Consult the organizational information available in most instrument manuals to help you decide which parameters to include on an instrument driver VI. In particular, the programming section of the manual might group the commands into sections, such as configuring a measurement, triggering, reading measurements, and so on. Use these groupings as a model for the driver hierarchy. Look for controls that are used together to perform a single task or function to help you develop a structure for the driver. A modular driver contains individual VIs for each of the control groups.
The table below shows how instrument commands for a simple DMM might correspond to developer-defined instrument driver VIs.
Table 2. Relationship of Manual Sections and Commands with Instrument Driver VIs.
|Virtual Instrument Terminals
|Initialize ID Query?
|Input/Output Configuration *IDN?
Number Power Line Cycles
|Measurement Configuration SENS:FUNC <function selection>
|Triggering Operations TRIG:SOUR
|Read Measurement Readings
Use the following commands to retrieve measurements
While the instrument manual can provide a great deal of information about how to structure the instrument driver, do not rely on it exclusively. Your knowledge of using the instrument should be your main guide. Often, you should place commands from several different command groups in a single VI. At other times you must take one group of commands from the manual and divide it into two or more VIs. Consider how an instrument manual groups the trigger configuration commands with the commands that actually perform trigger arming and execution. In this case, separate the commands into two VIs -- one that configures the trigger and one that arms or triggers the instrument.
Step 2. Use the Instrument Driver Project Wizard to Create a New Instrument Driver
After you design the LabVIEW instrument driver structure, use the Instrument Driver Project Wizard to create a new instrument driver, and then modify the new instrument driver VIs to work with your instrument.
Using the Instrument Driver Wizard
In LabVIEW 8.x and later, the Instrument Driver Project Wizard can be used to create a new instrument driver project.
Complete the following steps to create an Instrument Driver using the Instrument Driver Wizard:
- From LabVIEW Getting Started Window, select Tools»Instrumentation»Create Instrument Driver Project to launch the Instrument Driver Project Wizard.
- Select New driver from template from the Project Type menu and select the type of instrument from the Source Driver menu.
- Select Next.
- Create a Driver Identifier. It should be something practical.
- Select Next.
- Select icon color and type.
- Select Finish. This will bring up the Project Window and LabVIEW Help.
Step 3. Add Instrument Driver API VIs
Add the developer-defined API VIs that define the functionality of the instrument driver and access the unique capabilities of the instrument.
Using the Instrument Driver VI Wizard
The Instrument Driver VI Wizard can create additional VIs that the instrument supports. If you created a driver from a class template, such as the Digital Multimeter template, the instrument probably supports additional functionality not covered by the class template. You should create additional VIs for each supported feature, using the existing VIs and structure for guidance. For example, oscilloscopes often have many types of triggers but the Oscilloscope template only includes support for edge triggering. If the instrument supports additional types of triggers, add this functionality with additional instrument driver VIs.
Complete the following steps to create an Instrument Driver using the Instrument Driver Wizard:
- Open an Instrument Driver Project.
- Right-click a LabVIEW instrument driver project library (.lvlib) in the Project Explorer Window and select New»Instrument Driver VI from the shortcut menu to display the Instrument Driver VI Wizard.
- On the Start page of the Instrument Driver VI Wizard, select one of the following options and click the Next button.
- Create from an instrument driver template VI—Creates the instrument driver VI from a template VI.
- Copy from an existing VI—Copies and configures an existing instrument driver VI and its subVIs.
- Configure your own VI—Configures an instrument command, specifies how to parse a response, interacts with connected instruments, and generates the corresponding instrument I/O and string formatting/parsing code into a new instrument driver VI.
- Add a blank VI—Creates an instrument driver VI that contains only a VISA resource name control and indicator and an error cluster control and indicator.
- On the second page of the wizard:
- If you selected Create from an instrument driver template VI on the Start page, select a VI from the available instrument driver VI templates on the Clone from Template page and click the Next button.
- If you selected Copy from an existing VI on the Start page, click the Browse button on the Browse for VI page to navigate to and select the VI you want to add to the project and click the Next button.
- If you selected Configure your own VI on the Start page, select Configuration VI or Measurement VI on the Select VI type page and click the Next button. Select Configuration VI to create a VI that sends a command to the instrument. Select Measurement VI to create a VI that sends a command to the instrument and then reads a response from the instrument.
- If you selected Add a blank VI on the Start page, continue to step 6.
- If you selected Configure your own VI on the Start page, configure the Control setup page and click the Next button. Otherwise, continue to the next step.
- Select the appropriate data type for each parameter from the Data type pull-down menu.
- Set a default value for each parameter in the numeric box next to the Data type pull-down menu.
- Verify the configured command string in the Command preview text box.
- If you selected Configuration VI on the Select VI type page, select the instrument from the pull-down menu in the Test the Command section. If you selected Measurement VI on the Select VI type page, click the Next button and select the instrument from the pull-down menu in the Test the Command section.
- Click the Run Test button to test the command you configured. LabVIEW sends the command in the Command preview text box to the instrument and shows the number of bytes written to the instrument in the Bytes written box. If the command succeeds, the light turns a brighter green. If VISA returns an error, the light turns red. Click the Explain Error button to display the errors. If you selected Measurement VI on the Select VI type page, LabVIEW reads the response from the instrument and displays it in the Response text box. You can select the data type of the response in the Configure response data type section.
- On the VI Properties page, edit the VI name, path, icon, and description and click the Next button.
- On the Summary page, review the information about the new VI and click the Finish button to add the instrument driver VI and any subVIs to the instrument driver project and open the VI. If you created the VI from a template VI or an existing VI, LabVIEW renames subVIs that have the same name but a different connector pane as an existing VI in the project library. LabVIEW does not copy subVIs that have the same name and the same connector pane as an existing VI in the project library. The new VI uses the existing VIs in the project library in place of any subVIs that LabVIEW did not add.
• VIs: Names and Properties
• Control/Indicators: Naming and Data Representation
• VI Front Panels
• Icon & Connector Panes
• Block Diagrams
After you modify each VI, create Functions palette menus so customers can install, access, and use instrument drivers from the Functions palette. For consistency, instrument drivers should appear in the Instrument Driver VIs subpalette. Within the subpalette, the instrument VIs should have the same organization as the internal design model as shown in the figure below.
Figure 7. Example Subpalette for the FL45
Front Panel Style
In addition to the controls required to operate the instrument, the front panel should include the VISA resource name control, VISA resource name out indicator, error in control, and error out indicator. Refer to the Drivers Support Libraries section for more information about the VISA session handles. In LabVIEW 7.1 or earlier, refer to Chapter 6 of the LabVIEW User Manual (linked below) for more information about the error in and error out parameters. In LabVIEW 8.0 or later, refer to the Handling Errors topic in the LabVIEW Help (linked below).
Use the following style guidelines to ensure uniformity with other LabVIEW front panels as you design front panels. Refer to the Control/Indicators: Naming and Data Representation and Front Panels section of the Instrument Driver Guidelines for the complete requirements and recommendations for creating instrument driver front panels.
- Use the default (Application) font for all labels. LabVIEW includes this font, so it is available to all other users.
- Format control and indicator names as bold. Capitalize the first letter of each word in the control labels, such as Configure Trigger Source. VISA resource name, error in, error out, and well-known acronyms such as AC or FM are exceptions.
- Enclose default information in plain text in parentheses in the control label so the defaults appear in the Context Help window. This aids in wiring to the VI on the block diagram. For example, label a function selector ring control with a default of DC volts at item zero as Function (0:DCV), and label a Boolean switch that defaults to TRUE indicating automatic enabled as Auto Trigger Delay (T:On).
- Place the VISA resource name control in the upper left, the VISA resource name indicator in the upper right, the error in control in the lower left and the error out control in the lower right.
- Edit all control and indicator descriptions. Refer to the LabVIEW Help for more information about creating control descriptions.
Icon and Connector Pane
Reserve the upper left terminal of the connector pane for the VISA resource name control and the upper right terminal for the VISA resource name out indicator. Reserve the lower left terminal for the error in control and the lower right terminal for the error out indicator to simplify wiring to subsequent error terminals. Select a connector pane pattern that has more terminals than the number of controls and indicators because you might add controls or indicators to the connector pane at a later time. This precaution prevents you from changing the pattern and replacing all instances of calls to a modified subVI. Place inputs on the left and outputs on the right to promote a left-to-right data flow on the block diagram.
Use meaningful icons for every VI. Use the icons found in the Icon Art Glossary whenever possible. Also, you can borrow icons from similar VIs in other instrument drivers or use the icon library Icon256.vi located in the labview\examples\instr\insticon.llb directory. Include the instrument driver prefix at the top of the icon so users can identify VIs from the driver API. Create an icon using glyphs and images that represent the VI functionality. The figure below shows sample configuration icons from the Icon256.vi.
Figure 9. Sample Icons
Refer to the Icon & Connector Pane section of the Instrument Driver Guidelines for specific requirements and recommendations for creating meaning icons and designing connector panes.
After you design the front panel, create the block diagram. Use the Format into String function to create instrument command strings. This expandable function formats multiple values and multiple data types into a string. Double-click the function to enter format commands using the Format Strings dialog box. Also, use the Append True/False String and Pick Line functions to manipulate strings. For example, use the Append True/False String function to convert the value from a front panel Boolean to a string. This function selects the proper string and concatenates it to the command string in one step. Use the Pick Line function to convert a text ring value to a string. This function selects the proper string based on the label value and concatenates it with the command string. Refer to the LabVIEW Help (linked below) for descriptions of these functions. The block diagram in the figure below demonstrates the preferred methods for building command strings.
Figure 10. Techniques for Building Strings
Many instruments comply with the Standard Commands for Programmable Instruments (SCPI) programming command set and syntax. These SCPI-based instruments let you join multiple commands together to send in one I/O write operation. The String functions described above let you build strings that include multiple commands. Wire the combined string to the VISA Write function.
The block diagram is the primary way end users learn how the VI works, so it is important to make the block diagrams as easy to read as possible. Most of the recommendations for instrument driver block diagrams are similar to best practices for all LabVIEW applications, which include following a left-to-right layout of the diagram, minimizing bends in the wires, and using efficient and consistent coding techniques. Refer to the Block Diagram section of the Instrument Driver Guidelines for specific requirements and recommendations for creating an instrument driver block diagram.
The block diagram in the figure below adheres to the requirements and recommendations detailed in the Instrument Driver Guidelines.
Figure 11. Simple Block Diagram that Follows Style Guidelines