Technical data
34 Programmer’s Guide
4 Programming Example
Example Program
This example program queries a USB device for an identification string
and prints the results. Note that you must change the address if
something other than the default USB address value is required.
/*idn.c - program filename */
#include "visa.h"
#include <stdio.h>
void main ()
{
char buf[300]
ViSession viN9342C
ViStatus viSatus;
ViSession defaultRM;
/*Open session to USB device */
viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"USB0::2391::8472::000
0000000::0::INSTR",VI_NULL,VI_NULL,&viN9342C);
/*Initialize device */
viPrintf(viN9342C, "*RST\n");
/*Send an *IDN? string to the device */
printf(viN9342C, "*IDN?\n");
/*Read results */
viRead This function synchronously reads raw data from the session specified by the vi
parameter and stores the result in location where buf is pointing. Only one
synchronous read operation can occur at any one time.
viRead(vi, buf, count, &retCount)
viClose This function must be used to close each session. When you close a device session, all
data structures that had been allocated for the session will be set free. If you close the
default resource manager session, all sessions opened using that resource manager
session will be closed.
viClose(vi);
viClose(defaultRM)