Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIB and C# in Visual Studio 2010

Everything online is too old.  I can't find any references to NI-488.2 and VS2010.  Here's the deal.  When I upgraded from VS2005 to VS2010 I found out that Microsoft decided they would no longer support the intellisense feature for C++.NET (what a surprise! [dripping with sarcasm]).  This forced me to migrate my code to Visual C#.  No problem really, until I tried to setup my GPIB stuff.  The solutions I find online do not work (a 2005 or 2008 solution does not work on 2010 software).  I can add the assemblies and the VS2010 C# error checker is even fine until I try to compile and then the NationalInstruments.4882 namespace cannot be found.  I am looking for a yes / no answer.  Is there a solution that will allow me to develop GPIB applications with Visual C# on the Visual Studio 2010 IDE?  If the answer is no then I will have to develop applications the old/slow way using C++ and my memory.

 

Thanks,

Mr. Schleprock

0 Kudos
Message 1 of 9
(12,784 Views)

Hi Mr. Schleprock,

 

What do you mean that a 2005/2008 solution doesn't work in Visual Studio 2010?  I was able to open one of the 488.2 examples in Visual Studio 2010 and build/run with no problem.  I opened the SimpleReadWrite example for NI 488.2 in the DotNET3.5 folder. (C:\Users\Public\Documents\National Instruments\NI-488.2\Examples\DotNET3.5\SimpleReadWrite on Windows 7, C:\Documents and Settings\All Users\Documents\... on Windows XP).  The assembly that the example references is NationalInstruments.NI4882.  Do you have this assembly?  What version of the NI-488.2 driver do you have installed?  If you have the latest version and you enabled .NET 3.5 support, you should have all the files you need.

Eric B.
National Instruments
0 Kudos
Message 2 of 9
(12,749 Views)

Hi Eric, thank you for your reply.  I am on a Windows 7 machine.  I also can open and compile and run (using Visual Studio 2010) the SimpleReadWrite in the same path you specified, no problem.  In my C# application that I am developing in VS2010 I added the same two references used in the example to the project.  C:\ProgramFiles(x86)\NationalInstruments\MeasurementStudioVS2008\DotNet\Assemblies\Current\NationalInstruments.Common.dll and C:\ProgramFiles(x86)\NationalInstruments\MeasurementStudioVS2008\DotNet\Assemblies\Current\NationalInstruments.NI4882.dll.  I then try to add the 'using NationalInstruments;' (note that the intellesense feature did not recognize the NationalInstruments namespace) to my .cs file and I get the following compile error...

 

error CS0246: The type or namespace name 'NationalInstruments' could not be found (are you missing a using directive or an assembly reference?)

 

Now, if I add to the project the reference C:\ProgramFiles(x86)\NationalInstruments\MeasurementStudioVS2008\DotNet\Assemblies\Current\NationalInstruments.Common.Native.dll then the intellisense feature works and shows the NationalInstruments namespace when I add the 'using NationalInstruments;' to my .cs file.  Then the app compiles with no errors but does give the following warnings...

warning MSB3253: The referenced assembly "NationalInstruments.Common, Version=8.7.35.131, Culture=neutral, PublicKeyToken=18cbae0f9955702a, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

 

warning MSB3253: The referenced assembly "NationalInstruments.NI4882, Version=8.9.35.104, Culture=neutral, PublicKeyToken=18cbae0f9955702a, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project

 

The intellisense does not recognize the NI4882 namespace, there is only 'using NationalInstruments.Restricted;' available.

Now, if I remove the reference to the NationalInstruments.Common.dll file then the intellisense DOES recognize the NI4882 namespace and I can add the 'using NationalInstruments.NI4882;' directive to my .cs file.  If I try to compile the app I get the following error because of the NI4882 namespace...

error CS0234: The type or namespace name 'NI4882' does not exist in the namespace 'NationalInstruments' (are you missing an assembly reference?)

 

My Measurement and Automated Explorer is version 4.6.2f1 and shows the 488.2 version as 2.73.  I don't have a problem with this machine AND VS2005 AND NI4882 nor this machine AND VS2010 AND NI4882 with the example program.

I went ahead and reran ni4882273.exe and reinstalled the software.  There was an error if I tried to install support for the .NET framework 1.1.  The installer complained that .NET Framework 1.1 was not present.  I went back and deselected the support for .NET 1.1 and the rest of the installation went fine.

Now you see why I am such a schleprock.

Thanks again,

Schlep

0 Kudos
Message 3 of 9
(12,745 Views)

Hi Schleprock,

 

