USB Instrument Control

Publish Date: Apr 30, 2020 | 240 Ratings | 3.35 out of 5 | Print | 17 Customer Reviews | Submit your review


This tutorial shows you how to set up National Instrument software to communicate with a USB instrument in LabVIEW.

The NI-VISA driver supports two classes of USB instruments: USB Test and Measurement Class (USBTMC) and USB RAW instruments. USBTMC instrument conform to the USBTMC protocol, while USB RAW instruments use their own specific communication protocol. This tutorial will cover both types of instruments.

Table of Contents

  1. Prerequisites
  2. Install NI Software and Drivers
  3. Set Up and Configure Hardware
  4. Test Communication
  5. Install Instrument Driver
  6. Run an Example
  7. Related Links

1. Prerequisites

Make sure you have a USB A to USB B cable to connect your instrument to the computer.  

This tutorial assumes familiarity with your instrument’s communication protocol and focuses on the set-up workflow in National Instruments software. The set-up steps are different depending on the protocol used. Consult the documentation for your USB instrument or contact the instrument manufacturer for this information.


Back to Top

2. Install NI Software and Drivers

Install the latest compatible version of LabVIEW and the NI-VISA driver. Refer to the following for compatibility information. 


Back to Top

3. Set Up and Configure Hardware

After installing NI software, connect and configure your USB instrument.

USBTMC Instruments

NI-VISA will detect USBTMC instruments automatically, so no additional configuration is necessary after installing the NI-VISA driver. The instrument will be installed as a USB Test & Measurement Class Device. 

  1. Securely connect the USB instrument to the computer via a USB cable.
  2. Open Measurement and Automation Explorer (MAX) from the Start menu. Expand Devices and Interfaces >> USB Devices. You should see the VISA resource name of the USBTMC instrument listed as USB[board]:: manufacturer ID:: model code:: serial number:: [USB interface number]::INSTR.
  3. Once complete, continue to the Test Communication section.

USB RAW Instruments

For NI-VISA to recognize USB RAW instruments, you need to create a set-up information file (INF file) with the NI-VISA Driver Wizard and install it onto your computer.

Create INF File (USB driver)

  1. Open NI-VISA Driver Wizard from the Start menu.
  2. On the Hardware Bus Selection page, select USB. Click Next.

  1. On the Device Selection page, do one of the following:
    • If your device is already connected to the computer, select it from the device list and click Next. If you do not see your device on the list, make sure it is securely connected and select Refresh. Continue to Step 5.
    • If your device is not connected/unavailable, select Other… at the bottom of the list. Click Next.

  1. If you selected Other…, the USB – Device Information page allows you to manually input information about your device.

Click the question mark on the upper right of the window. This enables the Context Help and provides descriptions for each field.

To get the USB Manufacturer ID (Vendor ID) and USB Model Code (Product ID), refer to External: USB Vendors. Search for the manufacturer of your instrument from the list and select Devices. The table will provide the Vendor ID and the Device ID. If you cannot find the Vendor or Device ID, contact your device manufacturer for this information.

Once you have the fields filled out, click Next. The image below shows an example for a National Instruments GPIB-USB-HS device.

  1. On the Output Files Generation page, name your INF file in the Instrument Prefix field and specify where it should be saved. Click Next.

  1. On the Installation Options page, specify your installation option.
    • If you would like to have the  NI-VISA Driver Wizard automatically install the INF file for you, select Install the generated files on this computer and click Finish. This is the default and recommended option. Continue to the Install USB Instrument section.

Note: Choosing the Install the generated file(s) on this computer option requires administrator/root privilege.

    • If you would like to install the INF files yourself, select Do nothing and exit the wizard and click Finish. Continue to the section below.

Install INF File

If you are manually installing the INF file, navigate to the location the INF file was created and open the INF file in any text editor (e.g., Notepad). The installation instructions are included in the header at the top of INF file.

