Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
7 ratings:
 2.42 out of 5     Rate this Document

How Do I Create an Instrument Driver for Visual Basic from the LabWindows/CVI Instrument Driver?

Primary Software: LabWindows/CVI Development Systems>>Full Development System
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: Instrument Drivers/IVI, Measurement Studio>>Visual Basic Support

Problem: How do I use an instrument driver written for LabWindows/CVI in Visual Basic?

Solution: There are two fundamental ways to convert a LabWindows/CVI Instrument Driver to Visual Basic. Both methods require that you have National Instruments Measurement Studio with LabWindows/CVI


METHOD #1 : USE THE COMPONENTWORKS INSTRUMENT DRIVER FACTORY
  1. Launch the ComponentWorks Instrument Driver Factory, which is typically located at Start » Programs » National Instruments » Measurement Studio » Utility Programs » ComponentWorks Instrument Driver Factory.

  2. Follow the on-screen Instrument Driver Factory instructions. The Instrument Driver Factory will automate the driver creation steps using LabWindows/CVI.

  3. When complete, the Instrument Driver Factory will create a ".dll" (Dynamic Link Library, DLL) and ".hlp" file from the original LabWindows/CVI driver.

  4. In your Visual Basic project, select Project » References and select your instrument driver from the list. If your driver is not in the list, then use the Browse button to select your ".DLL" file.

  5. You will now be able to use the functions from the driver in your Visual Basic project. Additionally, The ".hlp" file can be used for online help on the DLL functions.

METHOD #2 : USE LABWINDOWS/CVI TO CREATE THE INSTRUMENT DRIVER

The general procedure for using an instrument driver created for LabWindows/CVI in Visual Basic is to compile the instrument driver files into a DLL that can be called by Visual Basic, the functions for which you can then call from within your Visual Basic code. Below is the procedure for creating the DLL using LabWindows/CVI version 5.5:
  1. Download the LabWindows/CVI driver files.

  2. Launch LabWindows/CVI.

  3. Create a new project by selecting File » New » Project. Accept all defaults on any pop-up windows. You should now be in the project window.

  4. Add the appropriate driver files to the project with Edit » Add Files to Project » All Files. Select the appropriate ".c", ".h", and ".fp" files to include.

    Note that sometimes developers will include LabWindows/CVI user-interface programs with their drivers that should NOT be included. For example, the LabWindows/CVI drivers for the Wavetek 75 include the following files:

      wt75.c
      wt75.h
      wt75.fp
      wt75u.h
      wt75u.c
      wt75u.uir

    In this case, you would only include wt75.c, wt75.h, and wt75.fp, since these files comprise the instrument driver. The wt75u.* files are for a LabWindows/CVI program that uses those drivers, and should therefore not be included.

  5. Double-click on the ".h" file in the project window to open it. Select Options » Generate Visual Basic Include. Take note of the DLL name in the "Confirm DLL Base Name" windows before you click OK, as you will need to know this file name in a future step. This will create the ".bas" module that will be included in the Visual Basic project.

  6. Close the ".h" file and return to the project window.

  7. Select Options » Build Options and change "Default Calling Convention" to "stdcall".

  8. Select Build » Target Type » Dynamic Link Library.

  9. Select Build » Target Settings.

  10. For "Where to Copy DLL", select "Windows System Directory".

  11. For "DLL File", change the DLL's file name to match the DLL Base Name from step 5.

  12. Click the Change button. For "Export What" select "Include File Symbols". Under "Which project include files" check the ".h" file included in your project. Press OK to go back to the project window.

  13. Select Build » Create Dynamic Link Library. The LabWindows/CVI source files will now been compiled into a Dynamic Link Library.

  14. To use the Dynamic Link Library in Visual Basic, you must right click on your project name in the project window, select "Add Module", and select the ".bas" module created in step 5. You should now be able to call any function in that driver from anywhere within your Visual Basic code.


Related Links:
KnowledgeBase 1VCB6D8M: How Do I Use Instrument Drivers/IVI in Visual Basic?
KnowledgeBase 1W9DC4VQ: How Do I Call a DLL Created in LabWindows/CVI from Visual Basic?

Attachments:





Report Date: 12/07/2000
Last Updated: 06/17/2005
Document ID: 246ARVLS

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit