Global TMW:
Login  |  Register          Free Newsletter Subscription
Subscribe
Email
Print
Reprint
Learn RSS

Map the route to USB instruments

Program instruments through their USB ports with the same code you use to program IEEE 488, serial, VXI, or Ethernet instruments.

Martin Rowe, Senior Technical Editor -- Test & Measurement World, 5/1/2003

In, out, and trigger
VISA: It's almost where you want to be
Listing 1
The programming of USB instruments

If you develop PC-based test applications, you may want to consider using the universal serial bus (USB) to connect your instruments. With two recently adopted specifications, you'll soon be able to program USB-based instruments with VISA—the Virtual Instrument Software Architecture that provides VXI, IEEE 488, Ethernet, and RS-232-based instruments with a common programming interface (Ref. 1). No longer will you need to use proprietary programming commands that have made it difficult to transfer USB code between instruments and test setups.

Traditional test-and-measurement instruments will increasingly contain USB ports. Courtesy of Agilent Technologies.

Figure 1

shows where VISA fits into the instrument-software hierarchy. VISA translates a common set of function calls into driver-specific commands. For example, an IEEE 488 interface card from National Instruments uses a different driver than a card from Agilent Technologies, but because both companies provide VISA, you can use the same higher-level programming calls with either card. (Both companies are developing new versions of VISA that add support for USB. See "VISA: It's almost where you want to be ," below, for more information.)

VISA and USB

Figure 1. The VISA I/O layer provides a common programming interface from application programs and instrument drivers to test equipment over any of four I/O buses.

VISA, originally developed by the VXIplug&play Systems Alliance, provided IEEE 488, VXI, and RS-232 instruments with a common command set. The alliance members later extended VISA to support Ethernet.

In April 2001, several instrument manufacturers convened to address the two main drawbacks to using USB in test applications:

  • USB is a serial bus, so it lacks dedicated hardware line interrupts, service requests, and triggers, which you get with IEEE 488 and VXI-based instruments. USB needs to provide these functions in software.
  • Most instruments with USB ports use proprietary drivers, so code written for IEEE 488 and VXI instruments is unusable with USB instruments.

Because USB instruments are packed in boxes like IEEE 488 instruments, rather than as cards like VXI instruments, the instrument makers wanted engineers to be able to take code they'd written for the IEEE 488 bus and use it to communicate over the USB. Working within the USB Implementers Forum Device Working Group (USB-IF DWG), the instrument manufacturers adopted two specifications in December 2002—the USB Test and Measurement Class (USBTMC) base-class specification and the USBTMC-USB488 subclass specification (Ref. 2).

The USBTMC base-class specification describes a method that lets computers communicate with sensors and analog-to-digital converters. The USB488 specification provides communication with test equipment such as oscilloscopes, DMMs, function generators, and power supplies.

To make USB compatible with existing VISA-compatible applications code, VISA maps certain IEEE 488 functions into USB functions. "In, out, and trigger ," below, provides more detail on the command mapping.

Using VISA

If you know how to use VISA with other buses, then you already know how to write code for the USB488 version of VISA. With VISA, application code or instrument drivers make function calls with names such as viOpen(), viClear(), viWrite(), and viRead(). Because VISA hides the details of the lower-level USB drivers from you, you needn't concern yourself with USB endpoints, headers, buffer lengths, or other parameters.

Figure 2. An alias editor lets you assign meaningful names to instruments on an I/O bus. Courtesy of National Instruments.

Each VISA function call requires an identifier, called a resource descriptor, that directs the call to the correct instrument. Figure 2 lists several types of resource descriptors, the last two of which pertain to USB. A USB resource descriptor for test-and-measurement equipment uses this syntax:

USB[board]::manufacturer ID::model code::serial number[::USB interface number][::INSTR]

The USB descriptor that ends in "INSTR" tells VISA that it will talk to a USBTMC piece of equipment. The "[board]" descriptor, which lets you describe a USB device, is optional. The manufacturer ID, model code, and serial number are always required to uniquely identify an instrument. Fortunately, producers of VISA also provide software that lets you enter aliases for resource descriptors so you don't have to define them in your code.

After you assign an alias to an instrument, you're ready to make function calls to VISA. Listing 1 shows an example (written in C) of using the VISA functions viOpen, viClear, viWrite, and viRead.

The viOpen command returns a session identifier that enables communication between an application program and a particular instrument. Listing 1 shows an example use of an alias with viOpen(). The viOpen() function returns arbGenSession, which viClear(), viWrite(), and viRead() then use to communicate with an arbitrary waveform generator. For a more extensive code example, click here .

In Listing 1, the variable defaultRM represents the VISA default Resource Manager. idnQuery represents the IEEE 488 "*IDN?" command, and idnResponse holds the instrument's response to the query. If, for example, you use a DMM, then idnResponse might hold "Agilent Technologies,34401B,S000-0123-02,0".

Listing 1 demonstrates that programming an instrument through VISA maintains a common programming interface across I/O buses. With VISA, you can write applications programs or instrument drivers for IEEE 488, USB, VXI, and Ethernet I/O buses using identical commands. You need only designate the I/O bus for each instrument.


Author Information
Martin Rowe has a BSEE from Worcester Polytechnic Institute and an MBA from Bentley College. Before joining T&MW in 1992, he worked for 12 years as a design engineer for manufacturers of semiconductor process equipment and as an applications engineer for manufacturers of measurement and control equipment. m.rowe@tmworld.com.


