Using APx with VEE and MATLAB (API Wrapper)

Created on 2009-10-23 21:20:00

AP’s API Wrapper resolves .NET limitations in VEE and MATLAB, allowing them to access the complete APx API for automation and systems integration.

The APx API (Application Programming Interface) supports the .NET framework, allowing extensive automation and data exchange using any .NET compatible programming language. Two of the popular languages that work with APx are VEE from Agilent, and MATLAB from The Mathworks. VEE is a graphical language designed to utilize interconnected hardware for measurement and analysis. MATLAB is optimized for computationally intensive tasks and has advanced graphing capabilities.

The APx API makes extensive use of .NET interfaces. In programming terms, an interface contains no functional code, but serves as a bridge between a program and the outside world. Although VEE and MATLAB can see these interfaces, their .NET implementation only enumerates a small subset of the properties and methods that are contained in them, leaving the others inaccessible.

To overcome this problem, AP software engineers have created a class wrapper—a dynamic link library (DLL) that wraps the APx API interfaces in classes, so that all the API objects become visible from within VEE and MATLAB. The wrapper is available as a separate download for APx500 2.4, but starting with APx500 2.5, it is installed along with the APx application. We aren’t currently aware of any other programming languages that need the wrapper, but if any arise, the wrapper should accommodate them as well.

Accessing the API directly vs. using the API wrapper.

Using the wrapper imparts no performance penalty, and it is essentially transparent—all you have to do is reference it at the beginning of your code. In a default installation, you would reference the API wrapper at:

C:Program FilesAudio PrecisionAPx500 x.xApiAudioPrecision.API2.dll

where x.x is the version of APx500 you are running.

Using the APx API Wrapper with VEE

To use the wrapper in a VEE program, proceed as follows:

1) Open VEE and add references to both the standard and wrapper APx API .dll files.

Adding references to the APx500 API and API wrapper to the VEE program.

2) Create an instance of the "APx500_Application" object. This is the API object contained in the new DLL. To do so, select a Constructor for the APx500_Application object under AudioPrecision.API2 in the Function and Object Browser.

Creating an instance of the APx500_Application object.

3) Once the instance of the APx500_Application object has been added, you can build your APx500 program by adding a series of .NET operation builders.

Adding a .NET operation to the VEE program.

A simple sample program written in VEE is shown below. It does the following:

  • Opens APx500 with the application window visible.
  • Turns off the signal monitors.
  • Selects the measurement named Frequency Response in Signal Path1.
  • When the Start button is clicked, it sets the start frequency, stop frequency, and analog generator level, and then runs the Frequency Response measurement.

Note that if you open the *.vee file over a network, you may receive .NET security errors, because VEE creates a copy of the AudioPrecision.API2.dll in the folder where the *.vee program is located. You may be able to resolve this in your .NET configuration, or alternatively, just run the *.vee file from a local disc.

 

Completed VEE program  (see larger version)  (download VEE program file).

Using the APx API Wrapper with MATLAB

Our MATLAB code accomplishes the same tasks as the VEE example above. The first three lines reference the API wrapper.

 

MATLAB wrapper example  (see larger version)  (view MATLAB code text file).

Wrap Up

The API wrapper now gives VEE and MATLAB complete access to the APx API. That, along with our existing .NET connectivity and the APx LabView driver, makes it possible to integrate APx into virtually any test and measurement environment.


RELATED DOWNLOADS

APx API Wrapper (for VEE, MATLAB) (185 KB)

This APx API wrapper dll enables you to access the entire APx API when using Agilent VEE and The Mathworks MATLAB. A discussion and instructions are in the kb article "Using APx with VEE." This download is only necessary for APx500 v2.4. APx500 v2.5 and later already include it.

APx VEE Example (7.75 KB)

An Agilent VEE example that opens APx500, makes settings, and runs an acquisition. For more details about controlling APx500 using VEE, read the associated kb article. After downloading, open in a text editor and modify the .NET references to refer to your current version of APx500.