Programming Manual UTG1000X Series
Instruments.uni-trend.com
35
/
51
int usbtmc_test()
{ /** This code demonstrates sending synchronous read & write commands
* to an USB Test & Measurement Class (USBTMC) instrument using NI-VISA
* The example writes the "*IDN?\n" string to all the USBTMC
* devices connected to the system and attempts to read back
* results using the write and read functions.
* Open Resource Manager
* Open VISA Session to an Instrument
* Write the Identification Query Using viPrintf
* Try to Read a Response With viScanf
* Close the VISA Session*/
ViSession defaultRM;
ViSession instr;
ViUInt32 numInstrs;
ViFindList findList;
ViStatus status;
char instrResourceString[VI_FIND_BUFLEN];
unsigned char buffer[100];
int i;
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS)
{
printf("Could not open a session to the VISA Resource Manager!\n");
return status;
}
/*Find all the USB TMC VISA resources in our system and store the number of resources in the system in
numInstrs.*/
status = viFindRsrc(defaultRM, "USB?*INSTR", &findList, &numInstrs, instrResourceString);
if (status<VI_SUCCESS)
{
printf("An error occurred while finding resources. \nPress Enter to continue.");
fflush(stdin);
getchar();
viClose(defaultRM);
return status;
}
/** Now we will open VISA sessions to all USB TMC instruments.
*
We must use the handle from viOpenDefaultRM and we must
*
also use a string that indicates which instrument to open. This
*
is called the instrument descriptor. The format for this string
*
can be found in the function panel by right clicking on the
*
descriptor parameter. After opening a session to the
*
device, we will get a handle to the instrument which we
*
will use in later VISA functions. The AccessMode and Timeout