Using NI-VISA to Communicate with Your USB Device

NI-VISA

Using NI-VISA to Communicate with Your USB Device

This topic explains how to communicate with your USB device using NI-VISA. Recall that there are two classes of USB devices. The communication method depends on the device class.

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, use the VISA Open, VISA Close, VISA Read, and VISA Write functions the same way as if communicating with GPIB instruments.

The following figure shows a LabVIEW VI that communicates with a USBTMC device. In this example, the VI opens a VISA session to a USB device, writes a command to the device, and reads back the response. In this example, the specific command being sent is the device ID query. Check with your device manufacturer for your device command set. After all communication is complete, the VI closes the VISA session.

USBTMC LabVIEW Example Block Diagram

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 device communication protocol.

USB communicates using four types of pipes or endpoints: control, bulk, interrupt, and isochronous. Each type of pipe transfers a different type of information. Also, 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.

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 and 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 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 must set up the communication protocol using the VISA USB attributes. The following functions are available:

  • Use VISA USB Control In and VISA USB Control Out to transfer data using the control pipe.
  • To transfer data using a bulk pipe, use VISA Read and VISA Write.
  • If you are using LabVIEW, VISA includes an additional function to use the interrupt pipe: VISA Get USB Interrupt Data. In the C API, you can do this by accessing the VI_ATTR_USB_RECV_INTR_SIZE and VI_ATTR_USB_RECV_INTR_DATA attributes of the VI_EVENT_USB_INTR event object.