Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA support for C in VS2012/MS2012

I'm not entirely sure I'm using all the correct words, but essentially I have a piece of hardware that uses NI-VISA drivers. I have installed MS Visual Studio 2012, Measurement Studio 2012, and NI-VISA 5.2. When I try to include "Development Support" for "Measurement Studio VC++ 2008," the installation complains that I do not have "Measurement Studio VC++ 2008" (which is true). So, I tried installing "Measurement Studio 2012 for VS2008" and it complains that I do not have VS2008 (which is true). I only need to be able to load a DLL in my C program which relies on NI-VISA. Is it really necessary to have all of this measurement studio stuff?

0 Kudos
Message 1 of 14
(7,015 Views)

You don't need measurement studio for  basic VISA programming.. You will need only visa.lib and visa.h on your development system and visa.dll on both your development and target system. and you have to ensure that the dll is in the systems dll search path and your development environment is configured to find and use the .h and .lib files.

0 Kudos
Message 2 of 14
(7,002 Views)

@qgm wrote:

When I try to include "Development Support" for "Measurement Studio VC++ 2008," the installation complains that I do not have "Measurement Studio VC++ 2008" (which is true).


What do you mean by include "Development Support"?

And why would you want to do that since you have Visual Studio 2010 which is not Visual Studio 2008?

 

 


@qgm wrote:

So, I tried installing "Measurement Studio 2012 for VS2008" and it complains that I do not have VS2008 (which is true).


Again why would you want to do that since you have Visual Studio 2010 which is not Visual Studio 2008?

 

 


@qgm wrote:

 Is it really necessary to have all of this measurement studio stuff?



It isn't necessary to have Measurement Studio to communicate with a piece of test equipment, but Measurement Studio gives you the nice charts and dials etc among other things. That is what you paid for.

 

 

0 Kudos
Message 3 of 14
(6,995 Views)

@mkossmann wrote:

You don't need measurement studio for  basic VISA programming.. You will need only visa.lib and visa.h on your development system and visa.dll on both your development and target system. and you have to ensure that the dll is in the systems dll search path and your development environment is configured to find and use the .h and .lib files.


That's good to hear that I don't need Measurement Studio. I should also say, I'm not sure I will need to do any actual VISA programming, as in I will not need to directly call functions. However, from using DependencyWalker and PE Explorer, it is certainly a dependency for my driver. The situation is that I'm trying to use this beta Windows 7 DLL for the Viewpoint DIO64 card. The installation instructions stipulate that NI-VISA must be installed. I've installed it (and so I get NationalInstruments.VisaNS.dll files in my Program Files (x86) folder and I also have a visa32.dll and visa64.dll in my Windows\System32 folder), but when I try to use "LoadLibrary" in my C program, the system simply hangs (doesn't freeze, spin forever, or use processing power). After some googling, I found this cryptic comment in the NI-VISA 5.2 readme 


NI-VISA 5.0.3 and later have dropped full feature support for Visual C++ MFC 2003 and .NET Framework 1.1. If you need NI-VISA support for the aforementioned languages, you must use NI-VISA 5.0.2 or earlier. For more information on NI-VISA support for .NET Framework 1.1 or Visual C++ MFC 2003, including considerations for users upgrading from NI-VISA 5.0.2 or earlier, visit www.ni.com/info and enter the info code visamvs03.

So, I install NI-VISA 5.0.2 and miraculously, the DLL loads and the exported functions seem to work fine. But then, I went to a different software project and now because NI-VISA 5.0.2 only supports up to .NET3.5, there were a bunch of errors because now for some reason VS2012 was asking for a .NET 3.5 version of  NationalInstruments.Common. I tried adding a reference to it in my VS2012 project settings, and this sounds really stupid and unbelievable, but for some reason even if I were careful to choose the .NET 3.5 version (something of the form 12.0.35.xxxxxx in the MeasurementStudioVS2008\DotNET\Assemblies\Current folder), the .NET 4 one is the only one that it would take (my "target framework" is ".NET4"). I would like to keep with .NET4 if possible lest I upset other dependencies and it should be better (they improve things with newer versions is the thinking...).

So, I went back to trying to get NI-VISA 5.2 installed. I was hoping that it would not take away the stuff that made my DLL finally function, but it seems to have done just that. And the most suspicious thing to me has been this VC++ Development Support stuff that I've seen in the National Instruments Software Uninstall/Change (in Windows 7 Programs and Features). Which is what brought me to the forums.

0 Kudos
Message 4 of 14
(6,985 Views)

Forgot to note, I have tried explicitly putting "visa32.dll" in a folder on my PATH and I have double checked that I have correctly set the PATH variable and that the PATH is in the search locations in my VS2012 project settings.

0 Kudos
Message 5 of 14
(6,984 Views)

Thanks for posting on the NI Discussion Forums.

 

Could you clarify whether you're using ANSI C or a .NET language, such as C# or VB.NET? If your project is written in C and doesn't have any dependencies on NI products beyond NI-VISA, there should be no need to worry about Measurement Studio or the .NET framework. You should be able to reference just the DLL and its header file to call its functions. You should not need to install VC++ Development support in order to obtain this DLL. Just look for the examples under Start>>All Programs>>National Instruments>>NI VISA>>Examples.

 

On the other hand, if you're writing your project in a .NET language such as C#, you will need to install .NET Framework support for NI-VISA. This will enable you to call NI-VISA functions from either C# or VB.NET, but not C++.

 

Visual C++ support is now in legacy status, meaning it is no longer being actively developed. Please see the following article for information on this:

 

https://www.ni.com/en/support/documentation/supplemental/13/version-information-for-legacy-environme...

 

I hope this helps.

0 Kudos
Message 6 of 14
(6,958 Views)

