Using NI-VISA 3.0 to Control Your USB Device
This tutorial is meant as a starting point for using NI-VISA to communicate with a USB device. It is not intended as a starting point for learning about USB architecture or the various protocols used in USB communication. After reading this tutorial, you should be able to install a USB device and use NI-VISA to communicate with that device, as long as you understand the device communication protocol.
Table of Contents:
- 1. USB and VISA Background
- 2. Configuring NI-VISA to Control Your USB Device
- 3. Using NI-VISA to Communicate with Your USB Device
|
| ||
| 1. USB and VISA Background | ||
VISA is a high-level application programming interface (API) used to communicate with instrumentation buses. VISA is platform independent, bus independent, and environment independent. In other words, the same API is used regardless of whether a program is created to communicate with a USB device with LabVIEW on a machine running Windows 2000 or with a GPIB device with C on a machine running Mac OS X.
Universal Serial Bus (USB) is a message-based communication bus. This means a PC and a USB device communicate by sending commands and data over the bus as text or binary data. 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. Check with your instrument manufacturer for a list of valid commands for your instrument.
Starting with version 3.0, NI-VISA supports USB communication. Two classes of VISA resources are supported: USB INSTR and USB RAW.
The USB INSTR resource class is used by USB devices that conform to the USB Test and Measurement Class (USBTMC) protocol. USBTMC devices conform to a protocol that the VISA USB INSTR resource class can understand. No configuration is necessary to communicate with a USBTMC device. To communicate with a USBTMC instrument, refer to section 3. For more information about the USBTMC specification, refer to the USB Implementers Forum Web page linked below.
USB RAW instruments are any USB instrument other than those instruments that specifically conform to the USBTMC specification. If you are using a USB RAW device, follow the instructions in section 2 to configure NI-VISA to control your device. Contact your instrument manufacturer for details about the communication protocol and the command set your instrument uses.
For specific information about the NI-VISA API, refer to the NI-VISA User Manual and NI-VISA Programmer Reference Manual. Both documents are included with NI-VISA and are available through the links at the end of this tutorial.
|
| ||
| 2. Configuring NI-VISA to Control Your USB Device | ||
This section walks through the steps for configuring a USB RAW device to be controlled by NI-VISA 3.0 on a Windows-based computer. If you are using a USBTMC-compatible device, connect your device and skip to section 2.3.
At this point, NI-VISA already should be installed on your computer, and your USB device should not be connected. Furthermore, you should not have a driver for your USB device installed. There are three steps to configure your USB device to use NI-VISA:
- Create the INF file using the Driver Development Wizard.
- Install the INF file and the USB device using the INF file.
- Test the device with NI-VISA Interactive Control.
Figure 1. VISA DDW Hardware Bus Window
Figure 2. VISA DDW Basic Device Information Window
Figure 3. VISA DDW Output Files Properties Window
Figure 5. VISA Interactive Control
Figure 6. VISA Interactive Control Open VISA Session
Figure 7. USBTMC LabVIEW Example Block Diagram
Related Links:
For the purposes of this tutorial, a National Instruments DAQPad-6020E is used as an example USB device and is installed on a Windows XP system. Because this tutorial is intended to explain the configuration of a generic USB device, details specific to the DAQPad-6020E are not discussed. Remember that NI-DAQ is the only supported driver for a DAQPad-6020E.
2.1. Create the INF File Using the Driver Development Wizard
To use NI-VISA, you must first tell Windows to use NI-VISA as default driver for the device. In the Windows environment, you can do this with an INF file. NI-VISA 3.0 includes the VISA Driver Development Wizard (DDW) to create an INF file for your USB device.
You can use this wizard to create an INF file for a PXI/PCI or USB device. Because you are creating the driver for a USB device, click USB and Next. The VISA DDW Basic Device Information window opens as shown in Figure 2.
Enter the vendor ID, product ID, manufacturer name, and model name for your device in their respective fields.
For the DAQPad-6020E, the vendor ID and product ID are 0x3923 and 0x12C0, respectively. If your device is not a National Instruments DAQPad-6020E, the vendor ID and product ID are different for your device. Contact your device vendor to obtain this information.
Click Next. The Output Files Properties window is displayed as shown in Figure 3.
2.2. Install the INF files and the USB device.
The installation of the INF files is different for each version of Windows. When the DDW creates an INF file, installation instructions are included in a header at the top of the INF file. Because INF files are ASCII text files, they can be read in any text editor such as Notepad. For detailed information about installing your INF file, open your INF file in a text editor and follow the instructions at the top of the file. This tutorial assumes you are using Windows XP.
2.3. Test Communication with VISA Interactive Control.
If you select your USB device, the device information is displayed in the Attributes window. Using this window, you can access information such as the manufacturer ID, model code, and serial number for your device.
Figure 4. USB Device Shown in Measurement & Automation Explorer
According to the USBTMC specification, all USBTMC devices must have a serial number. Some USB RAW devices may not have serial numbers. If your device does not have a serial number, NI-VISA automatically assigns a VISA specific serial number for that device. The format for the serial number is NI-VISA-#, where # is an automatically generated number.
Some USB devices have multiple interfaces. This is similar to the way a PCI device can have multiple functions. If your device only supports one interface, you do not need to include the USB interface number.
The DAQPad-6020E uses the RAW class, and the manufacturer code and model code are 0x3923 and 0x12C0, respectively. For the DAQPad-6020E, the instrument descriptor is USB0::0x3923::0x12C0::00B50DAE::RAW.
To test communication with this device, open Measurement & Automation Explorer. Select Tools»NI-VISA»VISA Interactive Control. A window similar to that shown in Figure 5 should open.
When you open a VISA Session with VISAIC, the Template tab and the Property Node (Read) tab are automatically selected. To read a property, select the desired property and click Execute. The current value of the property specified in Attribute Name is displayed in the Current Value indicator. In Figure 6, the Resource Name property was read.
For more information about using VISAIC, refer to Developer Zone Tutorial: VISA Interactive Control (VISAIC), linked below. For information about the NI-VISA API, review the NI-VISA Programmer Reference Manual and the NI-VISA User Manual. Both are available through the links at the end of this tutorial. For a list of valid commands for your USB instrument, contact your instrument’s manufacturer.
![]()
3. Using NI-VISA to Communicate with Your USB Device
This section explains how to communicate with your USB device using NI-VISA 3.0 and above. Recall that there are two classes of USB devices. The method of communication depends on the class of your device.
3.1 USB INSTR Class (USBTMC)
Devices that conform to the USB Test and Measurement Class (USBTMC) use the NI-VISA USB INSTR class. These devices use 488.2 style communication. For these devices, you can simply use the VISA Open, VISA Close, VISA Read, and VISA Write functions in the same way you would if you were communicating with GPIB instruments.
Figure 7 illustrates a LabVIEW VI that communicates with a USBTMC device. In this example, a VISA session is opened to a USB device. A command is written to the device, and the response is read back. In this example, the specific command being sent is the ID query for the device. Check with your device manufacturer for your device command set. After all communication is complete, the VISA session is closed.
3.2 USB RAW Class
Communicating with the USB RAW class is more complicated because each device may use its own communication protocol. Contact your device vendor for details about the communication protocol for your device.
USB communicates using four types of pipes or endpoints: control, bulk, interrupt, and isochronous. Each type of pipe transfers a different type of information. Furthermore, any number of endpoints can be of any endpoint type. Think of an endpoint as a communication socket. For specific details about USB architecture, review the USB specification linked below.
NI-VISA supports three types of USB pipes: control, bulk, and interrupt. When NI-VISA detects your USB instrument, it automatically scans your instrument for the lowest available endpoint for each type.
When VISA detects the lowest available endpoint, it assigns that value to the appropriate VISA attribute. The bulk in endpoint and bulk out endpoint are stored in the VI_ATTR_USB_BULK_IN_PIPE attribute and the VI_ATTR_USB_BULK_OUT_PIPE attribute, respectively. The interrupt in endpoint is stored in the VI_ATTR_USB_INTR_IN_PIPE attribute. A value of -1 indicates that a USB device does not support that type of pipe. For the control pipe, only endpoint zero is supported. If you are using the C API, use the viSetAttribute function to change endpoints. In LabVIEW, use a Write VISA Property node.
NI-VISA includes four functions to transfer data through USB pipes. Before you can communicate with your device using these functions, you need to set up the communication protocol using the VISA USB attributes. The following list describes the available functions.
Using the PXI Driver Development Wizard and NI-VISA to Register-Level Program a PXI/PCI Device under Windows
USB Implementers Forum: USB 2.0 Specification: http://www.usb.org/developers/docs
USB Implementers Forum: Approved Class Specification Documents: http://www.usb.org/developers/devclass_docs
VISA Interactive Control (VISAIC)
Product Manuals: NI-VISA Programmer Reference Manual
Product Manuals: NI-VISA User Manual
posted on 2005-05-22 15:42 LabVIEW开发者 阅读(2086) 评论(1) 编辑 收藏
