Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

I need the equivilent of Hello World for a C program that calls a GPIB instrument over VISA.

I have VISA installed.  I also use LabVIEW all the time for automated programs.
 
But today I want to create a simple C program that uses VISA to send an *IDN? command to an instrument, and then reads back the result.  This is the hello world program that will get me off the ground.
 
I have no idea where to start in terms of setting up the C variables, which functions to call in which order to establish a VISA connection so I can send my command and read the results.
 
I did some searches, but did not find any good matches.
 
I am going to write this C code in Dev-C.  (I do not have LabWindoes.) 
 
If it helps, my motivation is to create a very small executable that I can use to make simple measurments.  For complex tasks, I use LabVIEW.  But LabVIEW is overkill for some simple tasks. 
 
I appreciate any help from someone who knows how to do this without even thinking.  Thank you in advance,
 
Mike
0 Kudos
Message 1 of 4
(3,943 Views)
Hey Mike!
How are you doing?  If you have the drivers installed, you should have examples in different programming languages in the following directory:

C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples. 

These examples should get you started!
Best Regards,
Song Mu
National Instruments San Diego
0 Kudos
Message 2 of 4
(3,926 Views)

Hi Song,

Well, I knew what I was looking for must be out there somewhere.  But is nearly overwhelming to start looking...  : )

The path is slightly different, but the example here:

C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\C\General\RdWrt.c

is what I was looking for.

For anyone else doing this with Dev-C++, I downloaded version 4.9.9.2 from the internet, and it installed with no issues.

I then created a new project, and added the above example file "RdWrt.c" to the project.

I set the project type to console, and I selected "C" program, not C++.

I had to change the # include visa.h to be  #include "C:\VXIPNP\WinNT\include\visa.h"  (Is this the right way to do this?  It works...)

Then I added the library to the linker by selecting Project -> Project Options and then the Parameters tab in the dialog box.

The press the add libarary or object button, and I selected the path C:\VXIPNP/WinNT/lib/msc/visa32.lib  In this case, the msc library worked for me in Dev-C++.  I don't know if this means all of needed VISA functions are now available to me or not.  But so far this works.

Next select Execute -> compile, followed by Execute -> run.  And this works.  Smiley Very Happy  You have no idea how good it feels to reach this point.  I estimate it took me about 2 days, with many wrong turns, and with a lot of internet reading before settling on Dev-C++ as the IDE.  At this point, I have a "hello GPIB instrument" executable, and I think I will be able to do whatever I need to from here.

I hope this is useful information for others.  And thanks for your help.

Mike

 

0 Kudos
Message 3 of 4
(3,917 Views)
Glad I could help!
Best Regards,
Song Mu
National Instruments San Diego
0 Kudos
Message 4 of 4
(3,907 Views)