@FrankFurter wrote:

Thanks for posting on the NI Discussion Forums.

 

Could you clarify whether you're using ANSI C or a .NET language, such as C# or VB.NET? If your project is written in C and doesn't have any dependencies on NI products beyond NI-VISA, there should be no need to worry about Measurement Studio or the .NET framework. You should be able to reference just the DLL and its header file to call its functions. You should not need to install VC++ Development support in order to obtain this DLL. Just look for the examples under Start>>All Programs>>National Instruments>>NI VISA>>Examples.

 

On the other hand, if you're writing your project in a .NET language such as C#, you will need to install .NET Framework support for NI-VISA. This will enable you to call NI-VISA functions from either C# or VB.NET, but not C++.

 

Visual C++ support is now in legacy status, meaning it is no longer being actively developed. Please see the following article for information on this:

 

https://www.ni.com/en/support/documentation/supplemental/13/version-information-for-legacy-environme...

 

I hope this helps.


 

So, my ignorance is going to be laid bare. In principle, I think I am using ANSI C. However, I'm using Visual Studio 2012, which I think treats C as C++? Either way, VS2012 labels my project as VS2012 project. However, all my code for sure compiles fine in gcc. The only reason I'm not using gcc is because the hardware is actually on a Windows machine and I already have VS2012 installed. In this case, should the NI-VISA driver work, or do I need to be more specific in VS2012 and really force it to treat my code as ANSI C?

0 Kudos
Message 7 of 14
(6,956 Views)

@FrankFurter wrote:

Thanks for posting on the NI Discussion Forums.

 

Could you clarify whether you're using ANSI C or a .NET language, such as C# or VB.NET? If your project is written in C and doesn't have any dependencies on NI products beyond NI-VISA, there should be no need to worry about Measurement Studio or the .NET framework. You should be able to reference just the DLL and its header file to call its functions. You should not need to install VC++ Development support in order to obtain this DLL. Just look for the examples under Start>>All Programs>>National Instruments>>NI VISA>>Examples.

 

On the other hand, if you're writing your project in a .NET language such as C#, you will need to install .NET Framework support for NI-VISA. This will enable you to call NI-VISA functions from either C# or VB.NET, but not C++.

 

Visual C++ support is now in legacy status, meaning it is no longer being actively developed. Please see the following article for information on this:

 

https://www.ni.com/en/support/documentation/supplemental/13/version-information-for-legacy-environme...

 

I hope this helps.


So, I have since learned that C++ is an extension of C, so I guess in some sense I'm using C++.

 

I have looked at the examples and have tried to add the "#include "visa.h"" and "#include <visa.h>" lines, but seems like VS2012 can't find them. I've searched the "National Instruments" folder in both "Program Files" and "Program Files (x86)" in search of "visa.h" to no avail. However, I do have both "visa32.dll" and "visa64.dll" in my "Windows\System32" folder, so I expect all the drivers that depend on NI-VISA to work.

 

I will not need to directly call NI-VISA functions from C++, but the DIO64 DLL that I will call functions from does depend on NI-VISA. I have tested NI-VISA 5.0.2 and the driver seems to work with that version, but I would prefer to use a version of NI-VISA that supports the .NET4 framework.

 

I must admit, I'm a bit confused on why a DLL will work in one language but not another? I thought the whole point of DLLs was to be language independent?

 

0 Kudos
Message 8 of 14
(6,925 Views)

There is a difference between .NET DLLs and other C/C++ DLLs.

0 Kudos
Message 9 of 14
(6,912 Views)

@FrankFurter wrote:

Thanks for posting on the NI Discussion Forums.

 

Could you clarify whether you're using ANSI C or a .NET language, such as C# or VB.NET? If your project is written in C and doesn't have any dependencies on NI products beyond NI-VISA, there should be no need to worry about Measurement Studio or the .NET framework. You should be able to reference just the DLL and its header file to call its functions. You should not need to install VC++ Development support in order to obtain this DLL. Just look for the examples under Start>>All Programs>>National Instruments>>NI VISA>>Examples.

 

On the other hand, if you're writing your project in a .NET language such as C#, you will need to install .NET Framework support for NI-VISA. This will enable you to call NI-VISA functions from either C# or VB.NET, but not C++.

 

Visual C++ support is now in legacy status, meaning it is no longer being actively developed. Please see the following article for information on this:

 

https://www.ni.com/en/support/documentation/supplemental/13/version-information-for-legacy-environme...

 

I hope this helps.


I looked at the examples and have managed to find the location of "visa.h" and "visa32.lib" In my VS2012 settings, I have added "C:\Program Files (x86)\IVI Foundation\VISA\WinNT\lib\msc" to "Additional Library Directory" and "visa32.lib" to "Additional Dependencies" in the Linker options. I have also added "C:\Program Files (x86)\IVI Foundation\VISA\WinNT\include" to "Additional Include Directories" in the C/C++ options. Finally, I have added "include "visa.h"" to the beginning of my code. Anyway, nothing seems to have changed drastically.

 

I have also tried to import the function in VB.NET. The relevant code is as follows:

    <DllImport("C:\DIO64Visa\DIO64_Visa32.dll", _
                    EntryPoint:="DIO64_OpenResource", _
                    CallingConvention:=CallingConvention.StdCall, _
                    CharSet:=CharSet.Auto)> _
    Public Function DIO64_OpenResource(ByVal resourceName As String, ByVal board As UShort, ByVal baseio As UShort) As Long
    End Function

 Again, the operation just hangs. I've tried changing the calling convention to Cdecl (though the manufacturer has told me that StdCall is correct).

 

Again, any help would be greatly appreciated.

0 Kudos
Message 10 of 14
(6,905 Views)