C Interface Generator for LabVIEW Project-Style Instrument Drivers Readme (Windows Only)

August 2006

This file contains important information about the C Interface Generator for LabVIEW Project-Style Instrument Drivers. The C Interface Generator for LabVIEW Project-Style Instrument Drivers creates wrapper DLLs with a user-friendly C programming language interface for project-style LabVIEW instrument driver VIs that you specify. With the C Interface Generator for LabVIEW Project-Style Instrument Drivers, you can quickly and easily reuse existing LabVIEW instrument driver functionality in a C programming environment.

System and Tool Requirements
Converting LabVIEW Project-Style Instrument Drivers to C Instrument Drivers
C Interface Generator for LabVIEW Project-Style Instrument Drivers Dialog Box
Working with the Converted Instrument Driver DLLs
Known Issues
Copyright

System and Tool Requirements

You must have the following software installed before you can install and use the C Interface Generator for LabVIEW Project-Style Instrument Drivers:

Note  The C Interface Generator for LabVIEW Project-Style Instrument Drivers supports only LabVIEW project-style instrument drivers. For a complete list of LabVIEW project-style instrument drivers, you can search the Instrument Driver Network at http://www.ni.com/devzone/idnet/. Click Search Drivers and select Plug and Play (project-style) in the Technology listbox.

Converting LabVIEW Project-Style Instrument Driver VIs to C Instrument Drivers

The C Interface Generator for LabVIEW Project-Style Instrument Drivers generates a C interface for your instrument driver VIs by creating the following important files:

The C Interface Generator for LabVIEW Project-Style Instrument Drivers has two configuration modes (basic and advanced). The advanced mode provides more settings and options when creating the DLL and header files. If you are not familiar with LabVIEW instrument drivers, use the basic configuration.

Complete the following steps to create a C interface for the VIs in your LabVIEW instrument driver.

  1. If you have LabVIEW 8.0 or LabVIEW 8.2, select Tools»Instrumentation»Generate C Interface for LabVIEW Driver. If you have a previous version of LabVIEW, select Tools»Generate C Interface for LabVIEW Driver. LabVIEW launches the C Interface Generator for LabVIEW Project-Style Instrument Drivers dialog box.
  2. Select the Basic or Advanced option and click the Next button.
  3. Enter the path to and filename of the Project library (.lvlib) file that contains the instrument driver VIs you want to convert. You also can use the Browse button to navigate to and select a file.
    Note  Only .lvlib files compatible with LabVIEW 8.0 or LabVIEW 8.2 are supported.
  4. Select the Project library (.lvlib) file and Destination Directory and click the Next button.
  5. Select the files you want to generate and click the Next button.
  6. Review and edit the instrument driver information, if necessary, and click the Next button. LabVIEW includes this information in the generated DLL.
  7. (Advanced configuration only) Select which functions to generate by adding or removing checkmarks in the checkboxes to the left of each function. You also can double-click a function name to edit it. The number in the upper right corner of the listbox indicates the number of functions currently selected. Click the Next button.
  8. (Advanced configuration only) Review and edit the documentation conversion tasks for each generated function. Documentation conversion includes searching and replacing strings within the functions to be generated. You can complete any of the following tasks:
  9. Click the Next button.
  10. Click the Accept or Skip button to accept or skip each proposed change. Click the Accept All or Skip All button to accept or skip all remaining instances of proposed changes. You can edit the help text directly by clicking inside either text box.
  11. Review the summary of conversion tasks and click the Next button to convert the LabVIEW instrument driver.
  12. (Optional) Click the View the Report button to view the conversion report.
  13. (Optional) If you have installed LabWindows™/CVI™, you can click the View Driver In LabWindows/CVI button to review the generated C interface in LabWindows/CVI.
  14. Click the Finish button.

C Interface Generator for LabVIEW Project-Style Instrument Drivers Dialog Box

If you have LabVIEW 8.0 or LabVIEW 8.2, select Tools»Instrumentation»Generate C Interface for LabVIEW Driver to display this dialog box. If you have a previous version of LabVIEW, select Tools»Generate C Interface for LabVIEW Driver to display this dialog box.

Use this dialog box to create C-compatible DLL and header files based on LabVIEW instrument driver VIs.

Note  All generated DLL files require run-time support. You must install the LabVIEW Run-Time Engine as well as VISA to use the DLLs created by the C Interface Generator for LabVIEW Project-Style Instrument Drivers.

This dialog box includes the following pages and components:

