Modifying IVI Instrument Driver VIs for Improved Error Handling
Overview
The IVI driver VIs available on the Instrument Driver Network (www.ni.com/idnet) have been updated to correct two potential problems with error handling. National Instruments has updated the IVI-C Instrument Driver Conversion Tools for LabVIEW to build VIs to correct these potential problems.
If you cannot download updated IVI instrument driver VIs from National Instruments or another manufacturer you can do one of the following:
- Use the IVI-C Instrument Driver Conversion Tools for LabVIEW, available for download from the Instrument Driver Network (www.ni.com/idnet) to convert the instrument driver VIs.
- Edit the instrument driver VIs to fix the problems using the Initialize With Options and Close templates provided, as described in the Solution section.
Table of Contents
Background
The following two sections describe the two problems with the IVI instrument driver VIs. Race Conditions Problem
VIs on the LabVIEW block diagram do not necessarily run to completion before another VI executes. For example, if you use two or more Initialization VIs on the block diagram to open sessions to two or more instruments, it is possible for one Initialization VI to start executing before the other(s) complete execution. Therefore, it is possible that if an error occurs when the session opens, another session might open before LabVIEW can clear the error.
Persistent Error Problem
Each instrument driver Close VI includes an Error Conversion VI, which handles any errors LabVIEW or the driver .DLL found during execution. An example block diagram for an instrument driver Close VI appears in the following figure.
The Call Library Node unconditionally calls the DLL that closes the IVI session. If the DLL detects an error, it passes the error number (a signed 32-bit integer) to the Convert Errors VI.
Due to the way the Convert Errors VI is written, the calls to the error-handling functions in the DLL are not made if an error was detected in a subVI executed prior to the Close VI, such as an error from the Initialize VI. For example, if you do not power up your instrument and run the Initialize VI, the Initialize VI returns an error. However, the Convert Errors VI in the Close VI does not retrieve and clear the error because the error in input already contains error information. Therefore, the close error remains in the thread local storage and cannot be retrieved even if you turn on the instrument and rerun the VI.
Solution
Use the Prefix Initialize With Options and the Prefix Close template VIs to modify the Initialize with Options, Initialize, and Close VIs for your instrument driver so that they call the IVI Engine InitAndGetError and CloseAndGetError functions.
Refer to the following sections for information about how to modify these VIs.
Note: If you use the template VIs described in the following procedures, any context help information you wrote for the VI must be copied into the VI Properties dialog box, Documentation page of the template VIs for the documentation to appear in the context help window. Also, any context help information that you wrote for the controls and indicators must be copied to the Documentation tab of the control or indicator property dialog box for the documentation to appear in the context help window.
Modifying the IVI Initialize VIs
Complete the following steps to modify the Initialize VIs for your instrument driver and to update the Initialize with Options VI to the correct race conditions.
Initialize with Options VI
1. Download the Initialize With Options.vit template VI (see link below) to a directory on your computer.
2. Open the Initialize with Options template.
3. Replace Prefix with the prefix name of the instrument driver you are using in the prefix string constant. For example, enter fl8840a for the Fluke 8840A Digital Multimeter IVI driver, as shown in the following block diagram.

[+] Enlarge Image
4. Replace prefix_32.dll with the name of the DLL the instrument driver calls in the module path. For example, enter fl8840a_32.dll to communicate with the DLL for the Fluke 8840A Digital Multimeter IVI driver, as shown in the previous block diagram.
5. Save the VI as Prefix Initialize With Options.vi, where Prefix is the prefix name of the instrument.
Note: You can overwrite your existing Prefix Initialize With Options VI for this instrument with the new Prefix Initialize With Options template VI.
Initialize VI
6. Open the Prefix Initialize VI that you want to use, where Prefix is the prefix name of the instrument.
7. Replace the Prefix Initialize With Options VI with the VI that you previously saved in the step 5. Refer to the LabVIEW VI, Function, & How-to Help>>Replacing Block Diagram Objects topic for more information about replacing VIs with other VIs.
8. Save and close the Initialize VI.
Modifying the IVI Close VI
This section describes the modifications that you can make to the VIs that close IVI sessions.
1. Download the Prefix Close template VI (see link below) to a directory on your computer.
2. Open the Prefix Close template VI.
3. Save the template VI as Prefix Close.vi, where Prefix is the prefix name of the instrument.
Note: You can overwrite your existing Close VI for this instrument with the new Close VI.
4. Replace the Close VI on the block diagram of any VI that calls the instrument with the VI that you saved in the previous steps. Refer to the LabVIEW VI, Function, & How-to Help>>Replacing Block Diagram Objects topic for more information about replacing your current VIs with other VIs.
Related Links:
Template VIs to Modify IVI Instrument Driver VIs for Improved Error Handling
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
