C/C++ This example is run on the command line. It sends the *IDN? query to the instrument and prints the response to the console. // IdnExample.cpp : Microsoft Visual Studio-Generated Example // Based on Example 2-1 in the NI-VISA User Manual // Usage : IdnExample "TCPIP::xxx.xxx.xxx.xxx::inst0::INSTR" // where xxx.xxx.xxx.xxx is the IP address of the // instrument. // Output : The string identity string returned from the // instrument. // VISA Header : visa.h (must be included) // VISA Libarary : visa32.lib (must be linked with) #include "stdafx.h" #include "stdio.h" #include "string.h" #include "visa.h" #define BUFFER_SIZE 255 int main(int argc, char* argv[]) { 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 */ char *pAddress; /* Make sure we got our address. */ if ( argc < 2 ) { printf("Usage: IdnExample \"TCPIP::xxx.xxx.xxx.xxx::inst0::INSTR\"\n"); printf("\t where xxx.xxx.xxx.xxx is the IP address of your instrument.\n"); return -1; } /* Store the address. */ pAddress = argv[1]; /* Begin by initializing the system*/ status = viOpenDefaultRM(&defaultRM); if (status < VI_SUCCESS) { /* Error Initializing VISA...exiting*/ printf("Can't initialize VISA\n"); return -1; } /* Open communication with TCP/IP device at xxx.xxx.xxx.xxx*/ /* 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, 5000); /* 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(instr); status = viClose(defaultRM); return 0; }