For more detailed instructions, follow the steps below:

  1. If you’re using a Windows 8 machine or higher, you must sign the INF file first to install it on your computer. Windows 7 and earlier machines can skip to the next step.
  2. Make sure you are logged into an Administrator user account.
  3. Disconnect the USB instrument at this time so the driver will be properly associated with the device upon re-install.
  4. Copy the INF file to C:\\Windows\INF. If the INF folder is hidden, navigate to Tools >> Folder Options >> View >> Advanced Settings >> Show hidden files, folders, and drives to unhide it.
  5. Right-click on the INF file and click Install. This creates a PNF file for your device. You are now ready to install your USB instrument.

Install USB Instrument

  1. Securely connect the USB instrument to the computer via a USB cable.
  2. Add New Hardware Wizard should automatically open after you connect your device. Select Next. On the Add Hardware page, select Search for and install the hardware automatically (Recommended).  

  1. After an installation period, Windows should indicate that it has successfully installed your device.
  2. Open Measurement and Automation Explorer (MAX) from the Start Menu and expand Devices and Interfaces. You should see the instrument’s VISA resource name in the format USB[board]:: manufacturer ID:: model code:: serial number::[USB interface number]::RAW.

Some USB RAW instruments may not have serial numbers. If this is the case, NI-VISA automatically assigns a VISA specific serial number in the format “NI-VISA-[number]”.

If the instrument only supports 1 interface, it will not be included in the VISA resource name.

In some cases, Windows may already have a default driver associated with your USB instrument and will install that driver first. To re-associate the driver to the INF file, follow the steps below:

  1. Open Device Manager.
  2. Find your instrument on the list and make sure its Vendor ID (VID) and Product ID (PID) matches the ones used to create the INF file.
  3. Right click on the instrument and select Update Driver Software.
  4. Select Browse my computer for driver software.
  5. Select Let me pick from a list of drivers on my computer.
  6. Select Have disk.
  7. Navigate to C:\\Windows\INF and select the INF file.
  8. Click Next.
  9. Click Finished.  


Back to Top

4. Test Communication

After set-up and configuration, use VISA Test Panels to verify communication with the instrument and test different instrument commands.

  1. In MAX, select the Tools tab >> NI-VISA >> VISA Interactive Control.
  2. Select the VISA resource name of your USB instrument.
  3. In the Test Panel windows, select the Input/Output tab.
  4. In the Basic I/O tab, input a supported command and select Query. Refer to manufacturer documentation for a valid list of commands to use with your instrument. 
  5. The display window will outline the write and read operations.


Back to Top

5. Install Instrument Driver

After completing your configuration and verifying communication with the instrument, you need an easy way to transition from interactive mode to programming mode.The best way to achieve this is by using instrument drivers.

Refer to Choosing the Right Interface to Control Instruments in LabVIEW to determine which instrument driver type is best for your application. Follow the links in the document to install and use the instrument driver.


Back to Top

6. Run an Example

The instrument driver and NI-VISA driver will install examples and the API required to communicate with your instrument. Use these examples as programming references and an easy way to start using your instrument.

Note: Close MAX before you start running a LabVIEW example. Having MAX Test Panels open and running a LabVIEW example simultaneously will result in an access resource error. 

Instrument Driver Examples

If you installed an instrument driver, refer to the following examples:

  1. Plug and Play instrument driver examples
  2. IVI instrument driver examples

NI-VISA Driver Examples

If you are using NI-VISA, refer to the following examples based on the USB instrument type.

USBTMC Instruments

For USBTMC instruments, you can use the NI-VISA API to communicate with the instrument. An example snippet is provided below. This example opens a session to the USB instrument, performs a write of *IDN?\n, reads the specified number of bytes back from the instrument, closes the session, and handles any errors.

  1. Drag the snippet directly onto an empty LabVIEW block diagram. 
  2. On the front panel, configure the VISA resource name to be the VISA resource of your instrument previously configured in this tutorial.
  3. Run the VI.

For more information on VISA functions, refer to LabVIEW Help: VISA VIs and Functions.



USB RAW Instruments

NI-VISA USB RAW mode supports Interrupt, Bulk and Control data transfers. Isochronous transfers are not supported. For more information about these communication types, refer to LabVIEW Help: Using NI-VISA to Communicate with Your USB Device.

Refer to the USB RAW shipping examples by navigating to the LabVIEW Help tab >> Find Examples…>>Hardware Input and Output >> VISA. You will find examples for bulk, control, and interrupt communication.

