Models 707B and 708B Switching Matrix Reference Manual
Section 2: General operation
707B-901-01 Rev. A / August 2010
2-67
VISA-C sample code
The following is a simple C/C++ console application that reads back the instrument identification
string using VISA-C. You need to include visa.h and link with the visa32.lib file.
#include "stdafx.h"
#include <visa.h>
#define checkErr(fCall) if (error = (fCall), (error = (error <
0) ? error : VI_SUCCESS)) \
{goto Error;} else error = error
int _tmain(int argc, _TCHAR* argv[])
{
ViSession defaultRM, vi;
char buf [256] = {0};
ViStatus error = VI_SUCCESS;
/* Open session to GPIB device at address 22 */
checkErr(viOpenDefaultRM(&defaultRM));
checkErr(viOpen(defaultRM, "GPIB0::14::INSTR", VI_NULL,VI_NULL, &vi));
/* Initialize device */
checkErr(viPrintf(vi, "*RST\n"));
/* Send an *IDN? string to the device */
checkErr(viPrintf(vi, "*IDN?\n"));
ViUInt16 status = 0;
do
{
checkErr(viReadSTB(vi, &status));
printf("ReadSTB = %X\n", status);
} while(status == 0);
/* Read results */
checkErr(viScanf(vi, "%t", &buf));
/* Print results */
printf ("Instrument identification string: %s\n", buf);
/* Close session */
checkErr(viClose(vi));
checkErr(viClose(defaultRM));
Error:
if(error < VI_SUCCESS)
printf("Visa Error Code: %X\n", error);
printf("\nDone - Press Enter to Exit");
getchar();
return 0;
}