05-18-2010 07:30 PM
I am trying to use the NI GPIB interface in a .NET application developed in Visual C++ 2008 Express edition, without success so far. I tried simply adding a "using namespace NationalInstruments::NI4882;" line in the "using" section of the main form and including NationalInstruments.NI4882.dll in the project files of the solution explorer. This resulted in the error: "...'NationalInstruments' : is not a class or namespace name" during compilation.
Is it possible to use this .NET interface (MeasurementStudioVS2005\...) with VC++? How? Are there any examples available?
TIA, dean
05-19-2010 04:15 PM
Hi Dean,
I wasn't sure if you are currently using NI Measurement Studio, but if you are and with support for Visual Studio enabled during driver installation, you should have access to examples in the C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\MStudioVCxxxx folder.
Otherwise, you need to manually include the NI 488.2 object dependency within your Visual C++ project. For this, open the project properties window and expand the Configuration Properties tree. Be sure to include the path to the folder containing the ni4882.obj (C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc, for a 32-bit system) in the General tab under C/C++ and the ni4882.obj file as an additional dependency in the Input tab under Linker.
I hope this helps!
05-20-2010 01:49 PM
Thanks for taking the time to put that answer together. I don't have measurement studio, and there is no ni4882.obj on my system. There is a gpib-32.obj and a ni4882.h, but using those in a Visual C++ 2008 project hasn't worked for me so far. Using the approach outlined by Swathi B and #including the ni488.2 and windows.h headers in the form.h file of my test program results in a project which compiles, but which triggers an access violation exception on the first call to a gpib function (ibfind). I wonder if anyone has gotten this to work, and if example code is available?
The "old-fashioned" interface (ni4882.h, gpib-32.obj) approach wasn't the one I was trying to get working, though. I was trying to get the NI .NET interface to work with this development environment. I am using (or trying to use) the ".NET framework 2.0 languages support" from my NI488.2 ver. 2.5 driver disk. dean
05-21-2010
05:37 PM
- last edited on
02-06-2025
01:23 PM
by
Content Cleaner
Hi Dean,
I believe the ni4882.obj comes with the latest NI-488.2 driver (version 2.7.3). If there isn't a specific reason for using the 2.5 version, I would recommend upgrading to the latest version. You could also download the NI Measurement Studio 30-day trial for use with Visual Studio .NET.
Have a great weekend!
05-26-2010 08:20 PM
Looke like you are using C++/CLI (managed version of C++). If so ni4882.obj and gpib-32.obj can't be used directly because they are just import libraries of native DLL. Instead, you should use .NET interop assembly, which allows your app to indirectly access the GPIB-32.DLL.
NI provides .NET assembly to GPIB:
C:\Program Files\National Instruments\MeasurementStudioVS2008\DotNET\Assemblies\Current\NationalInstruments.NI4882.dll
or if you install IVI/VISA Shared Components, you will have:
C:\Program Files\IVI Foundation\VISA\VisaCom\Primary Interop Assemblies\Ivi.Visa.Interop.dll
Your app project needs to add reference to either assembly.
06-01-2010 02:00 PM
I've tried installing the latest version of the GPIB utilities and drivers, version 2.73. I have both a header file available (c:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\include\ni4882.h) and the .dll (C:\Program Files\National Instruments\MeasurementStudioVS2008\DotNET\Assemblies\Current\NationalInstruments.NI4882.dll). I have added a reference to ni4882.h to the "stdafx.h" file of my project, and I've added the .dll to the project by right clicking on the project name, selecting "Add | Existing item" and entering the above path and file name.
The linker, however, is not satisfied. I get errors like "unresolved token (0A00000E) "extern "C" int __stdcall ibfindA(char const *)" and "unresolved external symbol "extern "C" int __stdcall ibfindA(char const *)." So I'm back to my original question: Is it possible to use this .NET interface (MeasurementStudioVS2008\...) with VC++? How? There must be some way (that I'm missing) to let the linker know that the code referred to in ni4882.h is contained in NationalInstruments.NI4882.dll... dean
06-03-2010 11:34 AM
Hi Dean,
So there are a few changes you need to make to enable use of .NET modules in Visual C++. With a C++»General»Empty Project, I added a source file and right clicked on the project properties to enable common language runtime support.
I then added a reference to National Instruments 488.2 .NET from the right-click menu and the subsequent Add New Reference dialog.
I was then able to run some simple code demonstrating successful use of the NI-488.2 Device class, with the following statements included.
using namespace System;
using namespace NationalInstruments::NI4882;
Let me know if this helps!
06-03-2010
05:23 PM
- last edited on
02-06-2025
01:23 PM
by
Content Cleaner
Thanks, Swathi, that did help.
Here are my minimal instructions for anyone wanting to use the NI .NET gpib interface in MSVC++ (or, I guess, any of the other Visual Studio languages) without the aid of Measurement Studio or a safety net:
- Install NI's gpib drivers, from here for example:
https://www.ni.com/en/support/downloads/drivers/download.ni-488-2.html
- Create the project: start MSVC++, go to File | New | Project, select Project type: CLR, Template: Windows Forms Application, give it a name, then OK. MSVC++ creates a new "solution" and a form appears, Form1.
- Add the NI .NET interface to the project: go to "Project | Properties" (Alt-F7). Under Common Properties, select Framework and References, then click on the "Add new reference" button, and select the "National Instruments 488.2" .NET interface, then OK.
- Add an object to your code to represent your GPIB device (my test device is an oscilloscope): at the top of your form's class definiiton, i.e. just below the lines
public ref class Form1 : public System::Windows::Forms::Form
{
add the line:
private: NationalInstruments::NI4882::Device^ scope;
- Add visual controls: from the control "Toolbox" on the right of the IDE, place a list box and a button on the form.
- Add code to initialize communications with your GPIB device: single-click on the form background, then select the "Properties" editor on the right of the IDE, click on the "Events" button (lightening bolt icon) at the top, and double-click the empty field to the right of "Load" in the "Behavior" category. The editor will create the outline of a function which will be executed when the form is created; add the line
scope = (gcnew NationalInstruments::NI4882::Device(0, 1));
to that function. This creates an instance of our scope object on the GPIB interface with address 0. The scope is at address 1.
- Add code to communicate with your GPIB device: go back to the "Design view" of your form. Double-click on the button you placed on the form. The editor will create another function to be executed when you press the button. Add the following code to this function:
System::String^ idn; scope->Write( "*IDN?" ); idn = scope->ReadString(); listBox1->Items->Add( idn );
-Compile, link and run the program. Each time you click on the "button1" button, the ID string returned from your GPIB device should be added to the list box.
HTH!, dean
12-18-2013 07:09 AM
Hey,
I got a short question:
Is there any Documentation for the ni4882.dll in use with C++/CLI?
Where did you find those things like Device->Write(..) and stuff?
Regards,
Daniel
12-19-2013
11:59 AM
- last edited on
02-06-2025
01:25 PM
by
Content Cleaner
Hi Daniel,
To my knowledge, there is no documentation dealing directly with C++/CLI. However, there is for C++. As far as the functions, this link provides an overview of each function provided in the NI 488.2 API:
https://www.ni.com/docs/en-US/bundle/321038g/resource/321038g.pdf
Additionally, here is a link to the NI 488.2 User Manual:
https://www.ni.com/docs/en-US/bundle/ni-488.2-user-manual/resource/370428w.pdf