39
Programming Example
Checking the USB Connection
Checking the USB Connection
Usually, using
“*IDN?”
verifies the data transferring
between the controller PC and the instrument.
****************************************************
#include "visa.h"
#include <stdio.h>
#define BufferSize 128
static ViStatus status;
static ViSession defaultRM;
static ViSession inst_N9322C;
static ViUInt32 rcount;
static unsigned char buffer[BufferSize];
int main(void)
{
/* Connect N9322C and read its "IDN". */
status = viOpenDefaultRM (&defaultRM);
status = viOpen (defaultRM,
"USB0::2391::8472::0000000000::0::INSTR", VI_NULL,
VI_NULL, &inst_N9322C);
if (status != VI_SUCCESS)
return -1; //failed to connect N9322C/
/* Read "IDN" from N9322C" */
status = viWrite (inst_N9322C, "*RST\n",
StringLength("*RST\n"), &rcount);
status = viWrite (inst_N9322C, "*IDN?\n",
StringLength("*IDN?\n"), &rcount);
status = viRead (inst_N9322C, buffer, BufferSize,
&rcount);
/* Close connection to N9322C. */
status = viClose (inst_N9322C);
status = viClose (defaultRM); return 1;
}