Working with the Converted Instrument Driver DLLs

The following partial code sample demonstrates how you might get started with the code converted for the Agilent 34401 instrument driver to retrieve error information. This project library (Agilent 34401.lvlib) is available in the labview\instr.lib\Agilent 34401 directory.

Note  You cannot use the instrument driver session handle returned by the initialize ( ) function with VISA function calls. Only other instrument driver functions can use the handle.

#include "ag34401.h" // the generated wrapper header file

#define STR_LEN 256

#define ELT_LEN 1024



/* Return value of wrapper function call. VI_SUCCESS for success */

ViStatus result = VI_SUCCESS;



/* VISA Resource Name */

ViRsrc VISAResourceName = "GPIB0::22::INSTR"; // VISA Resource Name



/* VISA Session */

ViSession session = VI_NULL;



/* Used for getting string information*/

ViChar BufferString[STR_LEN] = {0};

ViInt32 BufferStringSize = STR_LEN;

ViInt32 BufferStringActualSize = 0;



/* Used for getting measurement points information*/

ViReal64 BufferPoints[ELT_LEN]={0.0};

ViInt32 BufferPointsSize = ELT_LEN;

ViInt32 BufferPointsActualSize = 0;



/* The instrument driver session handle returned by the Initialize ( ) function cannot be used with VISA function calls. The handle only can be used by other instrument driver wrapper functions. */



result = ag34401_initialize (VISAResourceName,
VI_TRUE, // Is Query
VI_TRUE, // Is Reset
BAUDRATE_VAL5_9600, // Baud Rate
PARITY_VAL2_EVEN, // Parity
DATABITS_VAL0_7, // Data Bits
&session);


/* Check for errors. You can call GetLastErrorMsg() following each instrument driver wrapper function. */



if (VI_SUCCESS != result)

{

/* Be sure to use GetLastErrorMsg() to retrieve error information instead of any other functions. The wrapper driver remembers the latest error in a VISA session. You can specify the VISA session to get the latest error information belonging to that VISA session. Once GetLastErrorMsg is called, it clears the latest error information. */



ag34401_GetLastErrorMsg (session, //VISA session
BufferStringSize, // Indicate the buffer size
BufferString, // Buffer to receive error message
&BufferStringActualSize // Integer variable to receive number of bytes actually copied to the buffer

);

}



/* Do configuration work here*/

result = ag34401_ConfigureTrigger (session,
&TRIGGERSOURCE_VAL0_IMMEDIATE, //Trigger Source
&VI_TRUE, //Auto Delay
&0.0); //Manual Delay


/* You can put check code here if you want

if(VI_SUCCESS != result) { ag34401_GetLastErrorMsg (?..);}*/



/* Read the measurement data* /

result = ag34401_ReadMultiplePoints (session,
&256, // SampleCount,
&10000,// Timeout,
&BufferPointsSize, // Indicate the buffer size
&BufferPoints, // Buffer to receive measurement data
&&BufferPointsActualSize // Integer variable to receive number of points actually copied to the buffer
 

);

/* You can put check code here if you want*/



/* Include other instrument driver calls, such as configure and read functions */



/* Make sure to close the VISA session when all jobs are done.*/



result = ag34401_Close(session);



The C Interface Generator for LabVIEW Project-Style Instrument Drivers also can build an installer if you select the Generate driver installer option. To use this feature, the target computer must have the LabVIEW Run-Time Engine installed with the same version as the LabVIEW environment.

Once you have initially converted your instrument drivers, you might want to update the wrapper code. If you have LabWindows/CVI 7.0 or later, you can modify the generated C source files in LabWindows/CVI and then rebuild the wrapper driver, but you may not create the installer directly within LabWindows/CVI. After you modify the source code, you can recreate the installer using Rebuild.vi, available in your LabVIEW installation directory at labview\project\_DriverLVtoC\ReBuild Installer. Select the LabWindows/CVI project file, fill in the destination folder, and click Rebuild. The new generated wrapper driver and its installer will be saved to the destination folder.

Known Issues

Refer to the KnowledgeBase for the latest information about the C Interface Generator for LabVIEW Project-Style Instrument Drivers.

This product includes software developed by the Apache Software Foundation (http://www.apache.org).

Copyright © 1999 The Apache Software Foundation. All rights reserved.

Refer to XercesLicense.txt in the labview\project\_DriverLVtoC directory for more information about the Apache Software License.


© 2006 National Instruments Corporation. All rights reserved.