How to Use NI-VISA with C in Visual Studio

Updated Mar 29, 2023

Reported In

Software

  • Microsoft Visual Studio

Driver

  • NI-VISA

Operating System

  • Windows

Programming Language

  • C

Issue Details

I want to use NI-VISA with C in Visual Studio. Where can I find examples, and how can I compile them in Visual Studio?

Solution

NI-VISA comes with a full C API and examples ready to use with Microsoft Visual Studio. To access those examples and successfully compile them in Visual Studio, follow these steps:



1. Make sure you installed the NI-VISA C Examples using NI Package Manager:
NI Package Manager cropped.JPG

2. Afterwards, you will find examples for NI-VISA on your computer in the following folder:
C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\C 

3. An extensive explanation and discussion of the NI-VISA C Examples can be found here:

https://www.ni.com/docs/de-DE/bundle/ni-visa/page/ni-visa/introprogrammingexamples.html  


4. The full NI-VISA C API is explained here:

https://www.ni.com/docs/en-US/bundle/ni-visa/page/ni-visa/help_file_title.html

Additional Information

For backwards compatibility, all Visual Studio examples are organized using a Visual Studio 2005 solution file. The different examples are then organized as projects within that solution. To facilitate that Visual Studio 2005 solution and its structure with newer versions of Visual Studio, you might need to perform some upgrade steps. As an example, the upgrade steps for Visual Studio 2022 are:
 

1. Go to the Windows folder
C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\C

and open Examples_MSVC_VS2005.sln using Visual Studio 2022.
 

 

2. Allow Visual Studio 2022 to automatically upgrade the solution.


3. Manually add the NI-VISA libraries to the projects' dependencies.
 
  • Within Visual Studio 2022, in the Solution Explorer, choose one of the listed projects. Expand the file tree to show Library Files.
Visual Studio Solution.JPG
 
  • Right-Click on Library Files. In the Context Menu, choose Add, then Existing Item...
Add Libraries.JPG

 
  • A file dialog window opens. Within the dialog, add one or both of the following files:
 

for x64 compilations:

C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Lib_x64\msc\nivisa64.lib

for x32 compilations:

C:\Program Files (x86)\IVI Foundation\VISA\WinNT\lib\msc\visa32.lib
 
  • You will have to add the NI-VISA libraries for each project separately. To do that quick, after the first import, you can drag-and-drop or copy-paste the library files within the Solution Explorer.
 
drag-and-drop:
Press (and hold) the CTRL key. With the left Mouse button, click on the library file and hold the button. Now move the Mouse until it hovers over another project's Library Files folder. Release the Mouse button.

copy-paste:
Right click on the library file. Within the context menu, choose Copy. Afterwards, right click on another project's Library Files folder. Within the context menu, choose Paste.