S331L PM PN: 10580-00322 Rev. F A-1
Appendix A — Examples
A-1 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 “USB0::0x0B58::0xFFF9::xxxxxxxx_xxx_xx::INSTR”
// where xxxxxxxx_xxx_xx is the USB Device ID 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 )