on monday I will start programming  a GPIB application in C#. Today I want to find out if the NI-VISA is compatible with Visual Studio 2010 or if I have to downgrade to VS2008. In the installation readme of the latest NI-VISA 5.0.1 (http://ftp.ni.com/support/softlib/visa/NI-VISA/5.0.1/win/readme.html) I don't see any support for VS2010. But I want to try it since I would like to use the latest VS.

 

Concerning you compilation problem I suggest you target your solution to a .NET 3.5 application in order to be VS2008 compatible.Currently your solution is targeted to .NET framework version 4.0 which is default in VS2010 but probably not appropiate for NI-VISA.

 

In the VS2010 Solution Explorer right click on every project within your solution and choose 'Properties'. In the first line  under ''Application' you find the combo box entitled 'Target framework". Currently ouy have choosen '.NET Framework 4.0'. Change it to '.NET Framework 3.5' and recompile your solution. This way you should at least get rid of the compiler warnings you described.

 

Please tell me how did you install the NI-VISA? Did you download the 'visa501full.exe' and just installed it? I want to setup a new computer with XP Prof SP3, VS2010 and NI-VISA. Did you face any installation problems with the NI-VISA?

 

Regards,

Wernherr

0 Kudos
Message 4 of 9
(12,723 Views)

Hi Wernherr,

 

Thank you, reverting the target framework back to .NET 3.5 did take car of my compilation namespace problem, once I removed the reference to NationalInstruments.Common.Native.dll and replaced it with NationalInstruments.Common.dll (which makes sense to me).  I can now continue with my C++ to C# application conversion.

 

Please excuse my ignorance but I really don't know anything about NI-VISA.  When I look in ControlPanel->ProgramsAndFeatures I only find "National Instruments Software".  When I run the install program for the NI-488.2 the window that lists the default software/features that will be installed shows that the NI-VISA 4.6 is not selected.  When I run the National instruments  'Measurement and Automation' application and look under software I do not see any reference to VISA,  so I don't even know if VISA support is installed (or wheather it is required for C# development).

 

I'm glad I could point out something that might not have been addressed yet, but that's because I'm really good at breaking things (or should I say, try to use them in a way the designers never intended).

 

Thank you again, and let me know what your conclusions are as I would like to be able to change the target back to .NET 4.0 at some time.

 

Shlep

 

0 Kudos
Message 5 of 9
(12,705 Views)

Schleprock,

 

The current version of VISA (5.0.1) does not currently have support for the .NET Framework 4.0, so it makes sense that you wouldn't be able to create a project that targets that framework.

 

A little background on the drivers: NI 488.2 is the driver that is required to communicate with your GPIB device.  NI VISA is a driver that sits on the 488.2 driver that makes for easier development for multiple types of instruments (GPIB, Ethernet, USB, Serial, etc), including your GPIB device.  You can use the 488.2 driver by itself, but you will find that it is easier to just use the NI-VISA driver instead.

 

I'd recommend installing VISA (when you open the list of programs installed, you can go to National Instruments Software and click Change/Remove to bring up a dialog with all of the NI software present on your machine...from there you can uninstall or repair installed software) and installing support for the 2.0 or 3.5 framework, then using Visual Studio 2010 to develop a project that supports one of those frameworks.  At some point, there will be a version of VISA that supports the .NET Framework 4.0, but at this time, there is not one available.

Eric B.
National Instruments
0 Kudos
Message 6 of 9
(12,701 Views)

Hi, not sure this is the right place for this but I have a small problem.

Background: I am developing programs for the mobile industry where we are using NI-VISA for communication. The user has to install that themselves in order to run our programs. But they also need to install a few other things and too many times they forget to install NI-VISA 😞

So, what I am actually wonder is if there is a great way to check if NI-VISA is present from my program? Of course there is a possibility to read the registry but I can't be sure of the name for future releases of NI-Software can I? 
What I would like to do is in my program perform a test or something to see if NI-VISA is installed.

Can someone give me a clue?

0 Kudos
Message 7 of 9
(12,158 Views)

Hi Mikla,

 

Why not simply attempt to open a VISA session and attempt to catch an error if it fails to open a session. Other than checking the registry for an entry, or manually checking MAX to see if the driver has been installed, I don't believe there's a programmatic way of identifying the installation of VISA on a machine.

Raj
National Instruments
Applications Engineer
0 Kudos
Message 8 of 9
(12,117 Views)

Hi,

 

I found this article very useful - I'm a complete novice at GPIB interfacing and am just updating a legacy VB6 system using GPIB (via gpib-32.dll) to work with 3 devices to a C# version in VS2010.

 

I am hoping that the pointers above will avoid a few hours of hair tearing !

 

Thanks guys! 

 

 

0 Kudos
Message 9 of 9
(10,608 Views)