References
  1. You can download the VISA specification from the VXIplug&play Systems Alliance, www.vxipnp.org.
  2. You can download the USB specifications from www.usb.org/developers/devclas_docs/USBTMC_1_006.zip. Eds. note 11/7/03: This is no longer available.
  •  

    In, out, and trigger

    Mapping of IEEE 488 commands to USB commands
    IEEE 488 command USB command
    Device Clear Control Endpoint request
    Remote/local Control Endpoint request
    Service request (SRQ) Interrupt-IN transfer
    Programming message Bulk-OUT transfer
    Response message Bulk-IN transfer
    Trigger (GET) Bulk-OUT transfer

    The IEEE 488 bus uses hardware lines to initiate bus events such as interrupts, service requests, and triggers. USB, though, is a serial bus that encapsulates data into packets rather than sending data over parallel lines. With USB488, each USB transfer begins with a header that describes the type of data that follows. For example, the header tells the USB device the total size of the message being sent so the device may begin a DMA operation.

    To make USB instrument control compatible with IEEE 488, the USB488 specification's developers separated GPIB functions into "in band" and "out of band" functions. IEEE 488 in-band functions include instrument programming messages and measurement results. Out-of-band messages include IEEE 488 functions such as device clear, service request (SRQ), trigger, and remote/local instrument control. The table summarizes the mapping of some IEEE 488 and USB commands.

    USB uses its Bulk-OUT transfer function to process programming messages. Programming messages include those that program an instrument state such as "VOLT:DC" and those that send queries such as "*IDN?" to an instrument. The USB Bulk-IN transfer function handles data sent from instruments to the host computer.

    Some out-of-band test-and-measurement commands such as Device Clear map to the USB control endpoint because the USB specification requires a control endpoint on every device. Many USB device-class specifications for devices such as printers and disk drives also use the USB control endpoint to reset a device.

    A hardware-controlled IEEE 488 SRQ becomes an out-of-band communication through the USB Interrupt-IN endpoint. Because USB uses a master-slave protocol, the transfer of Interrupt-IN data occurs only when the PC polls the Interrupt-IN endpoint. The USB device sets the polling interval, but the interval must fall within the limits set by the USB 2.0 specification.

    For high-speed (480 Mbits/s) devices, the polling interval must be less than or equal to 125 µs, the time of one USB microframe. For full-speed (12 Mbits/s), the polling interval must be less than or equal to the duration of 1 USB frame, or 1 ms.

    IEEE 488 provides both in-band an out-of-band methods to trigger a device. The "*TRG" command maps to USB as an in-band function because it's a software trigger. The "GET" command, a hardware trigger on the IEEE 488 bus, maps to USB as an out-of-band function.

    To learn the byte-level details of USB488 data transfers, you can download a paper by Andy Purcell, software design engineer at Agilent Technologies. Andy chaired the USB488 working group. Download the paper in Word format.

    VISA: It's almost where you want to be

    At press time, VISA with USB support had limited availability. Agilent Technologies' VISA version M, which supports USB, ships with the company's 33220A waveform generator. That was, and perhaps still is, the only way to get it.

    I asked Agilent when the company will make VISA version M available for download. Agilent Fellow Joe Mueller reported that the company planned to release Version M on May 1. To download VISA, you need an Agilent Developer Network Professional subscription ($495/year). You can, however, register for a 45-day free trial at www.agilent.com/find/buyadn. Eds. note 11/7/03: The free trial is no longer available at this address.

    National Instruments (www.ni.com) is currently developing its own VISA with USB support. Product manager Dany Cheij expects to release VISA with USB support in early summer. Currently, National Instruments distributes a copy of VISA with each hardware and software product that can use it. Hardware includes IEEE 488 interface cards and VXI system controllers. Software includes development packages such as LabView and Measurement Studio. If you already own a copy of NI-VISA, you can download the USB version, when available, at no charge.

    ---------------------------------------------------------------------------------------------------------

    Listing 1

    viOpen(defaultRM,”arbGen”,VI_EXCLUSIVE_LOCK,VI_NULL, &arbGenSession);
    viClear(arbGenSession);
    viWrite(arbGenSession,idnQuery,(ViUInt32)strlen idnQuery),&retCount);
    viRead(arbGenSession,idnResponse,sizeof(idnResponse),  &retCount);

    Email
    Print
    Reprint
    Learn RSS

    Talkback

    We would love your feedback!

    Post a comment

    » VIEW ALL TALKBACK THREADS

    Related Content

    Related Content

     

    By This Author

    Sponsored Links



     
    Advertisement
    SPONSORED LINKS

    More Content

    • Blogs
    • Podcasts

    Blogs

    • Martin Rowe
      Rowe's and Columns

      July 8, 2008
      Introducing...Test ideas
      Beginning in the T&MW August print issue, we’ll replace the “Project Profile” ...
      More
    • Martin Rowe
      Rowe's and Columns

      July 8, 2008
      They finally figured it out
      I just received a press release from one of those companies that analyzes industries. This one is ab...
      More
    • » VIEW ALL BLOGS RSS

    Podcasts

    Advertisements





    NEWSLETTERS

    Click on a title below to learn more.

    Test Industry News (3 Times Per Month)
    Machine-Vision & Inspection (Monthly)
    Communications Test (Monthly)
    Design, Test & Yield (Monthly)
    Automotive, Aerospace & Defense (Monthly)
    Instrumentation (Monthly)
    Resource Center E-Alert (Monthly)
    ©2008 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
    Use of this Web site is subject to its Terms of Use | Privacy Policy
    Please visit these other Reed Business sites