// Based on Example 2-1 in the NI-VISA User Manual
// Usage : IdnExample “USB0::0x0B58::0xFFF9::xxxxxxxx_xxx_xx::INSTR”
// where xxxxxxxx_xxx_xx is the USB Device ID of the
// Output : The string identity string returned from the
// VISA Header : visa.h (must be included)
// VISA Libarary : visa32.lib (must be linked with)
ViStatus status; /* For checking errors */
ViSession defaultRM, instr; /* Communication channels */
ViUInt32 retCount; /* Return count from string I/O */
ViChar buffer[BUFFER_SIZE]; /* Buffer for string I/O */
char tempDisplay[BUFFER_SIZE]; /* Display buffer for example */
/* Make sure we got our address. */
printf(”Usage: IdnExample \”USB0::0x0B58::0xFFF9::xxxxxxxx_xxx_xx::INSTR”);
printf(”\t where xxxxxxxx_xxx_xx is the USB Device ID of your instrument.\n”);
/* Begin by initializing the system*/
status = viOpenDefaultRM(&defaultRM);
/* Error Initializing VISA...exiting*/
printf(”Can't initialize VISA\n”);
/* USB0::0x0B58::0xFFF9::xxxxxxxx_xxx_xx::INSTR*/
/* NOTE: For simplicity, we will not show error checking*/
/* TODO: Add error handling. */
status = viOpen(defaultRM, pAddress, VI_NULL, VI_NULL, &instr);
/* Set the timeout for message-based communication*/
/* TODO: Add error handling. */
status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 120000);
/* Ask the device for identification */
sprintf(buffer, “*IDN?\n”);
status = viWrite(instr, (unsigned char *)&buffer[0], 6, &retCount);
status = viRead(instr, (unsigned char *)buffer, BUFFER_SIZE, &retCount);
/* TODO: Add code to process data. */
strncpy(tempDisplay, buffer, retCount);
tempDisplay[retCount] = 0; /* Null-terminate display string. */
printf(”*IDN? Returned %d bytes: %s\n”, retCount, tempDisplay);
/* Close down the system */
/* TODO: Add error handling. */
status = viClose(defaultRM);