02-13-2011 12:56 AM - edited 02-13-2011 12:57 AM
I am using VISA to control a network analyzer through Visual Studio and am running into issues with getting the data using the viScanf().
The code below is a snippet of my source code. The programmers reference guide for the network analyzer sates that the "CALC1:MARK:REF:X?" command will return the frequency of the marker in NR3 format (IEEE floating point standard).
I figure that since it is returning the info in floating point format that I should read it in as a float. Am I using the viScanf() correctly in this situation?
I initialize the "data" variable to 6 just to see if anything changes, which it doesn't. All I want to do is get the reading of 260 MHz.
Any help is appreciated.
float data = 6;
viPrintf(instr, "FORM:BORD NORM\n");
viPrintf(instr, "FORM:DATA REAL,32\n");
viPrintf(instr, "CALC1:MARK1 ON\n");
viPrintf(instr, "CALC1:MARK1:X 260 MHz\n");
viPrintf(instr, "CALC1:MARK:REF:X?\n");
viScanf(instr, "%f", &data);
printf("%f",data);
Thanks,
Nathan
02-13-2011 12:19 PM
Hi Jeff
The way your trying to access the VISA gpib driver is a very old style method there
are much new methods to access VISA gpib devices.The IVI foundation , NI & others
have updated the VISA GPIB driver to make things easier but not left much of real
programming example documentation trail .
If you look here at this post it shows the names of classes inside the driver
http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/How-to-get-VISA-GPIB-to-work-in-Excel-Excel-V...
This example is for visual basic 6 , the methodology will be different in visual C or C++ but the classes names will be similar.
In C/C++, you must tell the compiler where to find the include and library files are and make sure these paths include the
“VISA COM 3.0 Type Library”. Using the C++ statement either / or
#include "stdafx.h"
#import "C:/Program Files/IVI Foundation/VISA/VisaCom/GlobMgr.DLL" no_namespace named_guids
I have have not used visual C yet . These two link may help you also but its is mainly about using IVI drivers.
http://www.ivifoundation.org/downloads/IVI%20short%20guides%20May%205-6%20%2009/IVI%20GSG%20C++_May%...
http://www.kikusui.co.jp/download/doc/KivisaGuide_J.pdf
Another place to look is on your own machine if you are using a NI VISA driver. Look in this location on your machine
C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\C
This shows you examples of the more old school way your trying to do things which may help you. This is similar
to the way your trying to write your program at the moment.
The latest NI VISA drivers are located here. http://ftp.ni.com/support/softlib/visa/NI-VISA/
Make sure you read the help file to get the correct versions. In some of the newer NI VISA versions
they are retiring some of the older NI VISA/GPIB functions and this may create an issue for you.
If you want some good examples of programming using Microsoft Visual C from VS6 to VS2005.NET
look here . This is for measuring phase noise with a spectrum analyser . But there is a very good
example of how to program in C. This is only for ni488, which is the fore number to NI VISAGPIB
http://www.thegleam.com/ke5fx/gpib/setup.exe
Install it and look here C:\Program Files\KE5FX\GPIB\gpiblib
According to the author of this code. The code compilable with any version of MSVC from VS6 to VS2005.NET,
including the free Microsoft Visual Studio Express package. But you use it at your own risk.
Agilent also have a lot of good stuff. See here as examples. But remember aligent also have a lot
customer drivers stuff. Which may be a good idea to stay away from if possible. It can give
code transportablity issues when using NI drivers. But its still useful to read.
http://www.xtest.at/download/manual_iolib_suite_connectivity_guide_May2006.pdf
I know this is a bit rambling but I have tried to give you a dump of all the resource I found in my quest to learn
instrument control using visual basic . Along the way I cam across many Visual C links also.
Good luck with your quest.
Best wishes
SBA
02-14-2011 05:32 PM
Hi Nathan,
It looks like you are using the viScanf() function correctly. Are you being thrown any errors, or is the function just not returning the correct values from the instrument? Have you tried communicating with your instrument through Measurement and Automation Explorer, in order to ensure that it is communicating properly?
Regards,
Stephanie R.
National Instruments
02-17-2011 06:36 PM
Hi,
Thanks for the replies. It turns out that I was misunderstanding the format in which the data is being returned. It actually returns an array of ASCII characters that represent a floating point number.
Nathan