Note: Because NI-VISA USB RAW support is very device-specific, it requires detailed knowledge of how the device operates. Refer to manufacturer documentation for details on the communication protocol for your USB RAW instrument.


Back to Top

7. Related Links

More USB Resources

Other Instrument Control Tutorials

Back to Top

Customer Reviews
17 Reviews | Submit your review

Helpful hint if device not showing up in device list  - May 27, 2015

I found that the device wasn't showing up after installing the INF file as explained. I deleted the inf file and also the file that was generated at the same time, then started from scratch. Created an inf file and copied to \Windows\inf, -> Right click <<Install>>. Wait a minute, then connect the device. Hey presto! The device showed up on the task bar USB and in the M&A Explorer.

Worked great on a Mac...  - Apr 12, 2012

Still get error before termination completed  - Nov 22, 2011

I did all the steps but in MAX, the serial number appeared not as the format given as in NI-VISA#, but it appears as: 0001. Is this considered successful or I need to install it again? Plus, my VISA Interactive Control cannot be opened, popout error everytime I click. Help me please!

Excellent and complete  - Aug 25, 2010

Wow, what an amazingly complete set of instructions for setting up usb. Thank you!

  - Aug 6, 2010

I have used PIC18F4550 and successfully communicate it with PC using Virtual COM Port But I cant communicate it as a USB ... i have communicate it by using VB Code ( example on ) but cant send/receive data from PC using LabView (Although i m sending same Data) Plz tell me how to send/receive data using LabView THNK U JIMI

Really perfect!  - Jul 30, 2010

This was the first time I try to install a USB driver without the need of Windows! I've found exactly what I needed to communicate with my Ocean Optics USB4000 spectrometer. No problem, under Windows XP 32 bits and after with Windows 7 64 bits. Thanks a lot.

NOTE for Windows 7 Users  - Jun 7, 2010

Good article. Got me started using Wavelenngth Electronics FL593 Laser Diode Driver. I installed INF file on Windows 7, so using the Vista one worked (DDW also created one for XP) and NI-VISA recognized the device right afterwards. Also, it only worked when I uninstalled the weiusb driver that came with the product CD (consistent with article). Just thought I'd point that out in case someone's using Windows 7; so yes, i agree with everyone else about an update. :-)

For Windows Vista?  - Jul 30, 2008

Is the procedure same for Windows Vista?

You can get the vendor ID and Product ID  - Jul 19, 2007

In device manager view devices by connection and find the USB connections. Browse through all the hubs until you find your instrument then go to the properties. This is hidden in the normal view

  - Jan 26, 2007

Each USB device has its own command set. You can use NI-VISA Read and Write functions to send these commands to an instrument and read the response from an instrument. This is great But what if you vendor does not have this or does not want to give to you Check with your instrument manufacturer for a list of valid commands for your instrument. Is there a function that would list commands or a set of standard calls that would be a start

isochronus enpoints  - May 26, 2006

what about isochronus endpoints? can't we read in isochronus mode?

NI_Visa users manual out of date  - Mar 14, 2006

NI VISA Users manual is version 2.x (2001) and does not contain programming examples for USB connection. Current NI VISA is 3.x

It's a start.  - Aug 17, 2005

Like other comments, USB vendor ID and product ID for NI are identified but the world is bigger then that. Should you not be able to get the same information from the "Device Manager"

Full example for FX2 USB device  - Jul 25, 2005

The document is good, but need to be update; I am able to put online one update for this document. The purpose of my document is show how to make the interface with the cypress FX2 USB device. If some person explain mi how to put this update in this web I will put it. Thank you for the help that I found in this document Thak you for the help that i found in this document

RAW-USB-Devices and Linux ??  - Apr 15, 2005

Nice document... But what about people not using Windows but Linux ??? How do they get a RAW USB Device ready to work with Labview under Linux?

  - Aug 23, 2004

This document needs to tell you how to get the product ID and vendor ID

Vendor/Product ID  - Nov 21, 2003

It will be good if NI can keep a database of the various vendors and products ID that uses USB interface.

View more reviews

Bookmark & Share


Rate this document

Answered Your Question?
Yes No