Programming instructions
Programming Examples
RS-232 Programming Examples
Chapter 2 99
printf("\n");
exit(0);}
// Set timeout for 5 seconds
viSetAttribute(instr, VI_ATTR_TMO_VALUE, 5000);
// Asks for sig gen ID string
status = viWrite(instr, (ViBuf)"*IDN?\n", 6, &retCount);
// Reads the sig gen response
status = viRead(instr, (ViBuf)buffer, MAX_COUNT, &retCount);
buffer[retCount]= ’\0’; // Indicates the end of the string
printf("Signal Generator ID: "); // Prints header for ID
printf(buffer); // Prints the ID string to the screen
printf("\n"); // Prints carriage return
// Flush the read buffer
// Sets sig gen power to -5dbm
status = viWrite(instr, (ViBuf)"POW:AMPL -5dbm\n", 15, &retCount);
// Querys the sig gen for power level
status = viWrite(instr, (ViBuf)"POW?\n",5,&retCount);
// Read the power level
status = viRead(instr, (ViBuf)buffer, MAX_COUNT, &retCount);
buffer[retCount]= ’\0’; // Indicates the end of the string
printf("Power level = "); // Prints header to the screen
printf(buffer); // Prints the queried power level
printf("\n");
status = viClose(instr); // Close down the system
status = viClose(defaultRM);
return 0;
}