Click to See Complete Forum and Search --> : GPIB instrument control with VC++ .NET


dumbquestion
April 27th, 2005, 08:52 AM
Hi All,

I am searching for a very simple example of GPIB instrument control using Visual C++ .NET. I have searched around and found a bunch of run-around links which have not given any straightforward example. Even searching the National Instruments and Agilent webpages for examples led to nothing obvious for me. Maybe I'm missing something, but can anyone just show a simple example?

I have used Agilent VEE in the past to code Direct IO control of instruments via GPIB. For a simple example, say I wanted to send the "*RST" command to an instrument at address 719 by clicking a button in a form. Does anyone know how to do this?

Any help or links would be greatly appreciated! Oh, and I do not want to use any kits like Measurement Studio. I want very low level control of the instruments.

Thanks!

dumbquestion
April 28th, 2005, 12:24 PM
I got something that works. I had downloaded and installed the Agilent IO Libraries, v14 which creates the directory C:\Program Files\VISA\winnt\include

In this directory are the include files for using VISA com. So I copied "visa.h", "visaext.h", "visatype.h", and "vpptype.h" to my VC++ .NET project directory.

You also need to include "visa32.lib" in your project. This is found under
C:\Program Files\VISA\winnt\lib\msc

So I copied "visa32.lib" to my project directory and then went to the "Project" menu with the "ProjectName Properties" sub-item. Under the "Linker\Input" tree item, there is the box "Additional Dependencies". Enter visa32.lib here and click OK.

For a simple example, I wanted to reset an instrument and query it for its ID string. So in a form with with a button on it, I entered the following code (don't forget to put #include "visa.h" at the top of the form .h file):


private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
ViSession defaultRM, vi;
char buf [256] = {0};

/* Open session to GPIB device at address addrstr */
viOpenDefaultRM (&defaultRM);
viOpen (defaultRM, "GPIB0::19::INSTR", VI_NULL,VI_NULL, &vi);

/* Initialize device */
viPrintf (vi, "*RST\n");

/* Send an *IDN? string to the device */
viPrintf (vi, "*IDN?\n");

/* Read results */
viScanf (vi, "%t", &buf);

/* Close session */
viClose (vi);
viClose (defaultRM);

String *str;
str = Convert::ToString(buf);

MessageBox::Show(str);
}

So this popped up a MessageBox containing the ID string of the instrument at address 19.

It's a simple example, but it shows how you can implement low-level direct IO with instruments via GPIB with VISA com using VC++ .NET. By the way, I was using an Agilent 82357A USB/GPIB converter between my laptop and the instrument. The drivers for this were installed when I downloaded the Agilent IO Libraries, v14. The IO libraries gave the interface the symbolic name "GPIB0"