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.
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.
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:
To write an interrupt pipe out to a device, you first need to set the VI_USB_BULK_OUT_PIPE attribute in the C API or use the VISA USB Raw Out Pipe Property Node, shown below, in LabVIEW. Then, perform a VISA Write.