156 Keysight Signal Generators Programming Guide
Programming Examples
RS-232 Programming Interface Examples (ESG/PSG Only)
printf("Check instruments and connections\n");
printf("\n");
exit(0);}
// initialize device
viStatus=viEnableEvent(vi, VI_EVENT_IO_COMPLETION, VI_QUEUE,VI_NULL);
viClear(vi);// Sends device clear command
// Set attributes for the session
viSetAttribute(vi,VI_ATTR_ASRL_BAUD,baud);
viSetAttribute(vi,VI_ATTR_ASRL_DATA_BITS,8);
viPrintf(vi, "*RST\n");// Resets the signal generator
printf("The signal generator has been reset\n");
printf("Power level should be -135 dBm\n");
printf("\n");// Prints new line character to the display
viClose(vi);// Closes session
viClose(defaultRM);// Closes default session
}
Queries Using HP Basic and RS-232
This example program demonstrates signal generator query commands over RS- 232. Query commands
are of the type *IDN? and are identified by the question mark that follows the mnemonic.
rs232ex2.txt performs the following functions:
• resets the RS- 232 interface
• sets the baud rate to match the signal generator rate
• reads the value of register 4
• queries the signal generator ID
• sets and queries the power level
Start HP Basic, type in the following commands, and then RUN the program:
The following program example is available on the signal generator Documentation CD- ROM as
rs232ex2.txt.
10 !********************************************************************************
20 !
30 ! PROGRAM NAME: rs232ex2.txt
40 !
50 ! PROGRAM DESCRIPTION: In this example, query commands are used to read
60 ! data from the signal generator.
70 !
80 ! Start HP Basic, type in the following code and then RUN the program.
90 !
100 !********************************************************************************
110 !